InvManagerEditor.cs

using UnityEngine; using UnityEditor; using UnityEditorInternal; using AC; [CustomEditor(typeof(InvManager))] public class InvManagerEditor : Editor { private ReorderableList list; private void OnEnable() { list = new ReorderableList(serializedObject, serializedObject.FindProperty("itemOverrides"), true, true, true, true); list.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Inventory Action Syntax Overrides"); }; list.onAddCallback = (ReorderableList l) => { var index = l.serializedProperty.arraySize; l.serializedProperty.arraySize++; l.index = index; var element = l.serializedProperty.GetArrayElementAtIndex(index); element.FindPropertyRelative("hotspot").stringValue = Selection.activeGameObject.name; element.FindPropertyRelative("invitem").stringValue = "Item"; element.FindPropertyRelative("overrideSyntax").stringValue = "on"; }; list.onCanRemoveCallback = (ReorderableList l) => { return l.count > 1; }; list.onRemoveCallback = (ReorderableList l) => { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete the override?", "Yes", "No")) { ReorderableList.defaultBehaviours.DoRemoveButton(l); } }; list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var element = list.serializedProperty.GetArrayElementAtIndex(index); rect.y += 2; EditorGUI.LabelField (new Rect(rect.x, rect.y, 150, EditorGUIUtility.singleLineHeight), "Use "+element.FindPropertyRelative("invitem").stringValue); EditorGUI.PropertyField (new Rect(rect.x + 150, rect.y, 70, EditorGUIUtility.singleLineHeight),element.FindPropertyRelative("overrideSyntax"), GUIContent.none); EditorGUI.LabelField (new Rect(rect.x + rect.width - 140, rect.y, 140, EditorGUIUtility.singleLineHeight),element.FindPropertyRelative("hotspot").stringValue); }; } public override void OnInspectorGUI() { serializedObject.Update(); list.DoLayoutList(); serializedObject.ApplyModifiedProperties(); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.