예제 #1
0
        void Awake ()
        {
            m_pageHolder = new GameObject("PageHolder");
            m_pageHolderXPositions = new float[kMaxPages];

            m_basePageScale = new Vector3((Camera.main.orthographicSize * 2) * ((float)Screen.width / (float)Screen.height), // THE FLOAT CASTS ARE NESESSARY
                                           Camera.main.orthographicSize * 2,
                                           1.0f);

            m_pages = new BlankPage[kMaxPages] { new StartPage(ref m_basePageScale),
                                                 new DoubleTapPage(ref m_basePageScale),
                                                 new PinchPage(ref m_basePageScale),
                                                 new SimpleTiltingPage(ref m_basePageScale),
                                                 new MultiTouchPage(ref m_basePageScale),
                                                 new PhysicsTiltPage(ref m_basePageScale)};

            m_currentlyActivePage = null;
            m_updatedFirstPressPos = false;

            m_pixelRatio = (Camera.main.orthographicSize * 2) / Camera.main.pixelHeight;
            m_pixelRatio *= 2;

            initialisePages();
        }
예제 #2
0
        void updateTouchInput()
        {
            if (m_currentlyActivePage.isPageComplete())
            {
                for (int touch = 0; touch < Input.touchCount; ++touch)
                {
                    if (Input.GetTouch(touch).phase == TouchPhase.Began)
                    {
                        updateFirstPressPos();
                    }

                    if (Input.GetTouch(touch).phase == TouchPhase.Moved)
                    {
                        if (!m_updatedFirstPressPos)
                        {
                            updateFirstPressPos();
                        }

                        m_touchMoveDistance = (Input.mousePosition.x - m_firstPressPos) * m_pixelRatio;

                        if (m_touchMoveDistance > 2.5f)
                        {
                            m_touchMoveDistance += 1.0f;
                        }
                        else if (m_touchMoveDistance < -2.5f)
                        {
                            m_touchMoveDistance -= 1.0f;
                        }

                        m_pageHolderPos.x += m_touchMoveDistance;

                        m_firstPressPos = Input.mousePosition.x;

                    }
                    else if (Input.GetTouch(touch).phase == TouchPhase.Ended)
                    {
                        // Snap to the nearest page
                        // Cache these for better performance? (probably very very miniscule anyway)
                        float closestDist = float.MaxValue;
                        int page = 0;

                        // Snap to the closest character
                        for (int i = 0; i < kMaxPages; ++i)
                        {
                            if (Math.Abs(closestDist) > Math.Abs(m_pageHolderPos.x - m_pageHolderXPositions[i]))
                            {
                                closestDist = m_pageHolderPos.x - m_pageHolderXPositions[i];
                                page = i;
                            }
                            else if (Math.Abs(closestDist) < Math.Abs(m_pageHolderPos.x - m_pageHolderXPositions[i]))
                            {
                                break;
                            }
                        }

                        m_pageHolderPos.x = m_pageHolderXPositions[page];

                        if (m_currentlyActivePage.getPageNumber() != page)
                        {
                            m_currentlyActivePage = m_pages[page];

                            if (!m_currentlyActivePage.isPageComplete())
                            {
                                StartCoroutine(doOnPageBecomeActive(page));
                            }
                        }

                        m_updatedFirstPressPos = false;
                    }

                    // Limit the holder pos to the first and last characters if it goes over
                    if (m_pageHolderPos.x > m_pageHolderXPositions[0])
                    {
                        m_pageHolderPos.x = m_pageHolderXPositions[0];
                    }
                    else if (m_pageHolderPos.x < m_pageHolderXPositions[kMaxPages - 1])
                    {
                        m_pageHolderPos.x = m_pageHolderXPositions[kMaxPages - 1];
                    }
                }
            }
        }
예제 #3
0
 void Start ()
 {
     m_pages[0].onPageBecomeActive();
     m_currentlyActivePage = m_pages[0];
 }