Skip to content

Check Mouse over any GUILayout controll

User created LBs

Check Mouse over any GUILayout controll

Postby Neodrop » 05 Jul 2011, 00:43

This node will automatically check whether the mouse is inside last GUILayout controll. For example, in this graph you will check the mouse over Label :

mouseOverRect.jpg


Copy this code inside any .cs file somewhere inside your project.

P.S. I will include this node in Universe 1.21

Syntax:
Using csharp Syntax Highlighting
using Antares.Vizio.Runtime;
using UnityEngine;
[VisualLogicBlockDescription(@"Check the MouseOver condition after any GUILayout controll. Just connect this node right after your controll.
For example : GUILayoutDo-Label >> this node"
)]
    [VisualLogicBlock("Mouse Over Rect", "GUILayout", ParentName = "Check")]
    public class MouseOverGUILayoutRect : LogicBlock
    {
        [Parameter(VariableType.Out, typeof(bool), Name = "Mouse Over GUI")]
        public Variable overGui;

        [EntryTrigger("Check Mouse Over")]
        public void Check()
        {
            if (Event.current == null)
            {
                ActivateTrigger(1);
                return;
            }
            if (Event.current.type == EventType.Repaint) // We will check it only one time per frame
            {
                Rect r = GUILayoutUtility.GetLastRect();
                overGui.Value = r.Contains(Event.current.mousePosition);
            }
            ActivateTrigger((bool)overGui.Value ? 0 : 1);
        }

        public override void OnInitializeDefaultData()
        {
            RegisterOutputTrigger("TRUE");
            RegisterOutputTrigger("FALSE");
        }
    }
 
Parsed in 0.011 seconds, using GeSHi 1.0.8.4
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: Check Mouse over any GUILayout controll

Postby Neodrop » 05 Jul 2011, 01:09

Update : Added ("MOUSE DOWN" Out trigger)

Syntax:
Using csharp Syntax Highlighting
using Antares.Vizio.Runtime;
using UnityEngine;
[VisualLogicBlockDescription(@"Check the MouseOver condition after any GUILayout controll. Just connect this node right after your controll.
For example : GUILayoutDo-Label >> this node"
)]
    [VisualLogicBlock("Mouse Over Rect", "GUILayout", ParentName = "Check")]
    public class MouseOverGUILayoutRect : LogicBlock
    {
        [Parameter(VariableType.Out, typeof(bool), Name = "Mouse Over GUI")]
        public Variable overGui;

        [EntryTrigger("Check Mouse Over")]
        public void Check()
        {
            Event e = Event.current;
            if (e == null)
            {
                ActivateTrigger(1);
                return;
            }
            if (e.type == EventType.Repaint)
            {
                Rect r = GUILayoutUtility.GetLastRect();
                overGui.Value = r.Contains(Event.current.mousePosition);
            }
            else if ((bool)overGui.Value && e.type == EventType.MouseDown)
            {
                ActivateTrigger(2);
            }
            ActivateTrigger((bool)overGui.Value ? 0 : 1);
        }

        public override void OnInitializeDefaultData()
        {
            RegisterOutputTrigger("TRUE");
            RegisterOutputTrigger("FALSE");
            RegisterOutputTrigger("MOUSE DOWN");
        }
    }
 
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: Check Mouse over any GUILayout controll

Postby Visionaries 777 » 05 Jul 2011, 02:20

Awesome! Thanks Neodrop :)
User avatar
Visionaries 777
 
Posts: 50
Joined: 29 Mar 2011, 07:15
Location: Hong Kong


Return to Smart Blocks

Who is online

Registered users: No registered users