using UnityEditor; using UnityEngine; namespace SpellBoundAR.Items.Editor { [CustomEditor(typeof(Item), true)] public class ItemInspector : UnityEditor.Editor { private UnityEditor.Editor _typeEditor; private UnityEditor.Editor _instanceEditor; public override void OnInspectorGUI() { Object typeObject = serializedObject.FindProperty("type").objectReferenceValue; Object instanceObject = serializedObject.FindProperty("instance").objectReferenceValue; EditorGUI.BeginDisabledGroup(instanceObject); EditorGUILayout.PropertyField(serializedObject.FindProperty("type")); EditorGUI.EndDisabledGroup(); EditorGUILayout.PropertyField(serializedObject.FindProperty("instance")); if (typeObject) { CreateCachedEditor(typeObject, null, ref _typeEditor); if (_typeEditor) _typeEditor.OnInspectorGUI(); } else { _typeEditor = null; DrawDefaultTypeSettings(); } if (instanceObject) { CreateCachedEditor(instanceObject, null, ref _instanceEditor); if (_instanceEditor) _instanceEditor.OnInspectorGUI(); } else { _instanceEditor = null; DrawDefaultInstanceSettings(); } serializedObject.ApplyModifiedProperties(); } private void DrawDefaultTypeSettings() { GUILayout.Space(10); EditorGUILayout.BeginVertical(Styles.Subbox, GUILayout.MinHeight(30)); GUILayout.Label("Type Settings", Styles.H3, GUILayout.ExpandWidth(true)); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultID"), new GUIContent("ID")); EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultName"), new GUIContent("Name")); EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultLocalizedName"), new GUIContent("Localized Name")); EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultDescription"), new GUIContent("Description")); EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultDepiction"), new GUIContent("Depiction")); EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultShowInInventory"), new GUIContent("Show In Inventory")); EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); } private void DrawDefaultInstanceSettings() { GUILayout.Space(10); EditorGUILayout.BeginVertical(Styles.Subbox, GUILayout.MinHeight(30)); GUILayout.Label("Instance Settings", Styles.H3, GUILayout.ExpandWidth(true)); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(serializedObject.FindProperty("visible")); EditorGUILayout.PropertyField(serializedObject.FindProperty("interactable")); EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); } } }