예제 #1
0
    void Update( )
    {
        if (m_fLastStateUpdate > m_fMaxInactiveTime)
        {
            Debug.Log("Changed reference point.");
            m_vStartLooking    = GyroToUnityVec();
            m_fLastStateUpdate = 0;
        }

        if (m_GPState == eGesturePhase.SLEEP || m_GPState == eGesturePhase.TIME_OUT)
        {
            m_fLastStateUpdate += Time.deltaTime;
        }
        else
        {
            m_fLastStateUpdate = 0;
        }

        //If is outside of the threshold.
        if (m_GPState == eGesturePhase.TIME_COUNT)
        {
            m_fTimeCount += Time.deltaTime;
        }

        Vector3 m_vActualGyroPos = GyroToUnityVec( );

        if (m_GPState == eGesturePhase.SLEEP)
        {
            if (!IsGyroInsideThreshold(true, false))
            {
                m_fTimeCount  = 0;
                m_GPState     = eGesturePhase.TIME_COUNT;
                m_vMovedPos.x = (m_vStartLooking.x - m_vActualGyroPos.x > m_fThresholds) ? 1 : -1;
            }
            if (!IsGyroInsideThreshold(false, true))
            {
                m_fTimeCount  = 0;
                m_GPState     = eGesturePhase.TIME_COUNT;
                m_vMovedPos.y = (m_vStartLooking.y - m_vActualGyroPos.y > m_fThresholds) ? 1 : -1;
            }
        }
        // Detect if it's near the start looking
        if (m_GPState == eGesturePhase.TIME_OUT && IsGyroInsideThreshold(true, true))
        {
            m_GPState = eGesturePhase.SLEEP;
            EventManager.TriggerEvent(eGyroEvents.THRESHOLD);
        }

        // If the player was not trying to move/stop.
        if (m_GPState == eGesturePhase.TIME_COUNT)
        {
            if (m_fTimeCount > m_fMaxDetectTimeForReset)
            {
                m_GPState = eGesturePhase.TIME_OUT;

                if (m_vMovedPos.x != 0)
                {
                    EventManager.TriggerEvent(m_vMovedPos.x > 0 ? eGyroEvents.LEFT : eGyroEvents.RIGHT);
                }
                if (m_vMovedPos.y != 0)
                {
                    EventManager.TriggerEvent(m_vMovedPos.y > 0 ? eGyroEvents.UP : eGyroEvents.DOWN);
                }
                m_vMovedPos.x = 0;
                m_vMovedPos.y = 0;
            }
            else if (IsGyroInsideThreshold(true, true))
            {
                if (m_vMovedPos.x != 0)
                {
                    EventManager.TriggerEvent(m_vMovedPos.x > 0 ? eGyroEvents.LEFT_RIGHT : eGyroEvents.RIGHT_LEFT);
                }
                if (m_vMovedPos.y != 0)
                {
                    EventManager.TriggerEvent(m_vMovedPos.y > 0 ? eGyroEvents.UP_DOWN : eGyroEvents.DOWN_UP);
                }
                m_vMovedPos.x = 0;
                m_vMovedPos.y = 0;
                m_GPState     = eGesturePhase.SLEEP;
            }
        }
    }
예제 #2
0
    void Update( )
    {
        //If is outside of the threshold.
        if (m_GPState == eGesturePhase.TIME_COUNT)
        {
            m_fTimeCount += Time.deltaTime;
        }

        Vector3 m_vActualGyroPos = GyroToUnityVec( );

        if (m_GPState == eGesturePhase.SLEEP)
        {
            if (!IsGyroInsideThreshold(true, false))
            {
                if (m_bDebug)
                {
                    Debug.Log("TIME_COUNT Started in axis X.");
                }
                m_fTimeCount  = 0;
                m_GPState     = eGesturePhase.TIME_COUNT;
                m_vMovedPos.x = (m_vStartLooking.x - m_vActualGyroPos.x > m_fThresholds) ? 1 : -1;
            }
            if (!IsGyroInsideThreshold(false, true))
            {
                if (m_bDebug)
                {
                    Debug.Log("TIME_COUNT Started in axis Y.");
                }
                m_fTimeCount  = 0;
                m_GPState     = eGesturePhase.TIME_COUNT;
                m_vMovedPos.y = (m_vStartLooking.y - m_vActualGyroPos.y > m_fThresholds) ? 1 : -1;
            }
        }
        // Detect if it's near the start looking
        else if (m_GPState == eGesturePhase.TIME_OUT && IsGyroInsideThreshold(true, true))
        {
            if (m_bDebug)
            {
                Debug.Log("Returned to Threshold, current state: SLEEP.");
            }
            m_GPState = eGesturePhase.SLEEP;
        }

        // If the player was not trying to move/stop.
        if (m_GPState == eGesturePhase.TIME_COUNT)
        {
            if (m_fTimeCount > m_fMaxDetectTimeForReset)
            {
                m_GPState = eGesturePhase.TIME_OUT;
                if (m_bDebug)
                {
                    Debug.Log("TIME_OUT, need to return inside the Threshold.");
                }

                if (m_vMovedPos.x != 0)
                {
                    EventManager.TriggerEvent(m_vMovedPos.x > 0 ? eGyroEvents.LEFT : eGyroEvents.RIGHT);
                }
                if (m_vMovedPos.y != 0)
                {
                    EventManager.TriggerEvent(m_vMovedPos.y > 0 ? eGyroEvents.UP : eGyroEvents.DOWN);
                }
                m_vMovedPos.x = 0;
                m_vMovedPos.y = 0;
            }
            else if (IsGyroInsideThreshold(true, true))
            {
                if (m_vMovedPos.x != 0)
                {
                    EventManager.TriggerEvent(m_vMovedPos.x > 0 ? eGyroEvents.LEFT_RIGHT : eGyroEvents.RIGHT_LEFT);
                }
                if (m_vMovedPos.y != 0)
                {
                    EventManager.TriggerEvent(m_vMovedPos.y > 0 ? eGyroEvents.UP_DOWN : eGyroEvents.DOWN_UP);
                }
                m_vMovedPos.x = 0;
                m_vMovedPos.y = 0;
                m_GPState     = eGesturePhase.SLEEP;
            }
        }
    }
예제 #3
0
    void Update( )
    {
        // If the player is out of the offset the timer start to count
        if (m_GPState == eGesturePhase.TIME_COUNT)
        {
            m_fTime += Time.deltaTime;
        }

        /* ======================== Begin Movement ======================== */

        // Detect up/down to start timer to start movement
        if ((m_GPState == eGesturePhase.SLEEP || m_bMoving) && Mathf.Abs(m_vStartLooking.x - m_CachedTransform.eulerAngles.x) > m_fDetectMoveOffsetY)
        {
            if (m_bDebug)
            {
                Debug.Log("TIME_COUNT started");
            }
            m_fTime    = 0;
            m_GPState  = eGesturePhase.TIME_COUNT;
            m_bUpFirst = (m_vStartLooking.x - m_CachedTransform.eulerAngles.x > 0) ? true : false;
        }

        // Detect if it's near the start looking
        if (m_GPState == eGesturePhase.TIME_OUT && Mathf.Abs(m_vStartLooking.x - m_CachedTransform.eulerAngles.x) < m_fOffsetCenter)
        {
            if (m_bDebug)
            {
                Debug.Log("Current state: SLEEP");
            }
            m_GPState = eGesturePhase.SLEEP;
        }

        // If the player was not trying to move/stop.
        if (m_GPState == eGesturePhase.TIME_COUNT && m_fTime > m_fMaxDetectTimeMove)
        {
            m_GPState = eGesturePhase.TIME_OUT;
        }

        // The player wants to walk/stop.
        if (m_GPState == eGesturePhase.TIME_COUNT && m_vStartLooking.x - m_CachedTransform.eulerAngles.x > (m_bUpFirst ? m_fDetectMoveOffsetY : -m_fDetectMoveOffsetY))
        {
            m_bMoving = !m_bMoving;
            m_GPState = eGesturePhase.SLEEP;
        }

        /* ======================== Movement ======================== */
        if (Input.GetKey(KeyCode.W) || m_bMoving)
        {
            Vector3 tmpVecFB = m_fAphaFB * new Vector3(m_CachedTransform.forward.x, 0, m_CachedTransform.forward.z);
            transform.Translate(tmpVecFB);
        }
        else if (Input.GetKey(KeyCode.S))
        {
            Vector3 tmpVecFB = m_fAphaFB * new Vector3(m_CachedTransform.forward.x, 0, m_CachedTransform.forward.z);
            transform.Translate(tmpVecFB * -1);
        }

        if (Input.GetKey(KeyCode.A))
        {
            Vector3 tmpVecRL = m_fAphaRL * new Vector3(m_CachedTransform.right.x, 0, m_CachedTransform.right.z);
            transform.Translate(tmpVecRL * -1);
        }
        else if (Input.GetKey(KeyCode.D))
        {
            Vector3 tmpVecRL = m_fAphaRL * new Vector3(m_CachedTransform.right.x, 0, m_CachedTransform.right.z);
            transform.Translate(tmpVecRL);
        }
    }