BerkinAkkaya

Hiding Properties in Inspector

Dec 6th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3.  
  4. public class MovingPlatform : MonoBehaviour {
  5.  
  6.     public enum Direction {Vertical, Horizontal}
  7.     public Direction direction;
  8.  
  9.     [HideInInspector] public Vector2 verticalPath;
  10.     [HideInInspector] public Vector2 horizontalPath;
  11. }
  12.  
  13. [CustomEditor(typeof(MovingPlatform))]
  14. public class MovingPlatformEditor : Editor
  15. {
  16.    public override void OnInspectorGUI()
  17.    {
  18.       DrawDefaultInspector();
  19.        
  20.       var scr = target as MovingPlatform;
  21.       bool vertical = (scr.direction == MovingPlatform.Direction.Vertical);
  22.         string tooltip = "X: Start Point, Y: End Point";
  23.  
  24.         if(vertical)
  25.         {
  26.             GUIContent content = new GUIContent("Vertical", tooltip);
  27.             scr.verticalPath = EditorGUILayout.Vector2Field(content, scr.verticalPath);
  28.         }
  29.         else
  30.         {
  31.             GUIContent content = new GUIContent("Horizontal", tooltip);
  32.             scr.horizontalPath = EditorGUILayout.Vector2Field(content, scr.horizontalPath);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment