Ejemplo n.º 1
0
        public static void ProcessTouchEvent(int id, int phase, int x, int y)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            // Check if we already have an event with that ID
            int foundIndex = -1;
            for (int i = 0; i < m_TouchCountForNextFrame; ++i)
            {
                if (m_TouchesForNextFrame[i].fingerId == id)
                {
                    foundIndex = i;
                    break;
                }
            }

            CoherentTouch newTouch = new CoherentTouch();
            newTouch.fingerId      = id;
            newTouch.phase         = (TouchPhase)phase;
            newTouch.position      = new Vector2(x, Screen.height - y);
            newTouch.deltaTime     = 0;
            newTouch.deltaPosition = new Vector2(0, 0);
            newTouch.tapCount      = 1;

            if (foundIndex >= 0)
            {
                // Update event
                newTouch.deltaPosition            = newTouch.position - m_TouchesForNextFrame[foundIndex].position;
                m_TouchesForNextFrame[foundIndex] = newTouch;
                m_LastChangedTime[foundIndex]     = Time.time;
            }
            else
            {
                // Create new event if the touch has just begun; otherwise ignore the event
                if (phase == (int)TouchPhase.Began)
                {
                    if (m_TouchCountForNextFrame < MAX_TOUCHES)
                    {
                        m_TouchesForNextFrame[m_TouchCountForNextFrame] = newTouch;
                        m_LastChangedTime[m_TouchCountForNextFrame]     = Time.time;
                        ++m_TouchCountForNextFrame;
                    }
                    else
                    {
                        Debug.LogWarning("Cannot process touch event since current touch count exceeds maximum allowed (" + MAX_TOUCHES + ")!");
                    }
                }
            }
#endif
        }
Ejemplo n.º 2
0
        public static CoherentTouch GetTouch(int index)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (index >= 0 && index < m_TouchCount)
            {
                return(m_Touches[index]);
            }

            throw new System.IndexOutOfRangeException("Indexing CoherentTouch array with invalid value!");
#else
            CoherentTouch coherentTouch = new CoherentTouch();
            Touch         unityTouch    = Input.GetTouch(index);

            coherentTouch.fingerId      = unityTouch.fingerId;
            coherentTouch.deltaPosition = unityTouch.deltaPosition;
            coherentTouch.deltaTime     = unityTouch.deltaTime;
            coherentTouch.phase         = unityTouch.phase;
            coherentTouch.position      = unityTouch.position;
            coherentTouch.tapCount      = unityTouch.tapCount;

            return(coherentTouch);
#endif
        }
Ejemplo n.º 3
0
		public static CoherentTouch GetTouch(int index)
		{
#if UNITY_ANDROID || COHERENT_SIMULATE_MOBILE_IN_EDITOR || COHERENT_SIMULATE_MOBILE_IN_PLAYER
			if (index >= 0 && index < m_TouchCount)
			{
				return m_Touches[index];
			}
			
			throw new System.IndexOutOfRangeException("Indexing CoherentTouch array with invalid value!");
#else
			CoherentTouch coherentTouch = new CoherentTouch();
			Touch unityTouch = Input.GetTouch(index);
			
			coherentTouch.fingerId = unityTouch.fingerId;
			coherentTouch.deltaPosition = unityTouch.deltaPosition;
			coherentTouch.deltaTime = unityTouch.deltaTime;
			coherentTouch.phase = unityTouch.phase;
			coherentTouch.position = unityTouch.position;
			coherentTouch.tapCount = unityTouch.tapCount;
			
			return coherentTouch;
#endif
		}
Ejemplo n.º 4
0
		public static void ProcessTouchEvent(int id, int phase, int x, int y)
		{
			#if UNITY_ANDROID || COHERENT_SIMULATE_MOBILE_IN_EDITOR || COHERENT_SIMULATE_MOBILE_IN_PLAYER
			// Check if we already have an event with that ID
			int foundIndex = -1;
			for (int i = 0; i < m_TouchCountForNextFrame; ++i)
			{
				if (m_TouchesForNextFrame[i].fingerId == id)
				{
					foundIndex = i;
					break;
				}
			}
			
			CoherentTouch newTouch = new CoherentTouch();
			newTouch.fingerId = id;
			newTouch.phase = (TouchPhase)phase;
			newTouch.position = new Vector2(x, Screen.height - y);
			newTouch.deltaTime = 0;
			newTouch.deltaPosition = new Vector2(0, 0);
			newTouch.tapCount = 1;
			
			if (foundIndex >= 0)
			{
				// Update event
				newTouch.deltaPosition = newTouch.position - m_TouchesForNextFrame[foundIndex].position;
				m_TouchesForNextFrame[foundIndex] = newTouch;
				m_LastChangedTime[foundIndex] = Time.time;
			}
			else
			{
				// Create new event if the touch has just begun; otherwise ignore the event
				if (phase == (int)TouchPhase.Began)
				{
					if (m_TouchCountForNextFrame < MAX_TOUCHES)
					{
						m_TouchesForNextFrame[m_TouchCountForNextFrame] = newTouch;
						m_LastChangedTime[m_TouchCountForNextFrame] = Time.time;
						++m_TouchCountForNextFrame;
					}
					else
					{
						Debug.LogWarning("Cannot process touch event since current touch count exceeds maximum allowed (" + MAX_TOUCHES + ")!");
					}
				}
			}
			#endif
		}