/// <summary> /// Opens the Serialization Debugger Window and debugs the given type. /// </summary> /// <param name="type">The type to debug serialization of.</param> public static void ShowWindow(Type type) { SerializationDebuggerWindow window = Resources.FindObjectsOfTypeAll <SerializationDebuggerWindow>().FirstOrDefault(); if (window == null) { window = GetWindow <SerializationDebuggerWindow>("Serialization Debugger"); window.position = GUIHelper.GetEditorWindowRect().AlignCenter(500f, 400f); } window.targetType = type; window.Show(); if (window.targetType != null) { window.CreateMenuTree(true); window.Repaint(); } }
/// <summary> /// Not yet documented. /// </summary> public static void Show(Type type, int controlId, Rect buttonRect = default(Rect)) { Type = type; ControlID = controlId; var window = EditorWindow.CreateInstance <InstanceCreatorWindow>(); window.Initialize(); if (Event.current != null && Event.current.modifiers == EventModifiers.Control) { UnityEngine.Object.DestroyImmediate(window); return; } if (buttonRect.width > 0 && buttonRect.height > 0) { var prevWidth = buttonRect.width; buttonRect.width = Mathf.Clamp(prevWidth, 250, 500); buttonRect.x += (prevWidth - buttonRect.width); var windowSize = new Vector2(buttonRect.width, Mathf.Min(buttonRect.width, window.GetWindowHeight())); if (Event.current != null) { buttonRect.position = GUIUtility.GUIToScreenPoint(buttonRect.position); } window.ShowAsDropDown(buttonRect, windowSize); } else { var windowSize = new Vector2(500, 500); var windowRect = GUIHelper.GetEditorWindowRect(); window.ShowAuxWindow(); window.position = new Rect(windowRect.center - windowSize * 0.5f, new Vector2(windowSize.x, window.GetWindowHeight())); } window.minSize = new Vector2(20, 20); window.maxSize = window.position.size; }
/// <summary> /// Opens a new inspector window for the specified object. /// </summary> /// <param name="unityObj">The unity object.</param> /// <exception cref="System.ArgumentNullException">unityObj</exception> public static void OpenInspectorWindow(UnityEngine.Object unityObj) { if (unityObj == null) { throw new ArgumentNullException("unityObj"); } var windowRect = GUIHelper.GetEditorWindowRect(); var windowSize = new Vector2(450, Mathf.Min(windowRect.height * 0.7f, 500)); var rect = new Rect(windowRect.center - windowSize * 0.5f, windowSize); var inspectorInstance = ScriptableObject.CreateInstance(inspectorWindowType) as EditorWindow; inspectorInstance.Show(); var prevSelection = Selection.objects; Selection.activeObject = unityObj; inspectorWindowType .GetProperty("isLocked", Flags.AllMembers) .GetSetMethod() .Invoke(inspectorInstance, new object[] { true }); Selection.objects = prevSelection; inspectorInstance.position = rect; if (unityObj.GetType().InheritsFrom(typeof(Texture2D))) { EditorApplication.delayCall += () => { // Unity's Texture drawer changes Selection.object EditorApplication.delayCall += () => { // Lets change that back shall we? Selection.objects = prevSelection; }; }; } }