void Update() { // check if ExpanDialSticks is connected if (connected && !unknownParticipant) { if (Input.GetKey("escape") || (gaugeState == GAUGE_TO_APPEAR && gaugeIndex >= gaugePositions.Length)) { Quit(); } if (Input.GetKeyDown(KeyCode.RightArrow)) { Vector2 gaugePosition = gaugePositions[gaugeIndex]; HandleRotationChanged(new object(), new ExpanDialStickEventArgs(DateTime.Now, (int)gaugePosition.x, (int)gaugePosition.y, 0, 1, 1)); //currentRotation += anglePerStep; } if (Input.GetKeyDown(KeyCode.LeftArrow)) { Vector2 gaugePosition = gaugePositions[gaugeIndex]; HandleRotationChanged(new object(), new ExpanDialStickEventArgs(DateTime.Now, (int)gaugePosition.x, (int)gaugePosition.y, 1, 0, -1)); //currentRotation -= anglePerStep; } if (gaugeState == GAUGE_TO_APPEAR && ++gaugeIndex < gaugePositions.Length) { //Debug.Log("TRIGGER StartCoroutine ShowGauge"); gaugeState = GAUGE_APPEARING; StartCoroutine(ShowGauge()); } if (gaugeState == GAUGE_STARTED || gaugeState == LANDSCAPE_IS_CHANGING) { if (gaugeState == GAUGE_STARTED && Time.time - startGameTime >= motionDuration) { //Debug.Log("TRIGGER StartCoroutine Earthquake"); gaugeState = LANDSCAPE_IS_CHANGING; if (training) { StartCoroutine(FakeEarthquake()); } else { StartCoroutine(Earthquake()); } motionDuration = Mathf.Infinity; } if (gaugeState == GAUGE_STARTED && Time.time - startGameTime >= gameDuration) { /*Debug.Log("TRIGGER StartCoroutine NextGauge"); * Debug.Log("Time.time:" + Time.time); * Debug.Log("startGameTime:" + startGameTime); * Debug.Log("gameDuration:" + gameDuration);*/ gaugeState = GAUGE_APPEARING; StartCoroutine(NextGauge()); gameDuration = Mathf.Infinity; } else { // Gauge Game float prevRotation = cadranRotation; switch (directionRotation) { case DirectionRotation.CW: cadranRotation += speedRotation * Time.deltaTime; break; case DirectionRotation.CCW: cadranRotation -= speedRotation * Time.deltaTime; break; default: break; } string msg = "SYSTEM_ROTATION " + prevRotation + " " + cadranRotation; if ((int)prevRotation != (int)cadranRotation) { //Debug.Log(msg); } expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(msg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); if (Time.time - directionTime >= directionDuration) { int nbDirections = Enum.GetNames(typeof(DirectionRotation)).Length - 1; // without IDDLE directionRotation = (DirectionRotation)UnityEngine.Random.Range(0, nbDirections); speedRotation = UnityEngine.Random.Range(5f, 15f); directionDuration = UnityEngine.Random.Range(3f, 9f); directionTime = Time.time; } MoveAiguilleCadran(); } } if (gaugeState == LANDSCAPE_IS_CHANGING) { if ((currTime += Time.deltaTime) - prevTime > LOG_INTERVAL) { LogAllSystemData(); prevTime = currTime; } } } }
void Update() { // check if ExpanDialSticks is connected if (connected) { if (Input.GetKey("escape") || (gaugeState == GAUGE_TO_APPEAR && gaugeIndex >= gaugePositions.Length)) { Quit(); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { Vector2 gaugePosition = gaugePositions[gaugeIndex]; triggerChangeXYAxis(0, -5); //currentRotation += anglePerStep; } if (Input.GetKeyDown(KeyCode.RightArrow)) { Vector2 gaugePosition = gaugePositions[gaugeIndex]; triggerChangeXYAxis(0, 5); //HandleXAxisChanged(new object(), new ExpanDialStickEventArgs(DateTime.Now, (int)gaugePosition.x, (int)gaugePosition.y, 1, 0, -1)); //currentRotation -= anglePerStep; } if (Input.GetKeyDown(KeyCode.UpArrow)) { Vector2 gaugePosition = gaugePositions[gaugeIndex]; triggerChangeXYAxis(5, 0); //currentRotation += anglePerStep; } if (Input.GetKeyDown(KeyCode.DownArrow)) { Vector2 gaugePosition = gaugePositions[gaugeIndex]; triggerChangeXYAxis(-5, 0); //HandleXAxisChanged(new object(), new ExpanDialStickEventArgs(DateTime.Now, (int)gaugePosition.x, (int)gaugePosition.y, 1, 0, -1)); //currentRotation -= anglePerStep; } if (gaugeState == GAUGE_TO_APPEAR && ++gaugeIndex < gaugePositions.Length) { gaugeState = GAUGE_APPEARING; StartCoroutine(ShowGauge()); } if (gaugeState == GAUGE_APPEARED || gaugeState == LANDSCAPE_IS_CHANGING) { if (gaugeState == GAUGE_APPEARED && Time.time - startGameTime >= motionDuration) { gaugeState = LANDSCAPE_IS_CHANGING; StartCoroutine(Earthquake()); motionDuration = Mathf.Infinity; } if (gaugeState == GAUGE_APPEARED && Time.time - startGameTime >= gameDuration) { StartCoroutine(NextGauge()); gaugeState = GAUGE_APPEARING; } else { // Gauge Game float prevRotation = currentRotation; switch (directionRotation) { case DirectionRotation.CW: currentRotation += speedRotation * Time.deltaTime; break; case DirectionRotation.CCW: currentRotation -= speedRotation * Time.deltaTime; break; default: break; } string msg = "SYSTEM_ROTATE_GAUGE " + prevRotation + " " + currentRotation; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(msg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, true); if (Time.time - directionTime >= directionDuration) { int nbDirections = Enum.GetNames(typeof(DirectionRotation)).Length - 1; // without IDDLE directionRotation = (DirectionRotation)UnityEngine.Random.Range(0, nbDirections); speedRotation = UnityEngine.Random.Range(5f, 15f); directionDuration = UnityEngine.Random.Range(3f, 9f); directionTime = Time.time; } MoveAiguille(); } } if (gaugeState == LANDSCAPE_IS_CHANGING) { if ((currTime += Time.deltaTime) - prevTime > LOG_INTERVAL) { LogAllSystemData(); prevTime = currTime; } } } }