public static ObjectEditor CreateEditor(object _targetObject) { Type objectEditorType; ObjectEditor objectEditor; if (ObjectEditorTypeCache.TryGetValue(ObjectInspector.Instance.targetObject.GetType(), out objectEditorType)) { objectEditor = Activator.CreateInstance(objectEditorType, true) as ObjectEditor; } else if ((objectEditorType = ObjectEditorTypeCache.FirstOrDefault(kv => kv.Key.IsAssignableFrom(_targetObject.GetType())).Value) != null) { objectEditor = Activator.CreateInstance(objectEditorType, true) as ObjectEditor; } else { objectEditor = new ObjectEditor(); } objectEditor.Initialize(_targetObject); return(objectEditor); }
protected virtual void OnRightGUI(CZMenuTreeViewItem _selectedItem) { if (_selectedItem == null) { return; } switch (_selectedItem.userData) { case null: GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label(_selectedItem.displayName, (GUIStyle)"AM MixerHeader2"); GUILayout.EndHorizontal(); GUILayout.Space(5); EditorGUI.DrawRect(GUILayoutUtility.GetRect(rightRect.width, 1), Color.gray); break; case UnityObject unityObject: if (unityObject == null) { break; } if (!EditorCache.TryGetValue(unityObject, out Editor editor)) { EditorCache[unityObject] = editor = Editor.CreateEditor(unityObject); } editor.OnInspectorGUI(); Repaint(); break; default: if (!ObjectEditorCache.TryGetValue(_selectedItem.userData, out ObjectEditor objectEditor)) { ObjectEditorCache[_selectedItem.userData] = objectEditor = ObjectEditor.CreateEditor(_selectedItem.userData); } objectEditor.OnInspectorGUI(); break; } }
private void OnEnable() { OnEnable(ObjectInspector.Instance.TargetObject); ObjectInspector.Instance.onTargetObjectChanged = () => { OnEnable(ObjectInspector.Instance.TargetObject); }; void OnEnable(object _targetObject) { objectEditor = ObjectEditor.CreateEditor(_targetObject); if (objectEditor != null) { string title = objectEditor.GetTitle(); if (!string.IsNullOrEmpty(title)) { target.name = title; } objectEditor.OnEnable(); } } }
private void OnEnable() { if (ObjectInspector.Instance.targetObject == null) { Selection.activeObject = null; return; } if (objectEditor != null) { string title = objectEditor.GetTitle(); if (!string.IsNullOrEmpty(title)) { target.name = title; } } objectEditor = ObjectEditor.CreateEditor(ObjectInspector.Instance.targetObject); if (objectEditor != null) { objectEditor.OnEnable(); } }