#OpenPropertyWindow
1 messages · Page 1 of 1 (latest)
👍
2 errors now:
cannot convert from 'object[]' to 'System.Type[]'
and
cannot convert from 'System.Reflection.BindingFlags' to 'System.Reflection.ParameterModifier[]'
My bad, the first one is easy, just change new object[] {..} to new Type[] {..}
Second one is because I got the order wrong, it goes "string, bindingflags, type array"
hmm are you sure? if I do that I get
cannot convert from 'System.Reflection.BindingFlags' to 'System.Type[]'
Or not lol
and cannot convert from 'System.Type[]' to 'System.Reflection.ParameterModifier[]'
You are using VS right? hovering over GetMetod should show you all of the overrides for it
VS Code
Should still be able to hover to see the overrides
I just see "+5 overloads" but not sure how to view them :/
not for me! 😅
static MethodInfo _openPropertyWindowInfo;
public static EditorWindow OpenPropertyEditor(UnityEngine.Object obj)
{
if (_openPropertyWindowInfo == null)
{
System.Type propertyEditorType = typeof(EditorWindow).Assembly.GetType("UnityEditor.PropertyEditor");
_openPropertyWindowInfo = propertyEditorType.GetMethod("OpenPropertyEditor", BindingFlags.NonPublic | BindingFlags.Static, new object[] { typeof(Object), typeof(bool) });
}
return (EditorWindow)_openPropertyWindowInfo.Invoke(null, new object[] { obj, true });
}
Well this works for me 😛
That's my bad, I didn't see the error, there is one extra ( at the start of GetMethod that needs to be removed
Which are?
cannot convert from 'System.Reflection.BindingFlags' to 'System.Type[]'
and
Argument 3: cannot convert from 'object[]' to 'System.Reflection.ParameterModifier[]'
Seems it is .NET 6 overload. Looks like this is what you want
type.GetMethod(name, Flags, Type.DefaultBinder, parameterTypes, null);
this works! 🥳
_openPropertyWindowInfo = propertyEditorType.GetMethod("OpenPropertyEditor", BindingFlags.NonPublic | BindingFlags.Static, Type.DefaultBinder, new Type[] { typeof(Object), typeof(bool) }, null);
amazing. exactly what I need. thanks so much for the help @azure glen, and apologies for fumbling my way through it so cluelessly!
final code:
using UnityEditor;
using System.Reflection;
using System;
using Object = UnityEngine.Object;
public class EditorTools
{
static MethodInfo _openPropertyWindowInfo;
public static EditorWindow OpenPropertyEditor(UnityEngine.Object obj)
{
if (_openPropertyWindowInfo == null)
{
System.Type propertyEditorType = typeof(EditorWindow).Assembly.GetType("UnityEditor.PropertyEditor");
_openPropertyWindowInfo = propertyEditorType.GetMethod("OpenPropertyEditor", BindingFlags.NonPublic | BindingFlags.Static, Type.DefaultBinder, new Type[] { typeof(Object), typeof(bool) }, null);
}
return (EditorWindow)_openPropertyWindowInfo.Invoke(null, new object[] { obj, true });
}
}
All good, glad you got it working. And to be fair, if I had put in a bit more effort to start with it would have saved us both a bit of time, so I apologize for that haha.
hahaha it's all good.
any idea why this worked for you but not me? is it the version of .NET I have installed?
What version are you on of Unity?
2020.3.22
Maybe they moved to it in 2021?
is that what you're using?