marijnz / unity-toolbar-extender

Extend the Unity Toolbar with your own Editor UI code.
MIT License
1.67k stars 168 forks source link

Unity 2019.2 compatibility #10

Closed larssteenhoff closed 5 years ago

larssteenhoff commented 5 years ago

Can anyone confirm if it works in 2019.2 a13

It does not work for me.

It does work in 2018.3

ezaca commented 5 years ago

I am just a guest trying to run this code, but I feel I can provide some information to the developers. Is that your case, larssteenhoff? Otherwise, I will post as a new issue. Here, in Unity 2019.1.4f1 (.NET 4x), it prints the following errors:

image

Starting from the first error, I found this stack trace:

System.NullReferenceException: Object reference not set to an instance of an object

  at UnityToolbarExtender.ToolbarExtender..cctor () [0x00043] in C:\Users\...\unity-toolbar-extender-master\unity-toolbar-extender-master\Assets\ToolbarExtender\Scripts\Editor\ToolbarExtender.cs:23 
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes(Type[])

Which brought me to this part of the code:

image

The hightlighted line is the source of the error I am facing and unable to solve. Maybe I am completely wrong, but it seems the field was static (GetValue(null)) and now it is a non-static member (null reference after finding the field).

Other simple problems I solved:

marijnz commented 5 years ago

In 2019, the toolbar changed a bit so this probably breaks the code. The error is pretty trivial (we just use it for a length), if someone has a fix a PR is welcome!

Thanks for the investigation ezaca

Frank-99 commented 5 years ago

I found this, maybe it helps... https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/GUI/Toolbar.cs For the time being, I'm using the following:

`

if UNITY_2019_1_OR_NEWER

    m_toolCount = 7;
#elif UNITY_2018_1_OR_NEWER
    m_toolCount = 6;
#elif UNITY_2017_4_OR_NEWER
    m_toolCount = 6;
#else
    m_toolCount = 5;
#endif

`

I think the "move rotate or scale" tool was added in 2017.4? I'll have to check though...

marijnz commented 5 years ago

Hi Frank, could you make a PR with that change? I will approve.

Frank-99 commented 5 years ago

Hi Frank, could you make a PR with that change? I will approve.

Can't seem to make the code indent right... Anyway, the problem is that I've tried before but couldn't manage to do it... I'm fairly new to github (other than downloading) and I'd appreciate if you could explain quickly or direct me to a tutorial or something?

marijnz commented 5 years ago

Sure thing! 1) You can fork the project like this: https://help.github.com/en/articles/fork-a-repo 2) Change the code on your fork (by checking it out locally and pushing your change, or just change it in GitHub directly 3) And then you can create a PR like this: https://help.github.com/en/articles/creating-a-pull-request-from-a-fork

marijnz commented 5 years ago

Thanks @Frank-99 . I consider this one closed for now as a hacky fix fits perfectly in this hacky project ;)

Frank-99 commented 5 years ago

Thank you very much for the help! :) Also, I'm happy I was able to help out with a hacky fix, as you put it!

Do you think you can get access to the field, now that its a constant? I'm not too experienced with this stuff yet, but from what I've read here, the exception is thrown when "The field is non-static and obj is null". I'm guessing this doesn't sound too good, and that for now this 'fix' will have to do, right?

marijnz commented 5 years ago

I see, I didn't actually look at any of the new code, but the field just changed name! In the project, change s_ShownToolIcons to k_ToolCount and it will work. (see https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/GUI/Toolbar.cs) If you make that change, feel free to make another PR, it's a better fix!

Frank-99 commented 5 years ago

I tried to do so, but I still get the following error...

System.InvalidCastException: Specified cast is not valid. at UnityToolbarExtender.ToolbarExtender..cctor () [0x00043] in F:\Unity\Projects\ProjectName\Assets\ToolbarExtender\Scripts\Editor\ToolbarExtender.cs:24 UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes(Type[])

marijnz commented 5 years ago

It's not an array anymore, it's an int now. So instead of casting to an array and getting the length, just cast the result of GetValue to an int.

Frank-99 commented 5 years ago

Yeah, sorry... I'm really tired, and when I saw the error I just assumed it was the same as before, without even checking, my bad ahah

Frank-99 commented 5 years ago

Plus the heat is really a killer today, here... Anyway, issue should be fixed now! Glad i was able to help a little more :)

marijnz commented 5 years ago

Cool, enjoy the heat a bit if you can ;)