public override void ProcessData(byte[] data) { _swipe = (ESwipeType)BitConverter.ToInt32(data, 0); if (OnValueChanged != null) { OnValueChanged(this); } }
public IEnumerator SwipeTimer() { float timer = 0; while (timer < 1f) { timer += Time.deltaTime; yield return(null); } currentSwipe = ESwipeType.Null; squareCount = 0; }
public override void Update() { if (!_enabled || _mngr.IsReceiver) { return; } _data.Clear(); ESwipeType s = DetectSwipe(); if (s == _swipe) { return; //no change } _swipe = s; _data.AddRange(BitConverter.GetBytes((int)_swipe)); //if (OnValueChanged != null) // OnValueChanged (this); }
private void Update() { //Handle gestures if (Input.touchCount > 0) { if (isSwiping == false) { isSwiping = true; RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); if (Physics.Raycast(ray, out hit)) { if (hit.collider != null) { _coll = hit.collider; } } } if (Input.GetTouch(0).deltaPosition.x > 0) { if (currentSwipe == ESwipeType.LeftSwipe || currentSwipe == ESwipeType.Null) { squareCount++; } else if (currentSwipe != ESwipeType.RightSwipe) { squareCount = 0; } currentSwipe = ESwipeType.RightSwipe; } else if (Input.GetTouch(0).deltaPosition.x < 0) { if (currentSwipe == ESwipeType.RightSwipe || currentSwipe == ESwipeType.Null) { squareCount++; } else if (currentSwipe != ESwipeType.LeftSwipe) { squareCount = 0; } currentSwipe = ESwipeType.LeftSwipe; } else if (Input.GetTouch(0).deltaPosition.y > 0) { if (currentSwipe != ESwipeType.DownSwipe || currentSwipe == ESwipeType.Null) { squareCount++; } else if (currentSwipe != ESwipeType.UpSwipe) { squareCount = 0; } currentSwipe = ESwipeType.UpSwipe; } else if (Input.GetTouch(0).deltaPosition.y < 0) { if (currentSwipe == ESwipeType.UpSwipe || currentSwipe == ESwipeType.Null) { squareCount++; } else if (currentSwipe != ESwipeType.DownSwipe) { squareCount = 0; } currentSwipe = ESwipeType.DownSwipe; } if (squareCount == 4) { squareCount = 0; // Events.Instance.Raise(new ONSQUAREEVENT() { }); // -> stack/4 } } else { isSwiping = false; StopCoroutine(SwipeTimer()); if (co != null) { co = null; } currentSwipe = ESwipeType.Null; stack = 0; } }
void Update() { #if UNITY_ANDROID || UNITY_IOS if (Input.touchCount > 0) { if (Input.GetTouch(0).deltaPosition.x > 0) { if (co == null && currentSwipe != ESwipeType.RightSwipe) { StartCoroutine(SwipeTimer()); } if (currentSwipe == ESwipeType.LeftSwipe || currentSwipe == ESwipeType.Null) { currentSwipe = ESwipeType.RightSwipe; Events.Instance.Raise(new OnSwipeEvent() { _collider = _coll, numberSwipe = ++stack, _swipeType = ESwipeType.RightSwipe }); } } if (Input.GetTouch(0).deltaPosition.x < 0) { if (co == null && currentSwipe != ESwipeType.LeftSwipe) { StartCoroutine(SwipeTimer()); } if (currentSwipe == ESwipeType.RightSwipe || currentSwipe == ESwipeType.Null) { currentSwipe = ESwipeType.LeftSwipe; Events.Instance.Raise(new OnSwipeEvent() { _collider = _coll, numberSwipe = ++stack, _swipeType = ESwipeType.LeftSwipe }); } } } else { isSwiping = false; StopCoroutine(SwipeTimer()); if (co != null) { co = null; } currentSwipe = ESwipeType.Null; stack = 0; } #else if (Input.GetMouseButton(0)) { if (firstPosition == Vector3.zero) { firstPosition = Input.mousePosition; } if (firstPosition != Vector3.zero && Input.mousePosition.x - firstPosition.x > _minDistance) { if (co == null && currentSwipe != ESwipeType.RightSwipe) { StartCoroutine(SwipeTimer()); } if (currentSwipe == ESwipeType.LeftSwipe || currentSwipe == ESwipeType.Null) { currentSwipe = ESwipeType.RightSwipe; Events.Instance.Raise(new OnSwipeEvent() { _collider = _coll, numberSwipe = ++stack, _swipeType = ESwipeType.RightSwipe }); } } if (firstPosition != Vector3.zero && firstPosition.x - Input.mousePosition.x > _minDistance) { if (co == null && currentSwipe != ESwipeType.LeftSwipe) { StartCoroutine(SwipeTimer()); } if (currentSwipe == ESwipeType.RightSwipe || currentSwipe == ESwipeType.Null) { currentSwipe = ESwipeType.LeftSwipe; Events.Instance.Raise(new OnSwipeEvent() { _collider = _coll, numberSwipe = ++stack, _swipeType = ESwipeType.LeftSwipe }); } } previousPosition = Input.mousePosition; } else { isSwiping = false; StopCoroutine(SwipeTimer()); if (co != null) { co = null; } currentSwipe = ESwipeType.Null; stack = 0; previousPosition = Vector3.zero; } #endif }
// Update is called once per frame void Update() { #if UNITY_ANDROID || UNITY_IOS if (Input.touchCount > 0) { if (isSwiping == false) { isSwiping = true; RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); if (Physics.Raycast(ray, out hit)) { if (hit.collider != null) { _coll = hit.collider; } } } if (Input.GetTouch(0).deltaPosition.y > 0) { if (co == null && currentSwipe != ESwipeType.UpSwipe) { StartCoroutine(SwipeTimer()); } if (currentSwipe == ESwipeType.DownSwipe || currentSwipe == ESwipeType.Null) { currentSwipe = ESwipeType.UpSwipe; Events.Instance.Raise(new OnSwipeEvent() { _collider = _coll, numberSwipe = ++stack, _swipeType = ESwipeType.UpSwipe }); } } if (Input.GetTouch(0).deltaPosition.y < 0) { if (co == null && currentSwipe != ESwipeType.DownSwipe) { StartCoroutine(SwipeTimer()); } if (currentSwipe == ESwipeType.UpSwipe || currentSwipe == ESwipeType.Null) { currentSwipe = ESwipeType.DownSwipe; Events.Instance.Raise(new OnSwipeEvent() { _collider = _coll, numberSwipe = ++stack, _swipeType = ESwipeType.DownSwipe }); } } } else { isSwiping = false; StopCoroutine(SwipeTimer()); if (co != null) { co = null; } currentSwipe = ESwipeType.Null; stack = 0; } #else if (Input.GetMouseButton(0)) { if (isSwiping == false) { isSwiping = true; RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider != null) { _coll = hit.collider; } } } if (firstPosition == Vector3.zero) { firstPosition = Input.mousePosition; } if (firstPosition != Vector3.zero && Input.mousePosition.y - firstPosition.y > _minDistance) { if (co == null && currentSwipe != ESwipeType.UpSwipe) { StartCoroutine(SwipeTimer()); } if (currentSwipe == ESwipeType.DownSwipe || currentSwipe == ESwipeType.Null) { firstPosition = Vector3.zero; currentSwipe = ESwipeType.UpSwipe; Events.Instance.Raise(new OnSwipeEvent() { _collider = _coll, numberSwipe = ++stack, _swipeType = ESwipeType.UpSwipe }); } } if (firstPosition != Vector3.zero && firstPosition.y - Input.mousePosition.y > _minDistance) { if (co == null && currentSwipe != ESwipeType.DownSwipe) { StartCoroutine(SwipeTimer()); } if (currentSwipe == ESwipeType.UpSwipe || currentSwipe == ESwipeType.Null) { firstPosition = Vector3.zero; currentSwipe = ESwipeType.DownSwipe; Events.Instance.Raise(new OnSwipeEvent() { _collider = _coll, numberSwipe = ++stack, _swipeType = ESwipeType.DownSwipe }); } } previousPosition = Input.mousePosition; } else { firstPosition = Vector3.zero; isSwiping = false; StopCoroutine(SwipeTimer()); if (co != null) { co = null; } currentSwipe = ESwipeType.Null; stack = 0; previousPosition = Vector3.zero; } #endif }