/* global touch event (everybody get this event) */ private void eventOnTouch(InputTouchFinger finger) { if (!reactToTouch()) { return; } if (dontReactToCapturedFinger) { if (!finger.isCapturedBy(this) && finger.isCaptured()) { //Debug.Log(name + " can't react to finger " + finger.fingerId + " because is captured by someone else : " + finger.captured, gameObject); return; } } //Debug.Log(finger.fingerId + " on touch "+name); onTouch(finger); RaycastHit2D?hit = getLocalMatchingColliderWithFinger(finger); if (hit != null) { _touching = true; //Debug.Log("{InputObject} input touch over " + hit.Value.transform.name); eventTouchOver(finger, hit.Value); } }
//ON TOUCH DEVICES (MOBILE,TABLET) void update_touch() { touches = Input.touches; // stored for opti touchCount = Input.touchCount; // quantité de doigts a un instant T //first, check for new touch and assign touches to fingers for (int i = 0; i < touchCount; i++) { Touch touch = touches[i]; _finger = getFingerById(touches[i].fingerId); if (_finger == null) { _finger = getFirstAvailableFinger(); _finger.assign(touch.fingerId); } } //second, for each fingers apply state for (int i = 0; i < _fingers.Length; i++) { _finger = _fingers[i]; // never null Touch?touch = getSystemTouchById(_fingers[i].fingerId); if (touch != null) // active finger { _finger.update(touch.Value); } else if (_finger.isFingerNotCanceled()) { _finger.setEnded(); } } }
/* un doigt passe par là et y a que moi en dessous */ private void eventOnOverring(InputTouchFinger finger) { if (!reactToTouch()) { return; } if (!_overring) { return; } if (finger.isCaptured() && dontReactToCapturedFinger) { return; } RaycastHit2D?hit = getLocalMatchingColliderWithFinger(finger); if (hit != null) { //Debug.Log("overring "+finger.touchedObjects[0].collider.gameObject.name+" , count = "+finger.touchedObjects.Count); onOverring(finger); } }
virtual protected void onReleaseOver(InputTouchFinger finger, RaycastHit2D hit) { //Debug.Log(name + " release over"); if (cbReleaseOver != null) { cbReleaseOver(finger, hit); } }
virtual protected void onOverring(InputTouchFinger finger) { //Debug.Log(name + " overring"); if (cbStayOver != null) { cbStayOver(finger); } }
virtual protected void onTouchOver(InputTouchFinger finger, RaycastHit2D hit) { //Debug.Log(name + " touch over");Debug.Log(cbTouchOver); InputSelectionManager.manager.add(owner); if (cbTouchOver != null) { cbTouchOver(finger, hit); } }
static public Vector2 getDefaultFingerScreenPosition() { InputTouchFinger f = getDefaultFinger(); if (f != null) { return(f.screenPosition); } return(Vector2.zero); }
void cleanFingers() { if (_fingerA != null && _fingerA.fingerId < 0) { _fingerA = null; } if (_fingerB != null && _fingerB.fingerId < 0) { _fingerB = null; } }
virtual protected void onTouch(InputTouchFinger finger) { if (!reactToTouch()) { return; } this.finger = finger; if (cbTouch != null) { cbTouch(finger); } }
public InputTouchSwipe(InputTouchBridge itb) { iBridge = itb; iBridge.onTouch += delegate(InputTouchFinger finger) { _finger = finger; }; iBridge.onRelease += onRelease; limitLifeTime = iBridge.limitLifeTime; limitSwipeAmplitude = iBridge.limitSwipeAmplitude; }
protected RaycastHit2D?getLocalMatchingColliderWithFinger(InputTouchFinger finger) { List <RaycastHit2D> rCollisions = finger.touchedObjects; for (int i = 0; i < rCollisions.Count; i++) { //check si le collider trouvé par le doigt correspond a l'un des miens if (compareWithLocalCollider(rCollisions[i].collider)) { return(rCollisions[i]); } } return(null); }
private void eventTouchOver(InputTouchFinger finger, RaycastHit2D hit) { if (!reactToTouch()) { return; } if (!finger.isCaptured() && captureFingerOnTouch) { //Debug.Log(name + " <b>captured</b> finger " + finger.fingerId); finger.captured = this; } onTouchOver(finger, hit); }
/// <summary> /// this will trigger onRelease callback for that finger /// must be called once per end state /// </summary> /// <param name="finger"></param> void killFinger(InputTouchFinger finger) { //Debug.Log("killing " + finger.fingerId + " at phase " + finger.phase); //force a release if finger was used //active AND ended fingers ! if (!finger.isPhaseCanceled()) { if (onRelease != null) { onRelease(finger); // on finger killed } } finger.reset(); // set to canceled }
private void eventOnRelease(InputTouchFinger finger) { if (!reactToTouch()) { return; } //Debug.Log(name+" release finger "+finger.fingerId); if (finger.isCapturedBy(this)) { //Debug.Log(name + " <b>released</b> finger " + finger.fingerId); finger.captured = null; } if (!_interactive) { return; } if (finger.isCaptured() && dontReactToCapturedFinger) { return; } //on a besoin que touching soit MAJ avant d'apl ça pour le cas ou on desactive l'interactivité de l'extérieur bool wasTouching = _touching; _touching = false; onRelease(finger); if (wasTouching) { //chopper le hit correspondant a mes colliders RaycastHit2D?hit = getLocalMatchingColliderWithFinger(finger); if (hit != null) { //Debug.Log("{InputObject} input released over " + hit.Value.transform.name); onReleaseOver(finger, hit.Value); } } //if (cbRelease != null) cbRelease(finger); }
//ON PC void update_desktop() { bool mouseDown = Input.GetMouseButton(0); touchCount = mouseDown ? 1 : 0; //default finger _finger = _fingers[0]; if (mouseDown) { _finger.update(0, Input.mousePosition); } else if (_finger.isFingerNotCanceled()) { _finger.setEnded(); } }
/// <summary> /// return the name /// </summary> /// <returns></returns> public string getTouchedInteractorInfo() { string info = ""; InputTouchFinger fing = _fingers[0]; if (fing == null || fing.touchedObjects.Count == 0) { return("\n\nNo touch"); } Collider2D col = fing.touchedObjects[0].collider; info += "\n\nTouch info : "; info += "\n" + col.name; info += "\n"; return(info); }
public void onPress(InputTouchFinger finger) { if (_fingerA == null) { _fingerA = finger; return; } if (finger == _fingerA) { return; } if (_fingerB == null) { _fingerB = finger; } lastRawSpread = getDistanceBetweenFingers(); //current spread is neutral }
virtual protected void onRelease(InputTouchFinger finger) { if (!reactToTouch()) { return; } if (finger != this.finger) { return; } this.finger = null; InputSelectionManager.manager.remove(owner); if (cbRelease != null) { cbRelease(finger); } }
IEnumerator processSetup() { if (inputCamera == null) { while (inputCamera == null) { fetchCamera(); yield return(null); } Debug.Log(GetType() + " camera " + inputCamera.name + " is setup", inputCamera.gameObject); } int qtyFingers = 10; if (!isMobile()) { qtyFingers = 2; } //create all 11 touches _fingers = new InputTouchFinger[qtyFingers]; for (int i = 0; i < _fingers.Length; i++) { _fingers[i] = new InputTouchFinger(); } #if UNITY_EDITOR if (drawDebug) { Debug.LogWarning("debug drawing for " + GetType() + " is active"); } #endif //Debug.Log(GetType() + " setup is done, enabling update"); //EngineEventSystem.onPauseEvent += onSystemPause; //EngineEventSystem.onFocusEvent += onFocusPause; enabled = true; }
protected void onRelease(InputTouchFinger finger) { if (finger != _finger) { return; } Vector2 delta = _finger.getVectorFromStart(); if (_finger.lifeTime < limitLifeTime) { int horizontal = 0; if (Mathf.Abs(delta.x) > limitSwipeAmplitude) { horizontal = (int)Mathf.Sign(delta.x); } int vertical = 0; if (Mathf.Abs(delta.y) > limitSwipeAmplitude) { vertical = (int)Mathf.Sign(delta.y); } if (horizontal != 0 || vertical != 0) { //if(Mathf.Abs(delta.x) >= Mathf.Abs(delta.y)) if (onSwipe != null) onSwipe(horizontal, 0); //else if (Mathf.Abs(delta.x) < Mathf.Abs(delta.y)) if (onSwipe != null) onSwipe(0, vertical); if (onSwipe != null) { onSwipe(horizontal, vertical); } if (onSwipeDelta != null) { onSwipeDelta(delta); } } } }
protected void onBridgeInput(InputTouchFinger finger) { onInput(screenDimMode == ScreenDimensionMode.PROPORTIONNAL ? finger.screenProportional : (Vector2)finger.screenPosition); }
public void assignFinger(InputTouchFinger finger) { eventOnTouch(finger); }