/// <summary> /// Force Unity's "Selection" to use a non-unity object. /// </summary> public static void Select(object tag) { InspectorWrapper wrapper = CreateInstance <InspectorWrapper>(); wrapper.tag = tag; Selection.activeObject = wrapper; }
/// <summary> /// Get currenty Unity's Selection /// </summary> public static T GetSelection <T>() { InspectorWrapper wrapper = Selection.activeObject as InspectorWrapper; if (wrapper == null || !typeof(T).IsAssignableFrom(wrapper.tag.GetType())) { return(default(T)); } return((T)wrapper.tag); }
/// <summary> /// Is this object selected by Unity's Selection? /// </summary> public static bool IsSelected(object tag) { InspectorWrapper wrapper = Selection.activeObject as InspectorWrapper; if (wrapper == null) { return(false); } return(wrapper.tag == tag); }
/// <summary> /// Default Inspector entry point. /// </summary> public override void OnInspectorGUI() { if (Instances == null) { return; } current = this; if (advanced) { DrawAdvancedInspector(); } else { DrawDefaultInspector(); } if (picking) { Rect window = EditorWindow.focusedWindow.position; EditorGUIUtility.AddCursorRect(new Rect(0, 0, window.width, window.height), MouseCursor.CustomCursor); if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) { StopPicking(); Event.current.Use(); } } current = null; if (Instances.Length != 1) { return; } IInspect inspect = Instances[0] as IInspect; if (inspect == null) { return; } object[] inspectInstances = inspect.Inspect; if (inspectInstances == null || inspectInstances.Length == 0) { ClearExtraEditors(); } else { bool refreshEditors = inspectInstances.Length != extraEditors.Count; if (!refreshEditors) { for (int i = 0; i < inspectInstances.Length; i++) { if (inspectInstances[i] is UnityEngine.Object) { if ((UnityEngine.Object)inspectInstances[i] != extraEditors[i].target) { refreshEditors = true; break; } } else { InspectorWrapper wrapper = extraEditors[i].target as InspectorWrapper; if (wrapper == null || wrapper.Tag != inspectInstances[i]) { refreshEditors = true; break; } } } } if (refreshEditors) { ClearExtraEditors(); foreach (object inspectInstance in inspectInstances) { if (inspectInstance == null || inspectInstance.GetType().Namespace == "System") { continue; } UnityEngine.Object unityObject = inspectInstance as UnityEngine.Object; if (unityObject == null) { InspectorWrapper wrapper = CreateInstance <InspectorWrapper>(); wrapper.Tag = inspectInstance; unityObject = wrapper; } extraEditors.Add(CreateEditor(unityObject)); } } foreach (Editor editor in extraEditors) { editor.DrawHeader(); editor.OnInspectorGUI(); } } }