public void Switch() { Touch3 tmp = LastTouch; LastTouch = ThisTouch; ThisTouch = tmp; }
public bool Update() { switch (ThisTouch.phase) { case TouchPhase.Began: BeginTouch = ThisTouch; HasMoved = false; break; case TouchPhase.Moved: if (!HasMoved && !IsInScope(BeginTouch.position, ThisTouch.position)) HasMoved = true; break; case TouchPhase.Ended: EndTouch = ThisTouch; break; } // 如果发现当前的touch不是一个began,但是上一次的touch是一个end,表明是一个非began开始的touch(例如之前点在界面上,手指没有移动,但是界面消失了) if (ThisTouch.phase != TouchPhase.Began && LastTouch.phase == TouchPhase.Ended) { BeginTouch = ThisTouch; HasMoved = false; } return true; }
bool TickTouchStates(float fDeltaTime) { TouchCount = 0; int iTouchCount = Input2.touchCount; if (EntryPoint.Instance.DebugFlag) { EntryPoint.Instance.OnDebugTouch(); } for (int i = 0; i < iTouchCount; ++i) { if (TouchCount >= MaxTouchCount) break; Touch2 touch2 = Input2.GetTouch(i); //Debug.Log("touch2 phase = " + touch2.phase); if (0 == i && touch2.phase == TouchPhase.Began) { Vector2 pos = touch2.position; LuaDLL.lua_getglobal(wLua.L.L, "OnClickScreen"); LuaStatic.WriteVector2ToLua(wLua.L.L, pos); wLua.L.Call(1); } if (UICamera.isTouchHitUI(touch2.fingerId)) { continue; } Touch3 touch3 = new Touch3(); touch3.touch2 = touch2; TouchStates[TouchCount].Switch(); TouchStates[TouchCount].ThisTouch = touch3; TouchStates[TouchCount].Update(); ++TouchCount; } #if UNITY_IPHONE || UNITY_ANDROID //Skip Mouse Touch #else UpdateMouseTouch(); if (m_bHasMouseTouch && TouchCount < MaxTouchCount) { TouchStates[TouchCount].Switch(); TouchStates[TouchCount].ThisTouch = m_mouseTouch3; TouchStates[TouchCount].Update(); if (TouchStates[TouchCount].ThisTouch.phase == TouchPhase.Began) { Vector2 pos = m_mouseTouch3.position; LuaDLL.lua_getglobal(wLua.L.L, "OnClickScreen"); LuaStatic.WriteVector2ToLua(wLua.L.L, pos); wLua.L.Call(1); } ++TouchCount; } #endif IdleTime = (iTouchCount > 0 || m_bHasMouseTouch) ? 0 : IdleTime + fDeltaTime; /* if (TouchCount > 0) { string strLog = string.Format("Touch {0}", TouchCount); Debug.Log(strLog); } */ return true; }