public IEnumerator Routine(TapDetector tapD) { tapDetector = tapD; triggerTime = Time.realtimeSinceStartup; startTimeCharge = Time.realtimeSinceStartup; yield return(new WaitForSeconds(0.075f)); if (indexes.Count < 2) { routineEnded = true; yield break; } else { count = indexes.Count; posAvg = Vector2.zero; //foreach(Vector2 p in positions) posAvg+=p; for (int i = 0; i < positions.Count; i++) { posAvg += positions[i]; } posAvg /= positions.Count; posList = new Vector2[positions.Count]; positions.CopyTo(posList); indexList = new int[indexes.Count]; indexes.CopyTo(indexList); } bool isOn = true; float liftTime = -1; int rand = Random.Range(0, 99999); while (isOn) { for (int i = 0; i < indexes.Count; i++) { Touch touch = IT_Gesture.GetTouch(indexes[i]); if (touch.phase == TouchPhase.Moved) { isOn = false; } if (touch.position == Vector2.zero) { if (indexes.Count == count) { liftTime = Time.realtimeSinceStartup; } indexes.RemoveAt(i); i--; } } if (Time.realtimeSinceStartup - startTimeCharge > tapDetector.minChargeTime && chargeState == _ChargeState.Clear) { chargeState = _ChargeState.Charging; float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / tapDetector.maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(posAvg, posList, chargedValue, indexList); IT_Gesture.ChargeStart(cInfo); } else if (chargeState == _ChargeState.Charging) { float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / tapDetector.maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(posAvg, posList, chargedValue, indexList); if (tapDetector.chargeMode == _ChargeMode.PingPong) { if (chargedValue == 1 || chargedValue == 0) { chargeDir *= -1; if (chargeDir == 1) { chargeConst = 0; } else if (chargeDir == -1) { chargeConst = 1; } startTimeCharge = Time.realtimeSinceStartup; } IT_Gesture.Charging(cInfo); } else { if (chargedValue < 1.0f) { IT_Gesture.Charging(cInfo); } else { cInfo.percent = 1.0f; if (tapDetector.chargeMode == _ChargeMode.Once) { chargeState = _ChargeState.Charged; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = Mathf.Infinity; chargedValue = 0; } else if (tapDetector.chargeMode == _ChargeMode.Clamp) { chargeState = _ChargeState.Charged; IT_Gesture.Charging(cInfo); } else if (tapDetector.chargeMode == _ChargeMode.Loop) { chargeState = _ChargeState.Clear; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = Time.realtimeSinceStartup; } } } } if (!longTap && Time.realtimeSinceStartup - triggerTime > tapDetector.longTapTime) { if (indexes.Count == count) { Vector2[] posList = new Vector2[positions.Count]; positions.CopyTo(posList); Tap tap = new Tap(1, count, posList, indexList); IT_Gesture.LongTap(tap); longTap = true; } } if (indexes.Count < count) { if (Time.realtimeSinceStartup - liftTime > 0.075f || indexes.Count == 0) { if (indexes.Count == 0) { if (liftTime - triggerTime < tapDetector.shortTapTime + 0.1f) { Vector2[] posList = new Vector2[positions.Count]; positions.CopyTo(posList); //Tap tap=new Tap(1, count, posList); //IT_Gesture.MFShortTap(tap); tapDetector.CheckMultiTapMFTouch(count, posList, indexList); } } isOn = false; break; } } yield return(null); } if (chargeState == _ChargeState.Charging || (chargeState == _ChargeState.Charged && tapDetector.chargeMode != _ChargeMode.Once)) { float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / tapDetector.maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(posAvg, posList, chargedValue, indexList); IT_Gesture.ChargeEnd(cInfo); } routineEnded = true; }
IEnumerator MouseRoutine(int index) { mouseIndex.Add(index); //init tap variables float startTime = Time.realtimeSinceStartup; Vector2 startPos = Input.mousePosition; Vector2 lastPos = startPos; bool longTap = false; //init charge variables _ChargeState chargeState = _ChargeState.Clear; int chargeDir = 1; float chargeConst = 0; float startTimeCharge = Time.realtimeSinceStartup; Vector2 startPosCharge = Input.mousePosition; yield return(null); while (mouseIndex.Contains(index)) { Vector2 curPos = Input.mousePosition; if (Time.realtimeSinceStartup - startTimeCharge > minChargeTime && chargeState == _ChargeState.Clear) { chargeState = _ChargeState.Charging; float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(curPos, chargedValue, index, true); IT_Gesture.ChargeStart(cInfo); startPosCharge = curPos; } else if (chargeState == _ChargeState.Charging) { if (Vector3.Distance(curPos, startPosCharge) > tapPosDeviation) { chargeState = _ChargeState.Clear; float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(lastPos, chargedValue, index, true); IT_Gesture.ChargeEnd(cInfo); } else { float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(curPos, chargedValue, index, true); if (chargeMode == _ChargeMode.PingPong) { if (chargedValue == 1 || chargedValue == 0) { chargeDir *= -1; if (chargeDir == 1) { chargeConst = 0; } else if (chargeDir == -1) { chargeConst = 1; } startTimeCharge = Time.realtimeSinceStartup; } IT_Gesture.Charging(cInfo); } else { if (chargedValue < 1.0f) { IT_Gesture.Charging(cInfo); } else { cInfo.percent = 1.0f; if (chargeMode == _ChargeMode.Once) { chargeState = _ChargeState.Charged; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = Mathf.Infinity; chargedValue = 0; } else if (chargeMode == _ChargeMode.Clamp) { chargeState = _ChargeState.Charged; IT_Gesture.Charging(cInfo); } else if (chargeMode == _ChargeMode.Loop) { chargeState = _ChargeState.Clear; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = Time.realtimeSinceStartup; } } } } } if (!longTap && Time.realtimeSinceStartup - startTime > longTapTime && Vector2.Distance(lastPos, startPos) < maxTapDisplacementAllowance * IT_Gesture.GetDPIFactor()) { IT_Gesture.LongTap(new Tap(curPos, 1, index, true)); longTap = true; } lastPos = curPos; yield return(null); } //check for shortTap if (Time.realtimeSinceStartup - startTime <= shortTapTime && Vector2.Distance(lastPos, startPos) < maxTapDisplacementAllowance * IT_Gesture.GetDPIFactor()) { //IT_Gesture.ShortTap(startPos); CheckMultiTapMouse(index, startPos, lastPos); } //check for charge if (chargeState == _ChargeState.Charging || (chargeState == _ChargeState.Charged && chargeMode != _ChargeMode.Once)) { float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(lastPos, chargedValue, index, true); IT_Gesture.ChargeEnd(cInfo); } }
IEnumerator FingerRoutine(int index) { fingerIndex.Add(index); //init tap variables Touch touch = IT_Gesture.GetTouch(index); float startTime = Time.realtimeSinceStartup; Vector2 startPos = touch.position; Vector2 lastPos = startPos; bool longTap = false; //init charge variables _ChargeState chargeState = _ChargeState.Clear; int chargeDir = 1; int chargeConst = 0; float startTimeCharge = Time.realtimeSinceStartup; Vector2 startPosCharge = touch.position; //yield return null; bool inGroup = false; while (true) { touch = IT_Gesture.GetTouch(index); if (touch.position == Vector2.zero) { break; } Vector2 curPos = touch.position; if (Time.realtimeSinceStartup - startTimeCharge > minChargeTime && chargeState == _ChargeState.Clear) { chargeState = _ChargeState.Charging; float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(curPos, chargedValue, index, false); IT_Gesture.ChargeStart(cInfo); startPosCharge = curPos; } else if (chargeState == _ChargeState.Charging) { if (Vector3.Distance(curPos, startPosCharge) > tapPosDeviation) { chargeState = _ChargeState.Clear; float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(lastPos, chargedValue, index, false); IT_Gesture.ChargeEnd(cInfo); } else { float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(curPos, chargedValue, index, false); if (chargeMode == _ChargeMode.PingPong) { if (chargedValue == 1 || chargedValue == 0) { chargeDir *= -1; if (chargeDir == 1) { chargeConst = 0; } else if (chargeDir == -1) { chargeConst = 1; } startTimeCharge = Time.realtimeSinceStartup; } IT_Gesture.Charging(cInfo); } else { if (chargedValue < 1.0f) { IT_Gesture.Charging(cInfo); } else { cInfo.percent = 1.0f; if (chargeMode == _ChargeMode.Once) { chargeState = _ChargeState.Charged; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = Mathf.Infinity; chargedValue = 0; } else if (chargeMode == _ChargeMode.Clamp) { chargeState = _ChargeState.Charged; IT_Gesture.Charging(cInfo); } else if (chargeMode == _ChargeMode.Loop) { chargeState = _ChargeState.Clear; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = Time.realtimeSinceStartup; } } } } } if (!longTap && Time.realtimeSinceStartup - startTime > longTapTime && Vector2.Distance(lastPos, startPos) < maxTapDisplacementAllowance * IT_Gesture.GetDPIFactor()) { //new Tap(multiTapMFTouch[index].count, fCount, posL) //IT_Gesture.LongTap(new Tap(multiTapMFTouch[index].count, fCount, posL)); IT_Gesture.LongTap(new Tap(curPos, 1, index, false)); //IT_Gesture.LongTap(startPos); longTap = true; } lastPos = curPos; if (!inGroup) { inGroup = IndexInFingerGroup(index); } yield return(null); } //check for shortTap if (!inGroup) { if (Time.realtimeSinceStartup - startTime <= shortTapTime && Vector2.Distance(lastPos, startPos) < maxTapDisplacementAllowance * IT_Gesture.GetDPIFactor()) { CheckMultiTapTouch(index, startPos, lastPos); } } //check for charge if (chargeState == _ChargeState.Charging || (chargeState == _ChargeState.Charged && chargeMode != _ChargeMode.Once)) { float chargedValue = Mathf.Clamp(chargeConst + chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0, 1); ChargedInfo cInfo = new ChargedInfo(lastPos, chargedValue, index, false); IT_Gesture.ChargeEnd(cInfo); } fingerIndex.Remove(index); }
private IEnumerator MouseRoutine(int index) { mouseIndex.Add(index); float startTime = Time.realtimeSinceStartup; Vector2 startPos = Input.mousePosition; Vector2 lastPos = startPos; bool longTap = false; _ChargeState chargeState = _ChargeState.Clear; int chargeDir = 1; float chargeConst = 0f; float startTimeCharge = Time.realtimeSinceStartup; Vector2 startPosCharge = Input.mousePosition; yield return(null); while (mouseIndex.Contains(index)) { Vector2 curPos = Input.mousePosition; if (Time.realtimeSinceStartup - startTimeCharge > minChargeTime && chargeState == _ChargeState.Clear) { chargeState = _ChargeState.Charging; float chargedValue3 = Mathf.Clamp(chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0f, 1f); ChargedInfo cInfo3 = new ChargedInfo(curPos, chargedValue3, index, im: true); IT_Gesture.ChargeStart(cInfo3); startPosCharge = curPos; } else if (chargeState == _ChargeState.Charging) { if (Vector3.Distance(curPos, startPosCharge) > tapPosDeviation) { chargeState = _ChargeState.Clear; float chargedValue2 = Mathf.Clamp(chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0f, 1f); ChargedInfo cInfo2 = new ChargedInfo(lastPos, chargedValue2, index, im: true); IT_Gesture.ChargeEnd(cInfo2); } else { float chargedValue = Mathf.Clamp(chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0f, 1f); ChargedInfo cInfo = new ChargedInfo(curPos, chargedValue, index, im: true); if (chargeMode == _ChargeMode.PingPong) { if (chargedValue == 1f || chargedValue == 0f) { chargeDir *= -1; switch (chargeDir) { case 1: chargeConst = 0f; break; case -1: chargeConst = 1f; break; } startTimeCharge = Time.realtimeSinceStartup; } IT_Gesture.Charging(cInfo); } else if (chargedValue < 1f) { IT_Gesture.Charging(cInfo); } else { cInfo.percent = 1f; if (chargeMode == _ChargeMode.Once) { chargeState = _ChargeState.Charged; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = float.PositiveInfinity; } else if (chargeMode == _ChargeMode.Clamp) { chargeState = _ChargeState.Charged; IT_Gesture.Charging(cInfo); } else if (chargeMode == _ChargeMode.Loop) { chargeState = _ChargeState.Clear; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = Time.realtimeSinceStartup; } } } } if (!longTap && Time.realtimeSinceStartup - startTime > longTapTime && Vector2.Distance(lastPos, startPos) < (float)maxTapDisplacementAllowance * IT_Gesture.GetDPIFactor()) { IT_Gesture.LongTap(new Tap(curPos, 1, index, im: true)); longTap = true; } lastPos = curPos; yield return(null); } if (Time.realtimeSinceStartup - startTime <= shortTapTime && Vector2.Distance(lastPos, startPos) < (float)maxTapDisplacementAllowance * IT_Gesture.GetDPIFactor()) { CheckMultiTapMouse(index, startPos, lastPos); } switch (chargeState) { default: yield break; case _ChargeState.Charged: if (chargeMode == _ChargeMode.Once) { yield break; } break; case _ChargeState.Charging: break; } float chargedValue4 = Mathf.Clamp(chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0f, 1f); ChargedInfo cInfo4 = new ChargedInfo(lastPos, chargedValue4, index, im: true); IT_Gesture.ChargeEnd(cInfo4); }
private IEnumerator FingerRoutine(int index) { fingerIndex.Add(index); Touch touch2 = IT_Gesture.GetTouch(index); float startTime = Time.realtimeSinceStartup; Vector2 startPos = touch2.position; Vector2 lastPos = startPos; bool longTap = false; _ChargeState chargeState = _ChargeState.Clear; int chargeDir = 1; int chargeConst = 0; float startTimeCharge = Time.realtimeSinceStartup; Vector2 startPosCharge = touch2.position; while (true) { touch2 = IT_Gesture.GetTouch(index); if (touch2.position == Vector2.zero) { break; } Vector2 curPos = touch2.position; if (Time.realtimeSinceStartup - startTimeCharge > minChargeTime && chargeState == _ChargeState.Clear) { chargeState = _ChargeState.Charging; float chargedValue3 = Mathf.Clamp((float)chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0f, 1f); ChargedInfo cInfo3 = new ChargedInfo(curPos, chargedValue3, index, im: false); IT_Gesture.ChargeStart(cInfo3); startPosCharge = curPos; } else if (chargeState == _ChargeState.Charging) { if (Vector3.Distance(curPos, startPosCharge) > tapPosDeviation) { chargeState = _ChargeState.Clear; float chargedValue2 = Mathf.Clamp((float)chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0f, 1f); ChargedInfo cInfo2 = new ChargedInfo(lastPos, chargedValue2, index, im: false); IT_Gesture.ChargeEnd(cInfo2); } else { float chargedValue = Mathf.Clamp((float)chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0f, 1f); ChargedInfo cInfo = new ChargedInfo(curPos, chargedValue, index, im: false); if (chargeMode == _ChargeMode.PingPong) { if (chargedValue == 1f || chargedValue == 0f) { chargeDir *= -1; switch (chargeDir) { case 1: chargeConst = 0; break; case -1: chargeConst = 1; break; } startTimeCharge = Time.realtimeSinceStartup; } IT_Gesture.Charging(cInfo); } else if (chargedValue < 1f) { IT_Gesture.Charging(cInfo); } else { cInfo.percent = 1f; if (chargeMode == _ChargeMode.Once) { chargeState = _ChargeState.Charged; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = float.PositiveInfinity; } else if (chargeMode == _ChargeMode.Clamp) { chargeState = _ChargeState.Charged; IT_Gesture.Charging(cInfo); } else if (chargeMode == _ChargeMode.Loop) { chargeState = _ChargeState.Clear; IT_Gesture.ChargeEnd(cInfo); startTimeCharge = Time.realtimeSinceStartup; } } } } if (!longTap && Time.realtimeSinceStartup - startTime > longTapTime && Vector2.Distance(lastPos, startPos) < (float)maxTapDisplacementAllowance * IT_Gesture.GetDPIFactor()) { IT_Gesture.LongTap(new Tap(curPos, 1, index, im: false)); longTap = true; } lastPos = curPos; yield return(null); } if (Time.realtimeSinceStartup - startTime <= shortTapTime && Vector2.Distance(lastPos, startPos) < (float)maxTapDisplacementAllowance * IT_Gesture.GetDPIFactor()) { CheckMultiTapTouch(index, startPos, lastPos); } if (chargeState == _ChargeState.Charging || (chargeState == _ChargeState.Charged && chargeMode != 0)) { float chargedValue4 = Mathf.Clamp((float)chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / maxChargeTime), 0f, 1f); ChargedInfo cInfo4 = new ChargedInfo(lastPos, chargedValue4, index, im: false); IT_Gesture.ChargeEnd(cInfo4); } fingerIndex.Remove(index); }
public IEnumerator Routine(TapDetector tapD) { tapDetector = tapD; triggerTime = Time.realtimeSinceStartup; startTimeCharge = Time.realtimeSinceStartup; yield return(new WaitForSeconds(0.075f)); if (indexes.Count < 2) { routineEnded = true; yield break; } count = indexes.Count; posAvg = Vector2.zero; for (int i = 0; i < positions.Count; i++) { posAvg += positions[i]; } posAvg /= (float)positions.Count; this.posList = new Vector2[positions.Count]; positions.CopyTo(this.posList); indexList = new int[indexes.Count]; indexes.CopyTo(indexList); bool isOn = true; float liftTime = -1f; while (isOn) { for (int j = 0; j < indexes.Count; j++) { Touch touch = IT_Gesture.GetTouch(indexes[j]); if (touch.phase == TouchPhase.Moved) { isOn = false; } if (touch.position == Vector2.zero) { if (indexes.Count == count) { liftTime = Time.realtimeSinceStartup; } indexes.RemoveAt(j); j--; } } if (Time.realtimeSinceStartup - startTimeCharge > tapDetector.minChargeTime && chargeState == _ChargeState.Clear) { chargeState = _ChargeState.Charging; ChargedInfo cInfo3 = new ChargedInfo(val: Mathf.Clamp((float)chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / tapDetector.maxChargeTime), 0f, 1f), p: posAvg, posL: this.posList, inds: indexList); IT_Gesture.ChargeStart(cInfo3); } else if (chargeState == _ChargeState.Charging) { float chargedValue = Mathf.Clamp((float)chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / tapDetector.maxChargeTime), 0f, 1f); ChargedInfo cInfo2 = new ChargedInfo(posAvg, this.posList, chargedValue, indexList); if (tapDetector.chargeMode == _ChargeMode.PingPong) { if (chargedValue == 1f || chargedValue == 0f) { chargeDir *= -1; if (chargeDir == 1) { chargeConst = 0; } else if (chargeDir == -1) { chargeConst = 1; } startTimeCharge = Time.realtimeSinceStartup; } IT_Gesture.Charging(cInfo2); } else if (chargedValue < 1f) { IT_Gesture.Charging(cInfo2); } else { cInfo2.percent = 1f; if (tapDetector.chargeMode == _ChargeMode.Once) { chargeState = _ChargeState.Charged; IT_Gesture.ChargeEnd(cInfo2); startTimeCharge = float.PositiveInfinity; } else if (tapDetector.chargeMode == _ChargeMode.Clamp) { chargeState = _ChargeState.Charged; IT_Gesture.Charging(cInfo2); } else if (tapDetector.chargeMode == _ChargeMode.Loop) { chargeState = _ChargeState.Clear; IT_Gesture.ChargeEnd(cInfo2); startTimeCharge = Time.realtimeSinceStartup; } } } if (!longTap && Time.realtimeSinceStartup - triggerTime > tapDetector.longTapTime && indexes.Count == count) { Vector2[] posList2 = new Vector2[positions.Count]; positions.CopyTo(posList2); Tap tap = new Tap(1, count, posList2, indexList); IT_Gesture.LongTap(tap); longTap = true; } if (indexes.Count < count && (Time.realtimeSinceStartup - liftTime > 0.075f || indexes.Count == 0)) { if (indexes.Count == 0 && liftTime - triggerTime < tapDetector.shortTapTime + 0.1f) { Vector2[] posList = new Vector2[positions.Count]; positions.CopyTo(posList); tapDetector.CheckMultiTapMFTouch(count, posList, indexList); } break; } yield return(null); } if (chargeState == _ChargeState.Charging || (chargeState == _ChargeState.Charged && tapDetector.chargeMode != 0)) { ChargedInfo cInfo = new ChargedInfo(val: Mathf.Clamp((float)chargeConst + (float)chargeDir * ((Time.realtimeSinceStartup - startTimeCharge) / tapDetector.maxChargeTime), 0f, 1f), p: posAvg, posL: this.posList, inds: indexList); IT_Gesture.ChargeEnd(cInfo); } routineEnded = true; }