protected bool DoDrawCustomIMGUIInspector(Object target) { if (!ActiveEditorTracker.HasCustomEditor(target)) { GUILayout.Label("No custom inspector.", EditorStyles.boldLabel); return(false); } var editor = GetActiveEditor(target); if (editor == null) { editor = Editor.CreateEditor(target); } EditorGUIUtility.wideMode = true; GUIStyle editorWrapper = (editor.UseDefaultMargins() ? EditorStyles.inspectorDefaultMargins : GUIStyle.none); EditorGUILayout.BeginVertical(editorWrapper); { GUI.changed = false; try { editor.OnInspectorGUI(); } catch (Exception e) { Debug.LogException(e); } } EditorGUILayout.EndVertical(); return(true); }
private VisualElement CreateCustomInspector(SerializedObject serializedObject) { var target = serializedObject?.targetObject; if (target == null) { return(null); } if (!ActiveEditorTracker.HasCustomEditor(target)) { return(null); } var activeEditors = ActiveEditorTracker.sharedTracker?.activeEditors; var editor = activeEditors?.FirstOrDefault((e) => e.target == target); if (editor == null) { editor = Editor.CreateEditor(target); } VisualElement customInspector = null; if (mode != Mode.IMGUI) { customInspector = (editor as UIElementsEditor)?.CreateInspectorGUI(); } if (customInspector == null) { customInspector = new IMGUIContainer(() => { var originalWideMode = EditorGUIUtility.wideMode; EditorGUIUtility.wideMode = true; GUIStyle editorWrapper = (editor.UseDefaultMargins() ? EditorStyles.inspectorDefaultMargins : GUIStyle.none); EditorGUILayout.BeginVertical(editorWrapper); { GUI.changed = false; try { editor.OnInspectorGUI(); } catch (Exception e) { Debug.LogException(e); } } EditorGUILayout.EndVertical(); EditorGUIUtility.wideMode = originalWideMode; }); } customInspector.AddToClassList(s_CustumInspectorClassName); return(customInspector); }
bool AssetHasCustomEditor(SerializedProperty property) { ScriptableObject asset = property.objectReferenceValue as ScriptableObject; if (asset != null) { return(ActiveEditorTracker.HasCustomEditor(asset)); } return(false); }
protected bool DoDrawNormalIMGUIInspector(Object target) { if (ActiveEditorTracker.HasCustomEditor(target)) { return(DoDrawCustomIMGUIInspector(target)); } else { return(DoDrawDefaultIMGUIInspector(target)); } }