// Use this for initialization void Start() { gazePointData = GetComponent <GazePointDataComponent>(); OpenSerialPort(); InvokeRepeating("SendControlData", 0, SEND_FREQUENCY); Application.LoadLevel("drive"); UnityArduino.SendImmediate("1"); UnityArduino.SetStreamControlData(true); }
void Update() { bool hasGaze = _bgGazeAware.HasGaze && !activatedSwitchExists; //for now, just for debug if (Input.GetMouseButton(0)) { Vector2 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (_bgCollider2D.OverlapPoint(worldPos)) { hasGaze = true; } } //update gaze time if (hasGaze) { _bgTransform.Rotate(Vector3.forward); if (lastGazeTime == TIME_NOT_SET) { lastGazeTime = Time.time; } lastBreakTime = TIME_NOT_SET; } else if (lastGazeTime != TIME_NOT_SET) { if (Time.time - lastGazeTime >= ACTIVATE_THRESHOLD) { //since selection is already locked, only lack of valid gaze can deactivate if (!UnityArduino.validGaze) { if (lastBreakTime == TIME_NOT_SET) { lastBreakTime = Time.time; } else if (Time.time - lastBreakTime >= DEACTIVATE_THRESHOLD) { UnityArduino.SetControlData(UnityArduino.CONTROL_STOP); lastGazeTime = TIME_NOT_SET; } } else { lastBreakTime = TIME_NOT_SET; } } else { UnityArduino.SetControlData(UnityArduino.CONTROL_STOP); lastGazeTime = TIME_NOT_SET; } } bool prevActivated = activated; //respond to gaze time if (lastGazeTime == TIME_NOT_SET) { _bgSpriteRenderer.color = Color.red; activated = false; } else if (Time.time - lastGazeTime < ACTIVATE_THRESHOLD) { _bgSpriteRenderer.color = Color.yellow; activated = false; } else { _bgSpriteRenderer.color = Color.green; activated = true; } if (!prevActivated && activated) { activatedSwitchExists = true; } if (prevActivated && !activated) { activatedSwitchExists = false; } if (activated) { UnityArduino.SetControlData(controlData); } }
void Update() { bool hasGaze = _bgGazeAware.HasGaze; //for now, just for debug if (Input.GetMouseButton(0)) { Vector2 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (_bgCollider2D.OverlapPoint(worldPos)) { hasGaze = true; } } if (lastActivateTime != TIME_NOT_SET) { if (Time.time - lastActivateTime < COOL_DOWN_DURATION) { hasGaze = false; } else { lastActivateTime = TIME_NOT_SET; } } //update gaze time if (hasGaze) { _bgTransform.Rotate(Vector3.forward); if (lastGazeTime == TIME_NOT_SET) { lastGazeTime = Time.time; } } else if (lastGazeTime != TIME_NOT_SET) { lastGazeTime = TIME_NOT_SET; } //respond to gaze time if (lastGazeTime == TIME_NOT_SET) { if (lastActivateTime == TIME_NOT_SET) { _bgSpriteRenderer.color = Color.red; } else { _bgSpriteRenderer.color = Color.green; } } else if (Time.time - lastGazeTime < ACTIVATE_THRESHOLD) { _bgSpriteRenderer.color = Color.yellow; } else { _bgSpriteRenderer.color = Color.green; if (targetScene != "") { Application.LoadLevel(targetScene); if (targetScene == "drive" || targetScene == "arm") { UnityArduino.SetStreamControlData(true); } else { UnityArduino.SetStreamControlData(false); } } if (controlData != "") { UnityArduino.SendImmediate(controlData); } lastActivateTime = Time.time; } }