Last active
June 1, 2018 00:37
-
-
Save jringrose/3fc8c96798a2e3148464563c96018a74 to your computer and use it in GitHub Desktop.
A utility to open up temporary inspector windows to view objects. NewInspectorWindow.cs and InspectorButtonPropertyDrawer.cs should be inside an Editor folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
public static class NewInspectorWindow { | |
public static void InspectTarget(GameObject target) | |
{ | |
System.Type inspectorType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow"); | |
EditorWindow inspectorInstance = ScriptableObject.CreateInstance(inspectorType) as EditorWindow; | |
var p = inspectorInstance.position; | |
Vector2 pos = GUIUtility.GUIToScreenPoint(Event.current.mousePosition); | |
pos.x = pos.x - p.size.x * 0.5f; | |
pos.y += 20f; | |
p.position = pos; | |
p.size = new Vector2(400f, 600f); | |
inspectorInstance.ShowUtility(); | |
inspectorInstance.position = p; | |
var prevSelection = Selection.activeObject; | |
Selection.activeObject = target; | |
var isLocked = inspectorType.GetProperty("isLocked", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); | |
isLocked.GetSetMethod().Invoke(inspectorInstance, new object[] { true }); | |
Selection.activeObject = prevSelection; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment