Giter Club home page Giter Club logo

unity-toolbar-extender's People

Contributors

bgr avatar brogan89 avatar frank-99 avatar garrafote avatar gjh33 avatar marijnz avatar ondrejpetrzilka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity-toolbar-extender's Issues

Alternative approach

Hey, I was thinking about different approach:

  1. Create wrapper class deriving from Toolbar
  2. Override OldOnGUI(), provide callback
  3. Replace instance of the Toolbar in Editor

Sounds impossible, but it actually isn't.

  1. To derive from Toolbar, you'll have to do it in IL, because it's internal. See attached IL file. You can ignore GameObjectEditor that's something else :)
    I've also attached mockup of classes, which I compile and then disassemble into IL
    UnityIL.Editor.il.txt
    Mockup.cs.txt

  2. There's internal ToolbarWrapper and static class ToolbarExtension which exposes callbacks and other useful methods (see mockups)

  3. Create wrapper, copy all serialized properties, replace it
    MainView.children[0] is always Toolbar, just replace it
    There's also Toolbar.get (field surprisingly), which is probably a good idea to replace
    ToolbarExtension.cs.txt

IL compilation command:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\ilasm UnityIL.Editor.il /dll /OUTPUT=%~dp0UnityIL.Editor.dll

Simple case works, see screenshot below.
I've encountered some issues when switching layout (not sure why).
Done on Unity 2018.2.10f1

toolbarext

Remove default UI elements

It would be great to have the ability to move/edit/remove the existing toolbar buttons for further flexibility.

Having these take up less space would be great.
image

broken in 2020.2.0f1

Hi, Unity just releases 2020.2.0f1,
and unfortunately your hack fails now, it seems that some modifications have changed in that UI.
(m_viewVisualTree is null now)

Do you think you can find a way to still find the toolbar ?
Your plugin is sooo helpful !

The UI debugger works with the toolbar, if that can help you:
image

Thank you^^

Doesnt work in 2021.

It properly draw GUI but it doesn't handle mouse events properly... drop-down doesn't open, etc.

Unity 2020.1 compatability

In Unity 2020.1 UnityEditor.GUIView doesn't have a "visualTree" property animore. This results in a Null reference exception on line 46 in ToolbarCallback

Dragging Editor between two different-DPI displays makes added buttons disappear

Hello!

Windows allows you to change the scaling settings for a display by right-clicking the desktop and selecting "Display settings." It's possible to set different displays to different scales; for example, one monitor could have 100% scale, and another could have 150% scale.

If the main Unity Editor window is dragged from one monitor to another, and if the two monitors have different scaling settings in Windows, any custom content added to the toolbar using unity-toolbar-extender will disappear. It will reappear if Unity enters or exits Play Mode, if the Editor layout is changed, or if script compilation occurs.

It appears that changing the main editor's DPI causes the toolbar to be visually reset (which wipes out custom UI), but does not delete the toolbar's ScriptableObject (which is what unity-toolbar-extender checks to trigger re-adding the custom UI:

// Relying on the fact that toolbar is ScriptableObject and gets deleted when layout changes
if (m_currentToolbar == null)

I tried also re-adding the buttons in response to any change in Screen.dpi or EditorGUIUtility.pixelsPerPoint. This fixed the dragging issue if just one window was open, but it had a side effect: if the Editor had multiple windows open, and they were on different DPI windows, moving the mouse from one window to another would cause many duplicate copies of the custom UI to be added to the toolbar.

Manually repaint on demand?

Hi, love this asset!
Is there a way to force a repaint? to let's say show a timer.
I didn't find any. I can register a callback on EditorApplication.update but I didn't find what to call..

Request for editor layout buttons

I'm not sure how to do it but I would like to make 4 buttons for the different editor layouts so I can quickly switch between them.

Can you help me out?

Allow to use UIToolkit

It seems that the current way is to inject IMGUIContainer, maybe it would be possible to allow us to use just UIToolkit? It would make styling consistent with the existing UI a lot easier

PlayPauseStop Buttons are off center

Hey, I'm working on a fix for the buttons which seems to be off center in 2019. I'm following the same math in the Toolbar.cs file and I'll pull a new request afterwards.

I wanted to make sure that I was making it compatible with older version, so I wanted to ask if the position was calculated like this in 2018 and earlier:
float playButtonsPosition = (EditorGUIUtility.currentViewWidth - 100) / 2;
because now it's like the following:
float playButtonsPosition = Mathf.RoundToInt ((EditorGUIUtility.currentViewWidth - 140) / 2);
if it is, I'll use an #if and #else for the different versions, otherwise I'll just replace it :)

Doesn't work with Button on 2021.1.15f1

I've updated my project to version 2021.1.15f1 and for some reason, it is not returning true when I press the button.

I'm using it like this:

var test = GUILayout.Button("Test");

The test is always false. Additionally, it looks like it's constantly active.

image

Any idea how to fix it?

2021.3.0 LTS

Hey! I just wanted to say that in the last LTS update 2021.3.0 LTS, the toolbar is shown, but it's "disabled", we can hover stuffs, tooltips are shown if any, but left or right click doesn't work on any buttons.

Support Unity Package Manager

It would be cool if the project would support the Unity Package Manager.
I have made a start to this in my fork if you wanted to check it out.

The only major thing is I removed the examples as the developer can't remove them if they want because packages are immutable. I'm not really sure how to handle that.

If you want to go down this route I can make a way to turn off examples so developer doesn't need to see them.

Thanks for this code, it is very handy :)

Unity 2023.1.0 a25 icon alignment issue

Screenshot 2023-01-13 at 19 56 10

In Unity 2023.1.0 a25

The icons ar not aligned in the center of the button but on the left as can be seen in the screenshot.
Perhaps its a unity beta bug, or unity has changed something.

Simple approach

By taking advantage of UIElements, we can attach drawing handler right AFTER the toolbar.

This works well when resizing window and changing layouts. Tested on Unity 2018.2.10f1.
Implementation could be probably improved:

  • not using reflection heavy code every update
  • instead of 'hacking' existing IMGUIContainer try adding a new one (visualTree.Add)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEditor;
using System.Reflection;
using UnityEngine.Experimental.UIElements;

[InitializeOnLoad]
public static class ToolbarExtension
{
    static Type m_toolbarType = typeof(Editor).Assembly.GetType("UnityEditor.Toolbar");
    static Type m_guiViewType = typeof(Editor).Assembly.GetType("UnityEditor.GUIView");
    static PropertyInfo m_viewVisualTree = m_guiViewType.GetInstanceProperty("visualTree");
    static FieldInfo m_imguiContainerOnGui = typeof(IMGUIContainer).GetInstanceField("m_OnGUIHandler");

    static ToolbarExtension()
    {
        EditorApplication.update -= OnUpdate;
        EditorApplication.update += OnUpdate;
    }

    private static void OnUpdate()
    {
        // Find toolbar
        var toolbar = (ScriptableObject)Resources.FindObjectsOfTypeAll(m_toolbarType).FirstOrDefault();

        // Get it's visual tree
        var visualTree = (VisualElement)m_viewVisualTree.GetValue(toolbar);
        
        // Get first child which 'happens' to be toolbar IMGUIContainer
        var container = (IMGUIContainer)visualTree.Children().First();

        // Attach our handler
        var handler = (Action)m_imguiContainerOnGui.GetValue(container);
        handler -= OnGUI;
        handler += OnGUI;
        m_imguiContainerOnGui.SetValue(container, handler);
    }

    private static void OnGUI()
    {
        var buttonRect = new Rect(Screen.width / 2 + 50, 0, 100, 30);
        buttonRect.y = 4;

        if (GUI.Button(buttonRect, "TestButton"))
        {
            Debug.Log("Pressed");
        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.