Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine;
- using UnityEditor;
- using UnityEditorInternal;
- [CustomEditor(typeof(ClickableObject))]
- public class ClickableObjectEditor : Editor {
- private ReorderableList list;
- private void OnEnable()
- {
- list = new ReorderableList(serializedObject,serializedObject.FindProperty("Required"),true, true, true, true);
- //Draw the rect for the list
- list.drawElementCallback =
- (Rect rect, int index, bool isActive, bool isFocused) => {
- var element = list.serializedProperty.GetArrayElementAtIndex(index);
- rect.y += 2;
- EditorGUI.PropertyField(
- new Rect(rect.x, rect.y, 150, EditorGUIUtility.singleLineHeight),
- element.FindPropertyRelative("Type"), GUIContent.none);
- EditorGUI.PropertyField(
- new Rect(rect.x + 150, rect.y, 100, EditorGUIUtility.singleLineHeight),
- element.FindPropertyRelative("id"), GUIContent.none);
- if (element.FindPropertyRelative("Type").enumValueIndex == 2)//Only show this if it is relevant
- {
- EditorGUI.TextArea(
- new Rect(rect.x + 300, rect.y, 100, EditorGUIUtility.singleLineHeight),
- "Destroy Item");
- EditorGUI.PropertyField(
- new Rect(rect.x + 400, rect.y, 100, EditorGUIUtility.singleLineHeight),
- element.FindPropertyRelative("RemoveItem"), GUIContent.none);
- }
- };
- list.drawHeaderCallback = (Rect rect) => {
- EditorGUI.LabelField(rect, "Requirements");
- };
- }
- public override void OnInspectorGUI()
- {
- serializedObject.Update();
- //SuccessActions
- SerializedProperty _SuccessActions = serializedObject.FindProperty("SuccessActions");
- EditorGUI.BeginChangeCheck();
- EditorGUILayout.PropertyField(_SuccessActions, true);
- if (EditorGUI.EndChangeCheck())
- serializedObject.ApplyModifiedProperties();
- //FailActions
- SerializedProperty _FailActions = serializedObject.FindProperty("FailActions");
- EditorGUI.BeginChangeCheck();
- EditorGUILayout.PropertyField(_FailActions, true);
- if (EditorGUI.EndChangeCheck())
- serializedObject.ApplyModifiedProperties();
- list.DoLayoutList();
- serializedObject.ApplyModifiedProperties();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment