Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using UnityEngine;
  2. using UnityEngine;
  3. using UnityEditor;
  4. using UnityEditorInternal;
  5.  
  6. [CustomEditor(typeof(ClickableObject))]
  7. public class ClickableObjectEditor : Editor {
  8.     private ReorderableList list;
  9.  
  10.     private void OnEnable()
  11.     {
  12.         list = new ReorderableList(serializedObject,serializedObject.FindProperty("Required"),true, true, true, true);
  13.  
  14.         //Draw the rect for the list
  15.         list.drawElementCallback =        
  16.         (Rect rect, int index, bool isActive, bool isFocused) => {
  17.             var element = list.serializedProperty.GetArrayElementAtIndex(index);
  18.             rect.y += 2;
  19.  
  20.             EditorGUI.PropertyField(
  21.                 new Rect(rect.x, rect.y, 150, EditorGUIUtility.singleLineHeight),
  22.                 element.FindPropertyRelative("Type"), GUIContent.none);
  23.            
  24.            
  25.             EditorGUI.PropertyField(
  26.                 new Rect(rect.x + 150, rect.y, 100, EditorGUIUtility.singleLineHeight),
  27.                 element.FindPropertyRelative("id"), GUIContent.none);
  28.  
  29.             if (element.FindPropertyRelative("Type").enumValueIndex == 2)//Only show this if it is relevant
  30.             {
  31.  
  32.                 EditorGUI.TextArea(
  33.                 new Rect(rect.x + 300, rect.y, 100, EditorGUIUtility.singleLineHeight),
  34.                 "Destroy Item");
  35.  
  36.                 EditorGUI.PropertyField(
  37.                     new Rect(rect.x + 400, rect.y, 100, EditorGUIUtility.singleLineHeight),
  38.                     element.FindPropertyRelative("RemoveItem"), GUIContent.none);
  39.  
  40.             }
  41.         };
  42.         list.drawHeaderCallback = (Rect rect) => {
  43.             EditorGUI.LabelField(rect, "Requirements");
  44.         };
  45.     }
  46.  
  47.     public override void OnInspectorGUI()
  48.     {
  49.         serializedObject.Update();      
  50.        
  51.         //SuccessActions
  52.         SerializedProperty _SuccessActions = serializedObject.FindProperty("SuccessActions");
  53.         EditorGUI.BeginChangeCheck();
  54.         EditorGUILayout.PropertyField(_SuccessActions, true);
  55.         if (EditorGUI.EndChangeCheck())
  56.             serializedObject.ApplyModifiedProperties();
  57.  
  58.         //FailActions
  59.         SerializedProperty _FailActions = serializedObject.FindProperty("FailActions");
  60.         EditorGUI.BeginChangeCheck();
  61.         EditorGUILayout.PropertyField(_FailActions, true);
  62.         if (EditorGUI.EndChangeCheck())
  63.             serializedObject.ApplyModifiedProperties();
  64.  
  65.  
  66.         list.DoLayoutList();
  67.         serializedObject.ApplyModifiedProperties();
  68.     }
  69. }