Esempio n. 1
0
    void Update()
    {
        m_CurrentTouchBeginObjList.Clear();
        m_CurrentTouchMoveObjList.Clear();
        m_CurrentTouchEndObjList.Clear();

#if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            ITouchableObject obj = GetTouchableObject(Input.mousePosition);
            if (obj != null)
            {
                m_CurrentTouchBeginObjList.Add(obj);
                obj.TouchBegin();
            }
        }
#else
        int touchCount = Input.touchCount;
        for (int i = 0; i < touchCount; i++)
        {
            Touch            touch = Input.GetTouch(i);
            ITouchableObject obj   = GetTouchableObject(touch.position);
            if (obj == null)
            {
                continue;
            }

            switch (touch.phase)
            {
            case TouchPhase.Began:
                m_CurrentTouchBeginObjList.Add(obj);
                obj.TouchBegin();
                break;

            case TouchPhase.Moved:
            case TouchPhase.Stationary:
                m_CurrentTouchMoveObjList.Add(obj);
                obj.TouchMove();
                break;

            case TouchPhase.Ended:
            case TouchPhase.Canceled:
                m_CurrentTouchEndObjList.Add(obj);
                obj.TouchEnd();
                break;
            }
        }
#endif

        m_LastTouchBeginObjList = m_CurrentTouchBeginObjList;
        m_LastTouchMoveObjList  = m_CurrentTouchMoveObjList;
        m_LastTouchEndObjList   = m_CurrentTouchEndObjList;
    }
        public static void CaptureTouch(int touchId, ITouchableObject touchable)
        {
            // First add the pair to the dictionary indexed by ID
            CapturedTouchesByTouch.Add(touchId, touchable);

            // Now add the pair to the dictionary indexed by touchable object.
            if (CapturedTouchesByTouchableObject.ContainsKey(touchable))
            {
                // If the touch already exists in the dictionary, add this touch to the object's list
                CapturedTouchesByTouchableObject[touchable].Add(touchId);
            }
            else
            {
                // If the touch is not in the dictionary yet, make a new entry and put the touch
                // in the object's list
                List<int> list = new List<int>();
                list.Add(touchId);
                CapturedTouchesByTouchableObject.Add(touchable, list);
            }
        }