Home > Mobile >  How to keep multiple editor tool enabled at once in Unity GUI?
How to keep multiple editor tool enabled at once in Unity GUI?

Time:11-24

I have created a simple custom editor tool, which allows me to keep mouse position in a straight line. I require this to draw texture on a terrain in a straight line. Unfortunately, when I enable "Paint texture" tool in the terrain editor in inspector, my custom tool gets disabled and vice-versa. How can I keep both my custom tool and terrain paint tool enabled at once?

Custom tool selected but paint texture is deactivated- Custom tool selected but paint texture is deactivated

Custom tool got deselected on paint texture selection- Custom tool got deselected on paint texture selection

Following is the OnToolGUI method

    public override void OnToolGUI(EditorWindow window)
    {
        HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
        Event e = Event.current;
        if (!(window is SceneView))
            return;

        if (!ToolManager.IsActiveTool(this))
            return;

        if (e.shift)
        {
            if (e.type == EventType.MouseDown)
            {
                if (e.button == 0)
                {
                    downY = e.mousePosition.y;
                }
            }
            if (e.type == EventType.MouseDrag)
            {
                if (e.button == 0)
                {
                    e.mousePosition = new Vector2(e.mousePosition.x, downY);
                    Debug.Log("Mouse Position: "   e.mousePosition);
                }
            }
        }

CodePudding user response:

As mentioned in the comments I guess it simply is the nature of the tools that they are exclusive and you can only have one active at a time.

As alternative I would rather simply

  • enable/disable this via a general header menu entry
  • (optionally) store that decision persistent in enter image description here


    Then using this as start point you can probably still try to somehow integrate this somewhere more nicely into the SceneView menus - but maybe that is also overkill ;)

  • Related