void Update() { // Track user input if GestureRecognition is enabled. if (isEnabled) { // If it is a touch device, get the touch position // if it is not, get the mouse position if (Utility.IsTouchDevice()) { if (Input.touchCount > 0) { virtualKeyPosition = new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y); } } else { if (Input.GetMouseButton(0)) { virtualKeyPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y); } } if (RectTransformUtility.RectangleContainsScreenPoint(drawArea, virtualKeyPosition, Camera.main)) { if (Input.GetMouseButtonDown(0)) { ClearGesture(); } // It is not necessary to track the touch from this point on, // because it is already registered, and GetMouseButton event // also fires on touch devices if (Input.GetMouseButton(0)) { point = new Vector2(virtualKeyPosition.x, -virtualKeyPosition.y); // Register this point only if the point list is empty or current point // is far enough than the last point. This ensures that the gesture looks // good on the screen. Moreover, it is good to not overpopulate the screen // with so much points. if (points.Count == 0 || (points.Count > 0 && Vector2.Distance(point, points[points.Count - 1]) > distanceBetweenPoints)) { points.Add(point); gestureRenderer.SetVertexCount(++vertexCount); gestureRenderer.SetPosition(vertexCount - 1, Utility.WorldCoordinateForGesturePoint(virtualKeyPosition)); } } // Capture the gesture, recognize it, fire the recognition event, // and clear the gesture from the screen. if (Input.GetMouseButtonUp(0)) { if (points.Count > minimumPointsToRecognize) { gesture = new Gesture(points); result = gesture.Recognize(gl, UseProtractor); SetMessage("Gesture is recognized as <color=#ff0000>'" + result.Name + "'</color> with a score of " + result.Score); } } } } }
void Update() { if (inInShowingState == true) { StartCoroutine(ShowFigureFromLibrary()); inAttemptState = false; } else { if (currentTime <= 0f && inAttemptState == true) { isEnabled = false; inInShowingState = false; isInGame = false; startOverButton.SetActive(true); //gestureRenderer.enabled = false; messageArea.text = ""; //Debug.Log("Ой а вот таймер"); } // Track user input if GestureRecognition is enabled. else { if ((isEnabled && inAttemptState) || isInAddition) { if (isEnabled && inAttemptState) { currentTime -= Time.deltaTime; forTimer.text = currentTime.ToString(); } // If it is a touch device, get the touch position // if it is not, get the mouse position if (Utility.IsTouchDevice()) { if (Input.touchCount > 0) { virtualKeyPosition = new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y); } } else { if (Input.GetMouseButton(0)) { virtualKeyPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y); } } if (RectTransformUtility.RectangleContainsScreenPoint(drawArea, virtualKeyPosition, Camera.main)) { if (Input.GetMouseButtonDown(0)) { ClearGesture(); } // It is not necessary to track the touch from this point on, // because it is already registered, and GetMouseButton event // also fires on touch devices if (Input.GetMouseButton(0)) { point = new Vector2(virtualKeyPosition.x, -virtualKeyPosition.y); // Register this point only if the point list is empty or current point // is far enough than the last point. This ensures that the gesture looks // good on the screen. Moreover, it is good to not overpopulate the screen // with so much points. if (points.Count == 0 || (points.Count > 0 && Vector2.Distance(point, points[points.Count - 1]) > distanceBetweenPoints)) { points.Add(point); if (isInAddition == true) { gestureRenderer.SetVertexCount(++vertexCount); gestureRenderer.SetPosition(vertexCount - 1, Utility.WorldCoordinateForGesturePoint(virtualKeyPosition)); } } } // Capture the gesture, recognize it, fire the recognition event, // and clear the gesture from the screen. if (Input.GetMouseButtonUp(0) && inAttemptState == true) { if (points.Count > minimumPointsToRecognize) { gesture = new Gesture(points); result = gesture.Recognize(gl, UseProtractor); //SetMessage("Gesture is recognized as <color=#ff0000>'" + result.Name + "'</color> with a score of " + result.Score); if (result.Name == rightAnswer && result.Score >= 0.8f) { messageArea.color = Color.green; messageArea.text = "Currect"; score++; textlScore.text = score.ToString(); StartCoroutine(ShowFigureFromLibrary()); } else { messageArea.color = Color.red; messageArea.text = "Wrong"; } } } //if (isInGame == true) //{ // messageArea.text = "Currect"; // Debug.Log("Я в игре"); //} } } } } }
// Track user input and fire OnRecognition event when necessary. void Update() { // Track user input if GestureRecognition is enabled. if (isEnabled) { // If it is a touch device, get the touch position // if it is not, get the mouse position if (Utility.IsTouchDevice()) { if (Input.touchCount > 0) { virtualKeyPosition = new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y); } } else { if (Input.GetMouseButton(0)) { virtualKeyPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y); } } // It is not necessary to track the touch from this point on, // because it is already registered, and GetMouseButton event // also fires on touch devices if (Input.GetMouseButton(0)) { switch (gestureLimitType) { case GestureLimitType.None: RegisterPoint(); break; case GestureLimitType.RectBoundsIgnore: if (RectTransformUtility.RectangleContainsScreenPoint(gestureLimitRectBounds, virtualKeyPosition, null)) { RegisterPoint(); } break; case GestureLimitType.RectBoundsClamp: virtualKeyPosition = Utility.ClampPointToRect(virtualKeyPosition, gestureLimitRect); RegisterPoint(); break; } } // Capture the gesture, recognize it, fire the recognition event, // and clear the gesture from the screen. if (Input.GetMouseButtonUp(0)) { if (points.Count > minimumPointsToRecognize) { gesture = new Gesture(points); result = gesture.Recognize(gl, useProtractor); if (OnRecognition != null) { OnRecognition(result); } } ClearGesture(); } } }
void Update() { if (_LevelController.gameState == GameState.Playing || _LevelController.gameState == GameState.LifeLost) { if (Utility.IsTouchDevice()) { if (Input.touchCount > 0) { virtualKeyPosition = new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y); } } else { if (Input.GetMouseButton(0)) { virtualKeyPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y); } } if (Input.GetMouseButton(0)) { point = new Vector2(virtualKeyPosition.x, -virtualKeyPosition.y); if (points.Count == 0 || (points.Count > 0 && Vector2.Distance(point, points[points.Count - 1]) > distanceBetweenPoints)) { points.Add(point); gestureLineRenderer.SetVertexCount(++vertexCount); gestureLineRenderer.SetPosition(vertexCount - 1, Utility.WorldCoordinateForGesturePoint(virtualKeyPosition)); } } if (Input.GetMouseButtonUp(0)) { if (points.Count > minimumPointsToRecognize) { gesture = new Gesture(points); result = gesture.Recognize(gl, false); levelController.Fire(result.Name); } ClearGesture(); } } }