Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InspectorUtil fails to load current Inspector window in Unity 2018 #30

Closed
Maclay74 opened this issue Sep 16, 2018 · 1 comment
Closed
Assignees
Labels

Comments

@Maclay74
Copy link

So, it looks like something is broken in 2018.3 beta.

Everything is working great in Editor, but when you try to Play, initialize error occurs.
Seems like, something goes wrong in Initialize function in Assets\OneLine\OneLine\Editor\Utils\InspectorUtil.cs

So, in order to work around I found useful to check is s_CurrentInspectorWindow really exist and in case of null return false.

So, there are some changes I've made:

       public InspectorUtil() {
            enabled = false;
            if (EditorWindow.focusedWindow is PopupWindow) return; // Detect is it [Expandable] popup

            try {
                if (this.Initialize()) // Additional check
                    enabled = true;
            }
            catch (Exception ex){
                Debug.LogError(INITIALIZATION_ERROR_MESSAGE + ex.ToString());
            }
        }

       private bool Initialize(){
            inspectorWindowType = Type.GetType(INSPECTOR_WINDOW_ASSEMBLY_QUALIFIED_NAME);

            // If this field doesn't exist, return false
            if (inspectorWindowType.GetField("s_CurrentInspectorWindow") != null) {
                window = inspectorWindowType
                .GetField("s_CurrentInspectorWindow", BindingFlags.Public | BindingFlags.Static)
                .GetValue(null);    
            } else {
                return false;
            }
            
            scrollPositionInfo = inspectorWindowType.GetField("m_ScrollPosition");
            getWindowPositionInfo = inspectorWindowType.GetProperty("position", typeof(Rect))
                                                        .GetGetMethod();

            var test = ScrollPosition;
            return true;
        }

I see that new version is coming, hope this issue would be helpful.

@slavniyteo slavniyteo added the bug label Sep 17, 2018
@slavniyteo slavniyteo self-assigned this Sep 17, 2018
@slavniyteo
Copy link
Owner

Thank you for this bug.

The problem is there:

  • in 2017.3, the last I've tested, field s_CurrentInspectorWindow was public;
  • in 2018.3b s_CurrentInspectorWindow is internal.

This breaks some reflection magic.
I'll fix it in v0.4.0.

@slavniyteo slavniyteo changed the title Problem with new 2018.3 beta InspectorUtil fails to load current Inspector window in Unity 2018 Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants