예제 #1
0
        static public bool ClickZone(Rect rect)
        {
            GUIControlHandle handle = GetControlHandle(FocusType.Passive);

            switch (handle.GetEventType())
            {
            case EventType.MouseDown:
                if (rect.Contains(handle.GetEvent().mousePosition))
                {
                    handle.CaptureControl();
                }

                break;

            case EventType.MouseUp:
                if (handle.ReleaseControl() && rect.Contains(handle.GetEvent().mousePosition))
                {
                    handle.UseEvent();
                    return(true);
                }

                break;
            }

            return(false);
        }
예제 #2
0
        static public bool MouseArea(Rect rect, out Vector2 position, bool should_confine_position, bool should_position_be_relative)
        {
            GUIControlHandle handle = GetControlHandle(FocusType.Passive);

            switch (handle.GetEventType())
            {
            case EventType.MouseDown:
                if (rect.Contains(handle.GetEvent().mousePosition))
                {
                    handle.CaptureControl();
                }

                break;

            case EventType.MouseUp:
                handle.ReleaseControl();
                break;
            }

            if (handle.IsControlCaptured() && handle.GetEventType().IsMouseRelated())
            {
                position = handle.GetEvent().mousePosition;

                if (should_confine_position)
                {
                    position = position.BindWithin(rect);
                }

                if (should_position_be_relative)
                {
                    position = position - rect.min;
                }

                return(true);
            }

            position = new Vector2();
            return(false);
        }