void Start() { leftHand = capsuleHandLeftPrefab.GetComponent <MyCapsuleHand>(); rightHand = capsuleHandRightPrefab.GetComponent <MyCapsuleHand>(); expanDialSticks = expanDialSticksPrefab.GetComponent <ExpanDialSticks>(); safeGuard = safeGuardPrefab.GetComponent <SafeGuard>(); // Listen to events expanDialSticks.OnConnecting += HandleConnecting; expanDialSticks.OnConnected += HandleConnected; expanDialSticks.OnDisconnected += HandleDisconnected; expanDialSticks.OnXAxisChanged += HandleXAxisChanged; expanDialSticks.OnYAxisChanged += HandleYAxisChanged; expanDialSticks.OnClickChanged += HandleClickChanged; expanDialSticks.OnRotationChanged += HandleRotationChanged; expanDialSticks.OnPositionChanged += HandlePositionChanged; expanDialSticks.onHoldingChanged += HandleHoldingChanged; expanDialSticks.onReachingChanged += HandleReachingChanged; connected = false; expanDialSticks.client_MqttConnect(); // generate potential candidates orderedCandidates = new List <Vector3Int>(); prevOrderedCandidate = new Vector3Int(-1, -1, -1); candidates = new List <Vector2Int>(); //= Enumerable.Range(0, nbPins).ToList<int>(); // get pins inside matrix only for (int i = 1; i < expanDialSticks.NbRows - 1; i++) { for (int j = 1; j < expanDialSticks.NbColumns - 1; j++) { candidates.Add(new Vector2Int(i, j)); } } // Generate trials overlays = new List <ExpanDialSticks.SafetyOverlayMode> { ExpanDialSticks.SafetyOverlayMode.Edge, ExpanDialSticks.SafetyOverlayMode.Fill, ExpanDialSticks.SafetyOverlayMode.Hull, ExpanDialSticks.SafetyOverlayMode.Zone }; currOverlay = ExpanDialSticks.SafetyOverlayMode.None; difficulties = new List <Difficulty> { Difficulty.Easy, Difficulty.Medium, Difficulty.Hard }; trials = new Dictionary <Difficulty, List <List <int> > >(); nbTrials = 0; }
void OnGUI() { if (unknownParticipant) { // Make a text field that modifies stringToEdit. float midX = Screen.width / 2.0f; float midY = Screen.height / 2.0f; float componentHeight = 20; //GUI.Label(new Rect(midX - 50 - , midY, 100, 20), "Hello World!"); stringParticipant = GUI.TextField(new Rect(midX - 55, midY, 50, componentHeight), stringParticipant, 25); if (GUI.Button(new Rect(midX + 5, midY - 50, 150, componentHeight), "Training Overlay")) { numeroParticipant = int.Parse(stringParticipant); Debug.Log("TRAINING"); string identity = "USER_IDENTITY " + numeroParticipant + " TRAINING"; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(identity), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); // init trials /*InitTrials(); * moleIndex = -1; * moleState = MOLE_TO_APPEAR; * * currTime = LOG_INTERVAL; * prevTime = 0f; * string identity = "USER_IDENTITY " + numeroParticipant + " USER_TRIGGERED TRAINING"; * expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(identity), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); */ unknownParticipant = false; } if (GUI.Button(new Rect(midX + 5, midY - 25, 150, componentHeight), "Edge Overlay")) { expanDialSticks.SetSafetyMode(ExpanDialSticks.SafetyMotionMode.SafetyRatedMonitoredStop); numeroParticipant = int.Parse(stringParticipant); Debug.Log("Start"); currOverlay = ExpanDialSticks.SafetyOverlayMode.Edge; expanDialSticks.SetOverlayMode(currOverlay); expanDialSticks.triggerSafetyChange(); string identity = "USER_IDENTITY " + numeroParticipant + " EDGE_OVERLAY"; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(identity), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); unknownParticipant = false; } if (GUI.Button(new Rect(midX + 5, midY, 150, componentHeight), "Surface Overlay")) { expanDialSticks.SetSafetyMode(ExpanDialSticks.SafetyMotionMode.SafetyRatedMonitoredStop); numeroParticipant = int.Parse(stringParticipant); Debug.Log("Start"); currOverlay = ExpanDialSticks.SafetyOverlayMode.Fill; expanDialSticks.SetOverlayMode(currOverlay); expanDialSticks.triggerSafetyChange(); string identity = "USER_IDENTITY " + numeroParticipant + " SURFACE_OVERLAY"; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(identity), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); unknownParticipant = false; } if (GUI.Button(new Rect(midX + 5, midY + 25, 150, componentHeight), "Hull Overlay")) { expanDialSticks.SetSafetyMode(ExpanDialSticks.SafetyMotionMode.SafetyRatedMonitoredStop); numeroParticipant = int.Parse(stringParticipant); Debug.Log("Start"); currOverlay = ExpanDialSticks.SafetyOverlayMode.Hull; expanDialSticks.SetOverlayMode(currOverlay); expanDialSticks.triggerSafetyChange(); string identity = "USER_IDENTITY " + numeroParticipant + " HULL_OVERLAY"; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(identity), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); unknownParticipant = false; } if (GUI.Button(new Rect(midX + 5, midY + 50, 150, componentHeight), "Zone Overlay")) { expanDialSticks.SetSafetyMode(ExpanDialSticks.SafetyMotionMode.SafetyRatedMonitoredStop); numeroParticipant = int.Parse(stringParticipant); Debug.Log("Start"); currOverlay = ExpanDialSticks.SafetyOverlayMode.Zone; expanDialSticks.SetOverlayMode(currOverlay); expanDialSticks.triggerSafetyChange(); string identity = "USER_IDENTITY " + numeroParticipant + " ZONE_OVERLAY"; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(identity), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); unknownParticipant = false; } } }
private void TriggerNextTrial() { if (!landscapeGenerated) { for (int i = 0; i < expanDialSticks.NbRows; i++) { for (int j = 0; j < expanDialSticks.NbColumns; j++) { expanDialSticks.modelMatrix[i, j].TargetPosition = (sbyte)Random.Range(minPos, maxPos); expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = shapeChangeDuration; } } landscapeGenerated = true; } if (trials.Count() > 0) { // Unfreeze hand tracking safeGuard.UnFreeze(); // Extract difficulty and changes KeyValuePair <Difficulty, List <List <int> > > difficultyChanges = trials.First(); currDifficulty = difficultyChanges.Key; Debug.Log("currDifficulty -> " + currDifficulty); List <List <int> > changes = difficultyChanges.Value; currSubChanges = changes.First(); ExpanDialSticks.SafetyOverlayMode nextOverlay = (ExpanDialSticks.SafetyOverlayMode)currSubChanges.First(); // new overlay detected if (currOverlay != nextOverlay) { currOverlay = nextOverlay; expanDialSticks.SetOverlayMode(currOverlay); ResetDisplay(); newOverlay = true; toNextTrial = false; return; } // current trial; currTrial++; changes.RemoveAt(0); currSubChanges.RemoveAt(0); ListExtension.Shuffle(currSubChanges); Debug.Log("currSubChanges -> " + currSubChanges); // delete difficulty or if any reinsert remaining changes if (changes.Count() > 0) { trials[currDifficulty] = changes; } else { trials.Remove(currDifficulty); } // get a target for user target = candidates[Random.Range(0, candidates.Count())]; // Output Control List <int> randomIcons = new List <int>(); //= Enumerable.Range(0, nbPins).ToList<int>(); for (int i = 1; i < 30; i++) { randomIcons.Add(i); } ListExtension.Shuffle(randomIcons); for (int i = 0; i < expanDialSticks.NbRows; i++) { for (int j = 0; j < expanDialSticks.NbColumns; j++) { if (target.x == i && target.y == j) { expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon0"; } else { expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon" + randomIcons.First(); randomIcons.RemoveAt(0); } // Projector expanDialSticks.modelMatrix[i, j].TargetProjectorRotation = 90f; expanDialSticks.modelMatrix[i, j].TargetProjectorSize = expanDialSticks.modelMatrix[i, j].Diameter / 3f; expanDialSticks.modelMatrix[i, j].TargetProjectorChangeDuration = 0.1f; } } expanDialSticks.triggerProjectorChange(); expanDialSticks.triggerShapeChange(); DisplayInstructions("Tourner le cylindre avec l'icône <b>Avion</b>"); string trialMsg = "PARTICIPANT " + numeroParticipant + " DIFFICULTY " + currDifficulty + " OVERLAY " + currOverlay + " TARGET (" + target.x + ", " + target.y + ") "; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(trialMsg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); toNextTrial = false; overlayAppeared = false; } else { Quit(); } }