Beispiel #1
0
        /// <summary>
        /// Method called each frame when the menu is sliding in.
        /// It checks for possible slide out triggers.
        /// </summary>
        private void ProcessMenuSlidingIn()
        {
            MouseTouchInput theInput = GetOneTouch();

            if (theInput != null)
            {
                MouseTouchInput touch = GetOneTouch();
                if (touch != null)
                {
                    Vector2 deltaTouch = new Vector2((touch.position.x - touchBegan.x) / Screen.width, (touch.position.y - touchBegan.y) / Screen.height);
                    if (ReachedSlideOutThreshold(deltaTouch))
                    {
                        BeginTouchOut();
                    }
                }
            }

            float time = Time.timeSinceLevelLoad - animationBegan;

            if (time > desiredDuration)
            {
                SetMenuState(MenuState.In);

                SetPosition(anchorMinBegan + anchorChangeRequired);
            }
            else
            {
                SetPosition(EaseOut(time, anchorMinBegan, anchorChangeRequired, desiredDuration));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Method called each frame when the menu is sliding out.
        /// It checks for possible slide in triggers, but only if no other menu is shown.
        /// </summary>
        private void ProcessMenuSlidingOut()
        {
            MouseTouchInput theInput = GetOneTouch();

            if (theInput != null)
            {
                MouseTouchInput touch = GetOneTouch();
                if (touch != null)
                {
                    Vector2 deltaTouch = new Vector2((touch.position.x - touchBegan.x) / Screen.width, (touch.position.y - touchBegan.y) / Screen.height);
                    if (ReachedSlideInThreshold(deltaTouch))
                    {
                        lock (isAMenuOpenLock)
                        {
                            if (hasMenuOpen || !isAMenuOpen)
                            {
                                isAMenuOpen = true;
                                hasMenuOpen = true;
                                BeginTouchIn();
                            }
                        }
                    }
                }
            }

            float time = Time.timeSinceLevelLoad - animationBegan;

            if (time > desiredDuration)
            {
                SetMenuState(MenuState.Out);

                if (hasMenuOpen)
                {
                    lock (isAMenuOpenLock)
                    {
                        hasMenuOpen = false;
                        isAMenuOpen = false;
                    }
                }

                SetPosition(anchorMinBegan + anchorChangeRequired);

                if (moveRestWhenOpen)
                {
                    HideSnapshot();
                }
            }
            else
            {
                SetPosition(EaseIn(time, anchorMinBegan, anchorChangeRequired, desiredDuration));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Method called each frame when the menu is in.
        /// It checks for possible slide out triggers.
        /// </summary>
        private void ProcessMenuIn()
        {
            MouseTouchInput touch = GetOneTouch();

            if (touch != null)
            {
                Vector2 deltaTouch = new Vector2((touch.position.x - touchBegan.x) / Screen.width, (touch.position.y - touchBegan.y) / Screen.height);
                if (ReachedSlideOutThreshold(deltaTouch))
                {
                    BeginTouchOut();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// This function checks for touch inputs.
        /// </summary>
        /// <returns>Array of touch inputs</returns>
        private MouseTouchInput[] GetTouches()
        {
            MouseTouchInput[] touches = new MouseTouchInput[Input.touchCount];

            for (int i = 0; i < Input.touchCount; i++)
            {
                MouseTouchInput t = new MouseTouchInput();
                t.phase    = Input.touches[i].phase;
                t.position = Input.touches[i].position;
                t.id       = Input.touches[i].fingerId;
                touches[i] = t;
            }

            return(touches);
        }
Beispiel #5
0
        /// <summary>
        /// Method called each frame when the menu is out.
        /// It checks for possible slide in triggers, but only if no other menu is shown.
        /// </summary>
        private void ProcessMenuOut()
        {
            MouseTouchInput touch = GetOneTouch();

            if (touch != null)
            {
                Vector2 deltaTouch = new Vector2((touch.position.x - touchBegan.x) / Screen.width, (touch.position.y - touchBegan.y) / Screen.height);
                if (ReachedSlideInThreshold(deltaTouch))
                {
                    lock (isAMenuOpenLock)
                    {
                        if (!isAMenuOpen)
                        {
                            isAMenuOpen = true;
                            hasMenuOpen = true;
                            BeginTouchIn();
                        }
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// This function checks for mouse inputs.
        /// </summary>
        /// <returns>Array of inputs from mouse.</returns>
        private MouseTouchInput[] GetMouseAsTouch()
        {
            List <MouseTouchInput> mouseButtonsClicked = new List <MouseTouchInput>();

            for (int i = 0; i < 3; i++)
            {
                if (Input.GetMouseButtonDown(i))
                {
                    MouseTouchInput t = new MouseTouchInput();
                    t.phase    = TouchPhase.Began;
                    t.position = Input.mousePosition;
                    t.id       = -i;
                    mouseButtonsClicked.Add(t);
                    continue;
                }
                if (Input.GetMouseButtonUp(i))
                {
                    MouseTouchInput t = new MouseTouchInput();
                    t.phase    = TouchPhase.Ended;
                    t.position = Input.mousePosition;
                    t.id       = -i;
                    mouseButtonsClicked.Add(t);
                    continue;
                }
                if (Input.GetMouseButton(i))
                {
                    MouseTouchInput t = new MouseTouchInput();
                    t.phase    = TouchPhase.Moved;
                    t.position = Input.mousePosition;
                    t.id       = -i;
                    mouseButtonsClicked.Add(t);
                    continue;
                }
            }

            return(mouseButtonsClicked.ToArray());
        }
Beispiel #7
0
        /// <summary>
        /// Method called each frame when the menu is being gestured out.
        /// It checks for gesture end to begin either slide out or slide in transition.
        /// </summary>
        private void ProcessMenuTouchOut()
        {
            MouseTouchInput theInput = GetOneTouch();

            Vector2 deltaTouch;
            float   directionDeltaTouch = 0.0f;

            bool end = false;

            if (theInput == null)
            {
                end = true;
            }
            else
            {
                if ((theInput.phase == TouchPhase.Ended) || (theInput.phase == TouchPhase.Canceled))
                {
                    end = true;
                }
            }

            if (end)
            {
                deltaTouch = new Vector2((lastTouch.x - touchBegan.x) / Screen.width / sizeRelativeToScreen.x, (lastTouch.y - touchBegan.y) / Screen.height / sizeRelativeToScreen.y);
                float deltaTime = Time.timeSinceLevelLoad - touchBeganTime;

                switch (side)
                {
                case Side.left:
                    directionDeltaTouch = -deltaTouch.x;
                    break;

                case Side.top:
                    directionDeltaTouch = deltaTouch.y;
                    break;

                case Side.right:
                    directionDeltaTouch = deltaTouch.x;
                    break;

                case Side.bottom:
                    directionDeltaTouch = -deltaTouch.y;
                    break;
                }

                if ((directionDeltaTouch * 3.0f > deltaTime) || (directionDeltaTouch > 0.6f))
                {
                    SlideOut();
                }
                else
                {
                    SlideIn();
                }

                return;
            }

            deltaTouch = new Vector2((theInput.position.x - touchBegan.x) / Screen.width, (theInput.position.y - touchBegan.y) / Screen.height);

            switch (side)
            {
            case Side.left:
                directionDeltaTouch = -deltaTouch.x / sizeRelativeToScreen.x;
                break;

            case Side.top:
                directionDeltaTouch = deltaTouch.y / sizeRelativeToScreen.y;
                break;

            case Side.right:
                directionDeltaTouch = deltaTouch.x / sizeRelativeToScreen.x;
                break;

            case Side.bottom:
                directionDeltaTouch = -deltaTouch.y / sizeRelativeToScreen.y;
                break;
            }

            if (directionDeltaTouch > 1.0f)
            {
                directionDeltaTouch = 1.0f;
            }

            if (directionDeltaTouch < 0)
            {
                touchBegan = theInput.position;
            }
            else
            {
                SetPosition(positionOut * directionDeltaTouch + positionIn * (1.0f - directionDeltaTouch));
            }

            lastTouch = theInput.position;
        }
Beispiel #8
0
        /// <summary>
        /// This function returns exactly one or none input according to the set input methods.
        /// When there are more inputs they are ignored.
        /// The behaviour is different for different "Input.simulateMouseWithTouches" values
        /// </summary>
        /// <returns>One input or NULL if none</returns>
        private MouseTouchInput GetOneTouch()
        {
            List <MouseTouchInput> inputs = new List <MouseTouchInput>();

            if (UseMouse)
            {
                inputs.AddRange(GetMouseAsTouch());

                if (Input.simulateMouseWithTouches)
                {
                    if (!UseTouches)
                    {
                        MouseTouchInput[] inputsToRemove = GetTouches();
                        foreach (MouseTouchInput input in inputsToRemove)
                        {
                            inputs.Remove(input);
                        }
                    }
                }
                else
                {
                    if (UseTouches)
                    {
                        inputs.AddRange(GetTouches());
                    }
                }
            }
            else
            {
                if (UseTouches)
                {
                    inputs.AddRange(GetTouches());
                }
            }

            if (inputs.Count == 1)
            {
                MouseTouchInput theInput = inputs[0];

                switch (theInput.phase)
                {
                case TouchPhase.Began:
                    touchID        = theInput.id;
                    touchBegan     = theInput.position;
                    touchBeganTime = Time.timeSinceLevelLoad;
                    return(theInput);

                case TouchPhase.Moved:
                    if (theInput.id != touchID)
                    {
                        touchID = int.MinValue;
                        return(null);
                    }
                    return(theInput);

                case TouchPhase.Stationary:
                    if (theInput.id != touchID)
                    {
                        touchID = int.MinValue;
                        return(null);
                    }
                    return(theInput);

                case TouchPhase.Ended:
                    if (theInput.id != touchID)
                    {
                        touchID = int.MinValue;
                        return(null);
                    }
                    return(theInput);

                case TouchPhase.Canceled:
                {
                    touchID = int.MinValue;
                    return(null);
                }

                default:
                {
                    touchID = int.MinValue;
                    return(null);
                }
                }
            }

            touchID = int.MinValue;
            return(null);
        }