Ejemplo n.º 1
0
    // ########################################
    // Player Input functions
    // ########################################

    #region Player Input functions

    // Toggle Open or lock
    void MouseButtonUp(int Button)
    {
        FCMain pMain = GetHitChest(Input.mousePosition);

        if (pMain != null)
        {
            if (Button == 0)
            {
                pMain.ToggleOpen();
            }
            else if (Button == 1)
            {
                pMain.ToggleLock();
            }
        }
    }
Ejemplo n.º 2
0
    // Update is called every frame, if the MonoBehaviour is enabled.
    // http://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html
    void Update()
    {
        // If there is single touch input
        if (Input.touchCount == 1)
        {
            // Get touch
            Touch touch = Input.GetTouch(0);

            // Touch began
            if (touch.phase == TouchPhase.Began)
            {
                // Keep current touch phase
                currentSingleTouchPhase = TouchPhase.Began;

                // reset touch stationary duration
                TouchStationaryDuration = 0;
            }
            // Touch moves
            else if (touch.phase == TouchPhase.Moved)
            {
                // Keep current touch phase
                currentSingleTouchPhase = TouchPhase.Moved;

                // reset touch stationary duration
                TouchStationaryDuration = 0;
            }
            // Touch stationary
            else if (touch.phase == TouchPhase.Stationary)
            {
                // Check if there is a hit on a chest
                FCMain pMain = GetHitChest(touch.position);
                if (pMain != null)
                {
                    // Keep current touch phase
                    currentSingleTouchPhase = TouchPhase.Stationary;

                    // If last touch phase is stationary
                    if (previousSingleTouchPhase == TouchPhase.Stationary)
                    {
                        // Increase stationary duration
                        TouchStationaryDuration += Time.deltaTime;

                        // Toggle lock/unlock if stationary has reached it limitation duration
                        if (TouchStationaryDuration > TouchStationaryTime && TouchStationaryDuration < TouchStationaryTime + 1)
                        {
                            // Toggle lock/unlock
                            pMain.ToggleLock();
                            TouchStationaryDuration = TouchStationaryTime * 2;
                        }
                    }
                }
            }
            // Touch ended
            else if (touch.phase == TouchPhase.Ended)
            {
                // Keep current touch phase
                currentSingleTouchPhase = TouchPhase.Ended;

                // If last touch phase is not stationary
                if (previousSingleTouchPhase == TouchPhase.Began || (previousSingleTouchPhase == TouchPhase.Stationary && TouchStationaryDuration < TouchStationaryTime))
                {
                    // Toggle open/close
                    FCMain pMain = GetHitChest(touch.position);
                    if (pMain != null)
                    {
                        pMain.ToggleOpen();
                    }
                }

                // Reset touch stationary duration
                TouchStationaryDuration = 0;
            }

            // Store current touch phase in previous touch phase
            previousSingleTouchPhase = currentSingleTouchPhase;

            // set currentSingleTouchPhase to TouchPhase.Canceled
            currentSingleTouchPhase = TouchPhase.Canceled;
        }
        // Mouse inputs
        else
        {
            // User pressed the left mouse up
            if (Input.GetMouseButtonUp(0))
            {
                MouseButtonUp(0);
            }
            // User pressed the right mouse up
            else if (Input.GetMouseButtonUp(1))
            {
                MouseButtonUp(1);
            }
        }
    }