Hi,
I would like to know if it s possible to show two gameobject properties in two different inspectors?
Thanks,
Hi,
I would like to know if it s possible to show two gameobject properties in two different inspectors?
Thanks,
Actually it's possible, but not intuitive. Bear with me:
Hope this helps
Ben
Based on @Ben-14’s work-around, here’s how you create a new inspector window inspecting a certain target gameObject from code.
/// <summary>
/// Creates a new inspector window instance and locks it to inspect the specified target
/// </summary>
public static void InspectTarget(GameObject target)
{
// Get a reference to the `InspectorWindow` type object
var inspectorType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow");
// Create an InspectorWindow instance
var inspectorInstance = ScriptableObject.CreateInstance(inspectorType) as EditorWindow;
// We display it - currently, it will inspect whatever gameObject is currently selected
// So we need to find a way to let it inspect/aim at our target GO that we passed
// For that we do a simple trick:
// 1- Cache the current selected gameObject
// 2- Set the current selection to our target GO (so now all inspectors are targeting it)
// 3- Lock our created inspector to that target
// 4- Fallback to our previous selection
inspectorInstance.Show();
// Cache previous selected gameObject
var prevSelection = Selection.activeGameObject;
// Set the selection to GO we want to inspect
Selection.activeGameObject = target;
// Get a ref to the "locked" property, which will lock the state of the inspector to the current inspected target
var isLocked = inspectorType.GetProperty("isLocked", BindingFlags.Instance | BindingFlags.Public);
// Invoke `isLocked` setter method passing 'true' to lock the inspector
isLocked.GetSetMethod().Invoke(inspectorInstance, new object[] { true });
// Finally revert back to the previous selection so that other inspectors continue to inspect whatever they were inspecting...
Selection.activeGameObject = prevSelection;
}
// Now you just:
InspectTarget(myGO);
This is an editor script so you need to add using UnityEditor;
as well as System.Reflection
for the BindingFlags
How did I know about this? Simple, by decompiling UnityEditor.dll and lurking inside.
I personally like ILSpy, there’s also JustDecompile, dotPeek and (now the infamous) .NET Reflector
Thank you for telling me about that lock!!! wow, made it so much easier