#OpenPropertyWindow

1 messages · Page 1 of 1 (latest)

wide tartan
#

just popping this into a thread @azure glen

azure glen
#

👍

wide tartan
#

2 errors now:
cannot convert from 'object[]' to 'System.Type[]'
and
cannot convert from 'System.Reflection.BindingFlags' to 'System.Reflection.ParameterModifier[]'

azure glen
#

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"

wide tartan
#

hmm are you sure? if I do that I get
cannot convert from 'System.Reflection.BindingFlags' to 'System.Type[]'

azure glen
#

Or not lol

wide tartan
#

and cannot convert from 'System.Type[]' to 'System.Reflection.ParameterModifier[]'

azure glen
#

You are using VS right? hovering over GetMetod should show you all of the overrides for it

wide tartan
#

VS Code

azure glen
#

Should still be able to hover to see the overrides

wide tartan
#

I just see "+5 overloads" but not sure how to view them :/

wide tartan
#

not for me! 😅

azure glen
#
 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 😛

wide tartan
#

🤔

#

here is the error if I copy and paste exactly (with my previous namespaces)

azure glen
#

That's my bad, I didn't see the error, there is one extra ( at the start of GetMethod that needs to be removed

wide tartan
#

OK got that haha

#

but now I'm back to the previous errors

azure glen
#

Which are?

wide tartan
#

cannot convert from 'System.Reflection.BindingFlags' to 'System.Type[]'
and
Argument 3: cannot convert from 'object[]' to 'System.Reflection.ParameterModifier[]'

azure glen
#

Seems it is .NET 6 overload. Looks like this is what you want

type.GetMethod(name, Flags, Type.DefaultBinder, parameterTypes, null);
wide tartan
#

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 });
    }
}
azure glen
#

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.

wide tartan
#

hahaha it's all good.

#

any idea why this worked for you but not me? is it the version of .NET I have installed?

azure glen
#

What version are you on of Unity?

wide tartan
#

2020.3.22

azure glen
#

Maybe they moved to it in 2021?

wide tartan
#

is that what you're using?

azure glen
#

Yeah

#

2021.2