private static bool DoBookButton(Vector2 position, Texture2D image, Texture2D imageOver, Rect viewport, bool flip)
        {
            var imageSize  = new Vector2(image.width, image.height);
            var buttonRect = new Rect(position, imageSize);

            buttonRect = buttonRect.AdjustToViewport(800, 600, viewport);
            var mouseRect = buttonRect;

            if (flip)
            {
                buttonRect.x    += buttonRect.width;
                buttonRect.width = -buttonRect.width;
            }

            var isOver = mouseRect.Contains(Event.current.mousePosition);

            GUI.DrawTexture(buttonRect, isOver ? imageOver : image);

            if (isOver && Event.current.isMouse && Event.current.type == EventType.MouseDown && Event.current.button == 0)
            {
                Event.current.Use();
                return(true);
            }

            return(false);
        }
Пример #2
0
        private static Vector2 DoArrow(Vector2 position, Texture2D image, Texture2D imageOver, Rect viewport, bool flip, out bool selected, int controlId)
        {
            var imageSize  = new Vector2(image.width, image.height);
            var buttonRect = new Rect(position, imageSize);

            buttonRect = buttonRect.AdjustToViewport(800, 600, viewport);
            var mouseRect = buttonRect;

            if (flip)
            {
                buttonRect.x    += buttonRect.width;
                buttonRect.width = -buttonRect.width;
            }

            var isOver = mouseRect.Contains(Event.current.mousePosition);

            GUI.DrawTexture(buttonRect, isOver ? imageOver : image);

            selected = false;
            switch (Event.current.type)
            {
            case EventType.MouseDown:

                if (isOver && Event.current.isMouse && Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    GUIUtility.hotControl = controlId;
                    selected = true;
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (image && GUIUtility.hotControl == controlId)
                {
                    GUIUtility.hotControl = 0;
                }
                break;

            case EventType.MouseDrag:
                if (image && GUIUtility.hotControl == controlId)
                {
                    buttonRect.position += Event.current.delta;
                    GUI.changed          = true;
                    Event.current.Use();
                }
                break;
            }

            if (flip)
            {
                buttonRect.width = -buttonRect.width;
                buttonRect.x    -= buttonRect.width;
            }

            buttonRect = buttonRect.ViewportToScreen(800, 600, viewport);
            return(buttonRect.position);
        }