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

Clean-up code + working in Unity 2018.3.0b{x} #36

Closed
wants to merge 6 commits into from

Conversation

z3nth10n
Copy link

Well, I have clean-up code with CodeMaid.

Also, I have fixed the possible problems for Unity 2018.3b (must be reviewed)

NullReferenceException: Object reference not set to an instance of an object
Zios.ObjectExtension.GetVariableType (System.Object current, System.String name, System.Int32 index, System.Reflection.BindingFlags flags) (at Assets/unity-themes/Codebase/Extensions/Object/ObjectReflection.cs:259)
Zios.ObjectExtension.InstanceVariable (System.Object current, System.String name, System.Int32 index, System.Reflection.BindingFlags flags, System.Boolean force) (at Assets/unity-themes/Codebase/Extensions/Object/ObjectReflection.cs:491)
Zios.Interface.ThemeSkin.ApplyMain (Zios.Interface.Theme theme) (at Assets/unity-themes/Codebase/Systems/Interface/Themes/Editor/ThemeSkinset.cs:293)
Zios.Interface.ThemeSkinset.Apply (Zios.Interface.Theme theme) (at Assets/unity-themes/Codebase/Systems/Interface/Themes/Editor/ThemeSkinset.cs:106)
Zios.Interface.Theme.Apply (System.String themeName, System.Boolean forceWrite) (at Assets/unity-themes/Codebase/Systems/Interface/Themes/Editor/ThemeSystem.cs:264)
Zios.Interface.Theme.ApplySettings () (at Assets/unity-themes/Codebase/Systems/Interface/Themes/Editor/ThemeSystem.cs:257)
Zios.Interface.Theme.Update () (at Assets/unity-themes/Codebase/Systems/Interface/Themes/Editor/ThemeSystem.cs:93)
Zios.Interface.ThemeWindow.OnGUI () (at Assets/unity-themes/Codebase/Systems/Interface/Themes/Editor/ThemeWindow.cs:29)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at :0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at :0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at :0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:342)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:336)
UnityEditor.HostView.OldOnGUI () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:129)
UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:266)
UnityEngine.Experimental.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:438)
UnityEngine.Experimental.UIElements.IMGUIContainer.HandleIMGUIEvent () (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:412)
UnityEngine.Experimental.UIElements.ImmediateStylePainter.DrawImmediate (System.Action callback) (at C:/buildslave/unity/build/Modules/UIElements/ImmediateStylePainter.cs:113)
UnityEngine.Experimental.UIElements.IMGUIContainer.DoRepaint (UnityEngine.Experimental.UIElements.IStylePainter painter) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:98)
UnityEngine.Experimental.UIElements.VisualElement.Repaint (UnityEngine.Experimental.UIElements.IStylePainter painter) (at C:/buildslave/unity/build/Modules/UIElements/VisualElement.cs:829)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater.PaintSubTree (UnityEngine.Experimental.UIElements.VisualElement root, UnityEngine.Matrix4x4 offset, System.Boolean shouldClip, System.Boolean shouldCache, UnityEngine.Rect currentGlobalClip) (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeRepaintUpdater.cs:310)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater.PaintSubTreeChildren (UnityEngine.Experimental.UIElements.VisualElement root, UnityEngine.Matrix4x4 offset, System.Boolean shouldClip, System.Boolean shouldCache, UnityEngine.Rect textureClip) (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeRepaintUpdater.cs:328)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater.PaintSubTree (UnityEngine.Experimental.UIElements.VisualElement root, UnityEngine.Matrix4x4 offset, System.Boolean shouldClip, System.Boolean shouldCache, UnityEngine.Rect currentGlobalClip) (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeRepaintUpdater.cs:314)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater.Update () (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeRepaintUpdater.cs:35)
UnityEngine.Experimental.UIElements.VisualTreeUpdater.UpdateVisualTree () (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeUpdater.cs:70)
UnityEngine.Experimental.UIElements.Panel.Repaint (UnityEngine.Event e) (at C:/buildslave/unity/build/Modules/UIElements/Panel.cs:507)
UnityEngine.Experimental.UIElements.UIElementsUtility.DoDispatch (UnityEngine.Experimental.UIElements.BaseVisualElementPanel panel) (at C:/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:230)
UnityEngine.Experimental.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:68)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)

Chaging "public static Type GetVariableType(this object current, string name, int index = -1, BindingFlags flags = allFlags)" to this:

    public static Type GetVariableType(this object current, string name, int index = -1, BindingFlags flags = allFlags)
    {
        try
        {
            Type type = current is Type ? (Type)current : current.GetType();
            var field = Class.GetField(type, name, flags);
            if (!field.IsNull())
            {
                if (index != -1)
                {
                    if (current is Vector3) { return typeof(float); }
                    IList list = (IList)field.GetValue(current);
                    return list[index].GetType();
                }
                return field.FieldType;
            }
            var property = Class.GetProperty(type, name, flags);
            return property.IsNull() ? typeof(Type) : property.PropertyType;
        }
        catch
        {
            return typeof(Type);
        }
    }

Also, you need .NET 4.6 to compile:

...

BitStreamExtensions class can be removed too. Because it's doing nothing and giving error at compile time.

Copy link
Collaborator

@bradsmithee bradsmithee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much appreciation on taking the time to examine and alter the Zios Themes code; however, our coding conventions are quite a bit different than many of your "cleanup" changes -- namely related to whitespacing. https://docs.google.com/document/d/17nn8QXnsr0hVL8Y5Tja0byp3mNOqi2wnSVz7moz7twA/edit

Additionally, most of the .meta files are required by Unity in order to maintain references in the existing GUISkin files. In an upcoming release, I'll be moving the whole system to a Unity package for cleaner deployment.

Feel free to contact me on Discord (Bradical#2561) for more discussion about design/development!

@z3nth10n
Copy link
Author

Ok, I will send you a message later, thanks! If you want to merge it I can revert code conventions to default.

Also, it's now working on Unity 2018.3.0b6.

EditorApplication.update += ThemeWindow.ShowWindow;

Why you need to create a new window on every EditorApplication update callback, is better to set it though by a MenuItem as I done before.

@z3nth10n z3nth10n changed the title Clean-up code + working in Unity 2018.3b Clean-up code + working in Unity 2018.3.0b{x} Oct 21, 2018
@bradsmithee
Copy link
Collaborator

is better to set it though by a MenuItem as I done before.

Creating the window through a MenuItem would require the user to do so every time to keep the system in sync. Since I use a 1x1 pixel hidden popup type window, it doesn't always persist between Unity restarts (and especially not layout changes/resets).

Why you need to create a new window on every EditorApplication update callback

It should just be a window check that only creates it once. There's a version on the active SVN (which isn't synced to this GIT yet) http://ziosproject.com/Shared/Codebase/@Unity/Editor/Systems/Themes/ that should fix the window creation in newer versions (as well as address some other issues). I wanted to resolve some of the other errors and missing styles and make another major release -- if you are interested in helping out.

@z3nth10n
Copy link
Author

z3nth10n commented Oct 22, 2018

Ok, I just fixed it, I have added a method call ShowWindow() instead of handling it at EditorApplication.update event, this should do the trick too. (For some reason the IsNull() flag isn't executed well, so, calling once is enough)

Also, I updated PreferenceItem("Themes") attribute, because it will be deleted on 2018.3.0 versions. Now, this is done with SettingsProvider.

@Swivelgames
Copy link

Any chance this will get released soon?

@z3nth10n
Copy link
Author

z3nth10n commented Jan 8, 2019

Last night I was talking with Brad, and we reach the same point.

So, yes, I will upload the latest revision (r617) from SVN repo to Github.

Now it's uploaded: #37. Closing.

@z3nth10n z3nth10n closed this Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants