void OnGUI() { // Make a text field that modifies stringToEdit. float midX = Screen.width / 2.0f; float midY = Screen.height / 2.0f; float componentHeight = 20; float componentWidth = 50; stringCameraX = GUI.TextField(new Rect(midX - 100, 50, 50, componentHeight), stringCameraX, 25); stringCameraY = GUI.TextField(new Rect(midX - 50, 50, 50, componentHeight), stringCameraY, 25); stringCameraZ = GUI.TextField(new Rect(midX, 50, 50, componentHeight), stringCameraZ, 25); if (GUI.Button(new Rect(midX + 50, 50, componentWidth, componentHeight), "CAMERA")) { float cameraX = float.Parse(stringCameraX); float cameraY = float.Parse(stringCameraY); float cameraZ = float.Parse(stringCameraZ); SARCameraPrefab.transform.position = new Vector3(cameraX, cameraY, cameraZ); } int index = 0; int position = 0; stringIndex = GUI.TextField(new Rect(midX - 25, 25, 50, componentHeight), stringIndex, 25); stringPosition = GUI.TextField(new Rect(midX + 25, 25, 50, componentHeight), stringPosition, 25); if (GUI.Button(new Rect(midX + 75, 25, componentWidth, componentHeight), "SEND")) { index = int.Parse(stringIndex); position = int.Parse(stringPosition); Debug.Log(index + " " + position); int row = (int)(index / (float)expanDialSticks.NbColumns); int column = index % expanDialSticks.NbColumns; Debug.Log(row + " " + column); expanDialSticks.modelMatrix[row, column].TargetPosition = (sbyte)position; expanDialSticks.modelMatrix[row, column].TargetShapeChangeDuration = 2f; expanDialSticks.triggerShapeChange(); } if (GUI.Button(new Rect(midX + 150, 25, componentWidth, componentHeight), "CROSS")) { for (int i = 0; i < expanDialSticks.NbRows; i++) { for (int j = 0; j < expanDialSticks.NbColumns; j++) { expanDialSticks.modelMatrix[i, j].TargetColor = Color.red; expanDialSticks.modelMatrix[i, j].TargetTextureChangeDuration = 0.1f; expanDialSticks.modelMatrix[i, j].TargetProjectorFrontTexture = "cross-reverse"; expanDialSticks.modelMatrix[i, j].TargetProjectorFrontColor = Color.white; expanDialSticks.modelMatrix[i, j].TargetProjectorFrontRotation = 90f; expanDialSticks.modelMatrix[i, j].TargetProjectorFrontSize = 0.02f; expanDialSticks.modelMatrix[i, j].TargetProjectorFrontChangeDuration = 0.1f; } } expanDialSticks.triggerProjectorChange(); expanDialSticks.triggerTextureChange(); } }
// 1. void display0() { ClearAllChange(); string[] xTimes = new string[] { "Jan. 2021", "Feb. 2021", "Mar. 2021", "Apr. 2021", "May 2021" }; string[] xSpaces = new string[] { "ESTIA1", "ESTIA2", "ESTIA3", "ESTIA4", "ESTIA5", "ESTIA6" }; sbyte[] yData = new sbyte[] { 12, 18, 25, 10, 20 }; string xAxisLegend = "<size=7><line-height=60>"; for (int i = 0; i < xTimes.Length; i++) { xAxisLegend += xTimes[i] + "\n"; } string yAxisLegend = "<size=7>"; for (int i = 0; i < xSpaces.Length; i++) { yAxisLegend += xSpaces[i] + "<space=38>"; } for (int i = 0; i < expanDialSticks.NbRows; i++) { for (int j = 0; j < expanDialSticks.NbColumns; j++) { int datum = UnityEngine.Random.Range(0, 40); float coeff = datum / 40f; expanDialSticks[i, j].TargetText = "<b>" + datum + " MWh</b>"; expanDialSticks[i, j].TargetColor = new Color(1f - coeff, 1f - coeff, 1f); expanDialSticks[i, j].TargetTextureChangeDuration = 1f; expanDialSticks[i, j].TargetPosition = (sbyte)datum; expanDialSticks[i, j].TargetShapeChangeDuration = 1f; } } expanDialSticks.triggerTextureChange(); expanDialSticks.triggerShapeChange(); /*string legend = "<line-height=1em><voffset=-8><size=32><color=\"green\">•</voffset><size=8><color=\"black\">energy production\n" + "<voffset=-8><size=32><color=\"orange\">•</voffset><size=8><color=\"black\">energy storage\n" + "<voffset=-8><size=32><color=\"blue\">•</voffset><size=8><color=\"black\">energy consumption\n";*/ /*string labels = "<size=7><pos=3%>Past month <pos=85%>Next month\n"; * string direction = "<line-height=10><size=9>◄────────────────────────────────────────────►\n"; * string titles = "<b><line-height=10><size=10><pos=0%>Data Type<pos=30%>Mode<pos=50%>Time Scale<pos=75%>Space Scale</b>\n"; * string firstOption = "<line-height=7><size=7><pos=0%><color=#0000FFFF>■ <color=#000000FF>Energy Consumption<pos=30%><alpha=#FF>Time<pos=50%><alpha=#AA>Hours<pos=75%><alpha=#AA>Devices\n"; * string secondOption = "<line-height=7><size=7><pos=0%><color=#FF9900AA>■ <color=#000000AA>Energy Storage<pos=30%><alpha=#AA>Space<pos=50%><alpha=#AA>Days<pos=75%><alpha=#AA>Rooms\n"; * string thirdOption = "<line-height=7><size=7><pos=0%><color=#00FF00AA>■ <color=#000000AA>Energy Production<pos=50%><alpha=#FF>Months<pos=75%><alpha=#FF>Buildings ► ESTIA1\n"; * string legend = labels + direction + titles + firstOption + secondOption + thirdOption;*/ expanDialSticks.setLeftBorderText(TextAlignmentOptions.Center, 16, Color.black, xAxisLegend, new Vector3(90f, -90f, 0f)); expanDialSticks.setBottomBorderText(TextAlignmentOptions.Center, 8, Color.black, yAxisLegend, new Vector3(90f, -90f, 0f)); //expanDialSticks.setRightBorderText(TextAlignmentOptions.Center, 16, Color.black, legend, new Vector3(90f, 90f, 0f)); }
void calibrate0() { for (int i = 0; i < expanDialSticks.NbRows; i++) { for (int j = 0; j < expanDialSticks.NbColumns; j++) { expanDialSticks[i, j].TargetColor = new Color(1f, 1f, 1f); expanDialSticks[i, j].TargetPlaneTexture = "cross"; expanDialSticks[i, j].TargetTextureChangeDuration = 1f; } } expanDialSticks.triggerTextureChange(); expanDialSticks.triggerShapeChange(); }
/*void AllReset(float duration) * { * for (int i = 0; i < expanDialSticks.NbRows; i++) * { * for (int j = 0; j < expanDialSticks.NbColumns; j++) * { * expanDialSticks.modelMatrix[i, j].TargetColor = Color.black; * expanDialSticks.modelMatrix[i, j].TargetTextureChangeDuration = duration; * expanDialSticks.modelMatrix[i, j].TargetPosition = -1; * expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = duration; * * } * } * expanDialSticks.triggerTextureChange(); * expanDialSticks.triggerShapeChange(); * } * * * void AllUp(float duration) * { * for (int i = 0; i < expanDialSticks.NbRows; i++) * { * for (int j = 0; j < expanDialSticks.NbColumns; j++) * { * expanDialSticks.modelMatrix[i, j].TargetColor = Color.white; * expanDialSticks.modelMatrix[i, j].TargetTextureChangeDuration = duration; * expanDialSticks.modelMatrix[i, j].TargetPosition = 40; * expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = duration; * } * } * expanDialSticks.triggerTextureChange(); * expanDialSticks.triggerShapeChange(); * }*/ void AllDown(float duration) { for (int i = 0; i < expanDialSticks.NbRows; i++) { for (int j = 0; j < expanDialSticks.NbColumns; j++) { expanDialSticks.modelMatrix[i, j].TargetColor = Color.white; expanDialSticks.modelMatrix[i, j].TargetPosition = 0; expanDialSticks.modelMatrix[i, j].TargetTextureChangeDuration = duration; expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = duration; } } expanDialSticks.triggerTextureChange(); expanDialSticks.triggerShapeChange(); }
private void HandleConnected(object sender, MqttConnectionEventArgs e) { Debug.Log("Application connected."); connected = true; ViewFromDataSet(); expanDialSticks.triggerTextureChange(); expanDialSticks.triggerShapeChange(); }
void AllUp(List <Vector3> safePositionAndSpeeds) { foreach (Vector3 safePositionAndSpeed in safePositionAndSpeeds) { int i = (int)safePositionAndSpeed.x; int j = (int)safePositionAndSpeed.y; float speedCoeff = safePositionAndSpeed.z; // 1 stop, 0.5 half, 0.3 sbyte targetPos = 40; float safetySpeed = maxSpeed * (1f - speedCoeff); // 20 pos per sec max float distance = Math.Abs(targetPos - expanDialSticks.modelMatrix[i, j].CurrentPosition); float safetyDuration = Math.Max(distance / safetySpeed, 0.1f); expanDialSticks.modelMatrix[i, j].TargetPosition = targetPos; Debug.Log(i + " " + j + " " + safetyDuration); expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = safetyDuration; } expanDialSticks.triggerShapeChange(); }
void Update() { // check if ExpanDialSticks is connected if (connected) { if (Input.GetKey("escape") || (currentIndex > expanDialSticks.NbRows * expanDialSticks.NbColumns - 1)) { Quit(); } if (Input.GetKeyDown("i")) { for (int i = 0; i < expanDialSticks.NbRows; i++) { for (int j = 0; j < expanDialSticks.NbColumns; j++) { expanDialSticks.modelMatrix[i, j].TargetColor = Color.red; expanDialSticks.modelMatrix[i, j].TargetTextureChangeDuration = 0.1f; expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "cross-reverse"; expanDialSticks.modelMatrix[i, j].TargetProjectorColor = Color.white; expanDialSticks.modelMatrix[i, j].TargetProjectorRotation = 90f; expanDialSticks.modelMatrix[i, j].TargetProjectorSize = 2f; expanDialSticks.modelMatrix[i, j].TargetProjectorChangeDuration = 0.1f; } } expanDialSticks.triggerProjectorChange(); expanDialSticks.triggerTextureChange(); } if (Input.GetKeyDown("n")) { int i = currentIndex / expanDialSticks.NbColumns; // int i = 4; int j = currentIndex % expanDialSticks.NbColumns; // int j = 3; expanDialSticks.modelMatrix[i, j].TargetPosition = 30; expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = 1f; expanDialSticks.triggerShapeChange(); currentIndex++; Debug.Log(i + " " + j + " " + 30); } } }
private void TriggerNextTrial() { if (trials.Count() > 0) { List <Vector3Int> unsafes; List <Vector3Int> safes; //Vector2Int rightCandidatePosition = new Vector2Int(rightCandidate.x, rightCandidate.y); bool candidatesFound = false; int iconFactorIndex = -1; while (!candidatesFound) { iconFactorIndex++; if (iconFactorIndex < trials.Count()) { currIconUnder = trials[iconFactorIndex]; Debug.Log("Looking for candidates (" + currIconUnder + ")..."); // get all pins under and around user body unsafes = FindAllUnsafesUnderDistance(safetyDistance); safes = FindAllSafesAboveDistance(safetyDistance); // prevent same candidates unsafes.RemoveAll(x => movingCandidates.Contains(x)); safes.RemoveAll(x => movingCandidates.Contains(x)); // candidates to find under or above int nbUnderCandidates = currIconUnder; int nbAroundCandidates = maxIconUnder - currIconUnder; Predicate <Vector3Int> hasPotentialRightCandidate = candidate => Math.Abs(positionCandidates.Last() - candidate.z) >= stepPositionCandidate; List <Vector3Int> potentialRightCandidates = new List <Vector3Int>(); potentialRightCandidates.AddRange(unsafes.FindAll(hasPotentialRightCandidate)); potentialRightCandidates.AddRange(safes.FindAll(hasPotentialRightCandidate)); // if there is enough candidates if (unsafes.Count() >= nbUnderCandidates && safes.Count() >= nbAroundCandidates && potentialRightCandidates.Count() > 0) { // Randomly select the right candidate rightCandidate = potentialRightCandidates[Random.Range(0, potentialRightCandidates.Count())]; // Get all moving candidates movingCandidates = new List <Vector3Int>(); ListExtension.Shuffle(unsafes); ListExtension.Shuffle(safes); bool isSafe = safes.Remove(rightCandidate); //Debug.Log("isSafe => " + isSafe); bool isUnsafe = unsafes.Remove(rightCandidate); //Debug.Log("isUnsafe => " + isUnsafe); // check if right candidates is safe or unsafe to not select him if (isSafe) { movingCandidates.AddRange(unsafes.GetRange(0, nbUnderCandidates)); movingCandidates.AddRange(safes.GetRange(0, nbAroundCandidates - 1)); } else if (isUnsafe) { movingCandidates.AddRange(unsafes.GetRange(0, nbUnderCandidates - 1)); movingCandidates.AddRange(safes.GetRange(0, nbAroundCandidates)); } // generate position for moving candidates for (int i = 0; i < movingCandidates.Count(); i++) { Vector3Int movingCandidate = movingCandidates[i]; movingCandidate.z = Math.Abs(positionCandidates[0] - movingCandidate.z) > Math.Abs(positionCandidates[1] - movingCandidate.z) ? positionCandidates[0] : positionCandidates[1]; movingCandidates[i] = movingCandidate; } //Debug.Log("movingCandidates.Count() => " + movingCandidates.Count()); // Select a wrong candidate wrongCandidate = movingCandidates[Random.Range(0, movingCandidates.Count())]; // Add the right candidate to moving candidate rightCandidate.z = positionCandidates.Last(); movingCandidates.Add(rightCandidate); candidatesFound = true; } else { //What if? } } else // fails to find candidates for remaining icon factor { Debug.Log("Candidates Fail! Adding IconFactor.NoIconUnder."); iconFactorIndex = -1; trials.Insert(0, 0); } } Debug.Log("Candidates Successfully found!"); trials.RemoveAt(iconFactorIndex); // 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++) { Vector3Int movingCandidate = movingCandidates.Find(l => (l.x == i && l.y == j)); if (rightCandidate.x == i && rightCandidate.y == j) { Debug.Log("rightCandidate => " + rightCandidate); // Projector expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon0"; // Shape expanDialSticks.modelMatrix[i, j].TargetPosition = (sbyte)rightCandidate.z; expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = shapeChangeDuration; } else if (wrongCandidate.x == i && wrongCandidate.y == j) { Debug.Log("wrongCandidate => " + wrongCandidate); // Projector expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon0"; // Shape expanDialSticks.modelMatrix[i, j].TargetPosition = (sbyte)wrongCandidate.z; expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = shapeChangeDuration; } else if (movingCandidate != new Vector3Int()) { Debug.Log("movingCandidate => " + movingCandidate); // Projector expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon" + randomIcons.First(); randomIcons.RemoveAt(0); // Shape expanDialSticks.modelMatrix[i, j].TargetPosition = (sbyte)movingCandidate.z; expanDialSticks.modelMatrix[i, j].TargetShapeChangeDuration = shapeChangeDuration; } else { // Projector //expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "default"; expanDialSticks.modelMatrix[i, j].TargetProjectorTexture = "icon" + randomIcons.First(); randomIcons.RemoveAt(0); } // Projector expanDialSticks.modelMatrix[i, j].TargetProjectorRotation = 90f; expanDialSticks.modelMatrix[i, j].TargetProjectorSize = 2f; expanDialSticks.modelMatrix[i, j].TargetProjectorChangeDuration = 0.1f; } } expanDialSticks.triggerProjectorChange(); expanDialSticks.triggerShapeChange(); string participantNumber = "<pos=0%><b>P" + numeroParticipant + "</b>"; string trialProgress = "<pos=90%><b>" + trials.Count() + "/" + nbTrials + "</b>"; string legend = participantNumber + trialProgress; expanDialSticks.setBottomBorderText(TextAlignmentOptions.Center, 16, Color.black, legend, new Vector3(90f, -90f, 0f)); expanDialSticks.setBorderBackground(Color.white); expanDialSticks.triggerTextureChange(); string iconSituationMsg = "ICON_APPARATUS " + currIconUnder; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(iconSituationMsg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); string selectCandidateMsg = "SYSTEM_SELECT_PIN "; foreach (Vector3Int movingCandidate in movingCandidates) { selectCandidateMsg += "(" + movingCandidate.x + ", " + movingCandidate.y + ", " + movingCandidate.z + ") "; } expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(selectCandidateMsg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); string rightCandidateMsg = "SYSTEM_RIGHT_PIN (" + rightCandidate.x + ", " + rightCandidate.y + ", " + rightCandidate.z + ")"; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(rightCandidateMsg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); string wrongCandidateMsg = "SYSTEM_WRONG_PIN (" + wrongCandidate.x + ", " + wrongCandidate.y + ", " + wrongCandidate.z + ")"; expanDialSticks.client.Publish(MQTT_SYSTEM_RECORDER, System.Text.Encoding.UTF8.GetBytes(wrongCandidateMsg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); } else { Quit(); } }
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(); } }
void TriggerShapeChangeUp() { expanDialSticks.modelMatrix[2, 2].TargetPosition = 40; expanDialSticks.modelMatrix[2, 2].TargetShapeChangeDuration = 4f; expanDialSticks.triggerShapeChange(); }
// Rover Control void displayRoverControlStart() { ClearAllChange(); // Pitch/Roll/Yaw/Throlle/On/Pull/push // Button on/off expanDialSticks[4, 5].TargetText = "Start"; expanDialSticks[4, 5].TargetColor = new Color(0f, 1f, 0f); expanDialSticks[4, 5].TargetTextSize = 2f; expanDialSticks[4, 5].TargetTextureChangeDuration = 1f; expanDialSticks[4, 5].TargetPosition = 5; expanDialSticks[4, 5].TargetShapeChangeDuration = 1f; expanDialSticks.triggerTextureChange(); expanDialSticks.triggerShapeChange(); string legend = "Starting the rover with a button."; expanDialSticks.setLeftBorderText(TextAlignmentOptions.Center, LEGEND_SIZE, Color.black, legend, new Vector3(90f, 0f, 0f)); expanDialSticks.setRightBorderText(TextAlignmentOptions.Center, LEGEND_SIZE, Color.black, legend, new Vector3(90f, 180f, 0f)); }