slavniyteo / one-line

One line property drawer for Unity3d
MIT License
146 stars 12 forks source link

InspectorUtil fall if use OneLine at editor window (not in inspector) #38

Closed raslab closed 3 years ago

raslab commented 5 years ago

In case of using some global editor window with small child editors, OneLine flag in child objects can fall.

For example:

Some scriptable object

public class GlobalConfigContainer : ScriptableObject
{
    public ConfigPart part;
}

public class ConfigPart
{
    [SerializeField]
    [OneLine.OneLine]
    public SomeDatas[] dataArray;
}

Some editor window

public class GlobalConfigEditor : EditorWindow
{
    private Editor _editor;

// ......

    public override void OnInspectorGUI()
    {
        // here we creating and drawing some editor for our scriptable object
        if (_editor == null)
            _editor = CreateEditor(CreateInstance<GlobalConfigContainer>());

        _editor.DrawDefaultInspector();
    }
// ......
}

In this case we catch error because InspectorUtil can't find inspector window (in this case we using custom editor window)

OneLine can not initialize Inspector Window Utility. 
You may experience some performance issues. 
Please create an issue on https://github.com/slavniyteo/one-line/ and we will repair it.
System.Reflection.TargetException: Non-static field requires a target
  at System.Reflection.MonoField.GetValue (System.Object obj) [0x0000b] in <d7ac571ca2d04b2f981d0d886fa067cf>:0 
  at OneLine.InspectorUtil.get_ScrollPosition () [0x00001] in Assets\ThirdParty\OneLine\OneLine\Editor\Utils\InspectorUtil.cs:63 
  at OneLine.InspectorUtil.Initialize () [0x0006c] in Assets\ThirdParty\OneLine\OneLine\Editor\Utils\InspectorUtil.cs:60 
  at OneLine.InspectorUtil..ctor () [0x00045] in Assets\ThirdParty\OneLine\OneLine\Editor\Utils\InspectorUtil.cs:41 
slavniyteo commented 5 years ago

Thank you for reporting.

What version of Unity do you use?

raslab commented 5 years ago

Oops, forgot to attach to report, sorry. Unity version 2018.4.0f1

slavniyteo commented 5 years ago

Seems to be similar to #34.

At versions v0.4.0+ you can disable this message at Window/OneLineSettings by turn off the Culling column.

As I said in https://github.com/slavniyteo/one-line/issues/34#issuecomment-478413485, one of my magic optimizations is broken in the latest versions. But you affected by this only if your consist of very large arrays (optimization allow not to draw invisible elements).

raslab commented 5 years ago

Looks like same but not fully. In #34 problem then in 2019 Unity s_CurrentInspectorWindow field deleted but in this case we just not using inspector window - we using custom editor window. In this case s_CurrentInspectorWindow exist but null. Exception throws at OneLine.InspectorUtil.get_ScrollPosition, in case of reflection didn't found inspector field - exception was thrown by few lines earlier.

raslab commented 5 years ago

Thanks, turning down of content culling helps :) But it saves to local Prefs (not in Project Settings) and I can't share this solution to all team via git, so just commented exception for next OneLine update.

slavniyteo commented 5 years ago

Sorry, I can't take a screenshot now (because I don't have Unity installed right now), but there is an option to store settings in ScriptableObject.

As said in the description (you can see it in the Inspector when you open Window/OneLineSettings), you can choose where to store your settings: in ScriptableObject or in EditorPrefs. See https://github.com/slavniyteo/one-line/blob/master/Editor/Scripts/Settings/SettingsEditor.cs#L22.

Don't forget to click the Save button =)

raslab commented 5 years ago

Wow, it's work, thanks)

slavniyteo commented 3 years ago

Closed with #v0.5.2