private void Update() { // if there are no touch to be processed, just ignore the following instructions if (Input.touchCount <= 0) { return; } // loop through each touch and process it according to its phase foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { // If this touch is on UI elements or PhysicsRaycaster targets, mark as invalid if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { SetTouchState(touch.fingerId, TouchState.Invalid); } else // if not, we can mark it as a valid touch { SetTouchState(touch.fingerId, TouchState.Valid); } } else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { if (IsTouchInDictionaryInvalid(touch.fingerId)) { continue; } bool isTouchMoved = (touchStateDictionary[touch.fingerId] == TouchState.Moved); // this touch leaves screen, so set it to invalid // need to do this after assigning isTouchMoved, otherwise it'll be corrupted touchStateDictionary[touch.fingerId] = TouchState.Invalid; if (OnTouchEnded != null) { EndedTouchEventArgs eventArgs = new EndedTouchEventArgs(isTouchMoved, touch.position); OnTouchEnded.Invoke(this, eventArgs); } } else if (touch.phase == TouchPhase.Moved) { // if this touch is invalid, don't reset it to moved if (IsTouchInDictionaryInvalid(touch.fingerId)) { continue; } touchStateDictionary[touch.fingerId] = TouchState.Moved; if (OnTouchMoving != null) { MotionEventArgs eventArgs = new MotionEventArgs(touch.deltaPosition); OnTouchMoving.Invoke(this, eventArgs); } } } }
public void TouchEnded(int fingerId) { if (touchInfo.ContainsKey(fingerId)) { OnTouchEnded?.Invoke(fingerId, touchInfo[fingerId]); touchInfo.Remove(fingerId); } }
private void Mobile_Update() { PrevTouchCount = Input.touchCount; MainInputPresent = PrevTouchCount > 0; for (int _touchIndex = 0; _touchIndex < PrevTouchCount; _touchIndex++) { Touch _touch = Input.touches[_touchIndex]; if (_touch.phase == TouchPhase.Began) { OnTouchBegan?.Invoke(_touch); } if (_touch.phase == TouchPhase.Ended) { OnTouchEnded?.Invoke(_touch); } } }
// Update is called once per frame void Update() { if (Input.touchCount == 1 && !DragCameraZoom.b_IsTouch2) { touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { OnTouchBegan?.Invoke(); } if (touch.phase == TouchPhase.Moved) { OnTouchMoved?.Invoke(); } else if (touch.phase == TouchPhase.Ended) { OnTouchEnded?.Invoke(); } } }
public GestureListener() { _tmrCallEnded = new Timer(1000) { AutoReset = false }; _tmrCallEnded.Elapsed += (s, e) => Device.BeginInvokeOnMainThread(() => OnTouchEnded?.Invoke(-1, -1)); }
/// <summary> /// 更新中の場合 /// </summary> private void Update() { // UIを選択した場合ここで処理終了 if (IsSelectedUI()) { return; } #if UNITY_EDITOR // UNITYエディタの場合 if (Input.GetMouseButtonDown(0)) { OnTouchBegan?.Invoke(); } else if (Input.GetMouseButton(0)) { OnTouchMoved?.Invoke(); } else if (Input.GetMouseButtonUp(0)) { OnTouchEnded?.Invoke(); } #else // 実機の場合 if (Input.touchCount > 0) { // 0番目のタッチ取得 var touch = Input.GetTouch(0); switch (touch.phase) { case TouchPhase.Began: { OnTouchBegan?.Invoke(); } break; case TouchPhase.Moved: { OnTouchMoved?.Invoke(); } break; case TouchPhase.Ended: { OnTouchEnded?.Invoke(); } break; case TouchPhase.Stationary: { OnTouchStationary?.Invoke(); } break; case TouchPhase.Canceled: { OnTouchCanceled?.Invoke(); } break; } } #endif }