public void SetLastCredentials(string flagset, int credentials) { if (!LastCredentialsByFlagset.ContainsKey(flagset)) { LastCredentialsByFlagset.Add(flagset, credentials); } else { LastCredentialsByFlagset [flagset] = credentials; } Player.Get.AvatarActions.ReceiveAction(AvatarAction.SkillCredentialsGain, WorldClock.AdjustedRealTime); }
private static void StringAddGUI <TValue>(SDictionary <string, TValue> dict, ref string toAdd, GetNew <TValue> getNew) { EditorGUILayout.LabelField("New:", GUILayout.Width(45)); toAdd = EditorGUILayout.TextField(toAdd); if (GUILayout.Button(new GUIContent("Add"), GUILayout.Width(45))) { if (!string.IsNullOrWhiteSpace(toAdd) && !dict.ContainsKey(toAdd)) { dict.Add(toAdd, getNew()); } toAdd = string.Empty; GUIUtility.keyboardControl = 0; } }
public void FinishSpeech(string characterName) { if (FinishedByCharacters.ContainsKey(characterName)) { int numTimes = FinishedByCharacters [characterName] + 1; FinishedByCharacters [characterName] = numTimes; } else { FinishedByCharacters.Add(characterName, 1); } NumTimesCompleted++; NumUsers--; }
public void StartSpeech(string characterName) { if (StartedByCharacters.ContainsKey(characterName)) { int numTimes = StartedByCharacters [characterName] + 1; StartedByCharacters [characterName] = numTimes; } else { StartedByCharacters.Add(characterName, 1); } NumTimesStarted++; NumUsers++; }
private static void EnumAddGUI <TKey, TValue>(this SDictionary <TKey, TValue> dict, GetNew <TValue> getNew) where TKey : System.Enum { if (EditorGUILayout.DropdownButton(new GUIContent("+"), FocusType.Keyboard)) { GenericMenu menu = new GenericMenu(); foreach (var t in EnumUtils.GetValues <TKey>()) { if (!dict.ContainsKey(t)) { menu.AddItem(new GUIContent(t.ToString()), false, (obj) => dict.Add((TKey)obj, getNew()), t); } } menu.ShowAsContext(); } }
// Update is called once per frame void Update() { if (Time.time > nextActionTime) { nextActionTime += period; // Layer 9 is TrackedVisual layer int layerMask = 1 << 9; RaycastHit hit; Physics.Raycast(viewport.transform.position, viewport.transform.forward, out hit, 20.0F, layerMask); Debug.DrawRay(viewport.transform.position, viewport.transform.forward); bool indexChanged = false; bool viewportChanged = false; if (hit.collider) { // Calculate Voxel position in unrotated space Vector3 vectorFromCenter = hit.point - gameObject.transform.position; Vector3 rotatedVectorFromCenter = Quaternion.Inverse(gameObject.transform.rotation) * vectorFromCenter; Vector3 index = new Vector3(Mathf.Round((1 / gridInterval[0]) * rotatedVectorFromCenter[0]) / (1 / gridInterval[0]), Mathf.Round((1 / gridInterval[1]) * rotatedVectorFromCenter[1]) / (1 / gridInterval[1]), Mathf.Round((1 / gridInterval[2]) * rotatedVectorFromCenter[2]) / (1 / gridInterval[2])); index = new Vector3(index[0] / gameObject.transform.localScale[0], index[1] / gameObject.transform.localScale[1], index[2] / gameObject.transform.localScale[2]); // Has the cube changed /* * Update the time spent at the previous cube * * Create a new cube if required */ if (index != currentVoxel.position) { indexChanged = true; // Finish previous instance float elapsedTime = Time.time - currentVoxel.lastViewedAt; currentVoxel.timeViewed += elapsedTime; currentVoxel.uniqueViews += 1; currentVoxel.lastViewedAt = Time.time; // Save results back to the previous Voxel voxelDict[currentVoxel.position] = currentVoxel; // Retrieve or Start a new instance if (voxelDict.ContainsKey(index)) { currentVoxel = voxelDict[index]; } else { currentVoxel = new Voxel(); // set initial values currentVoxel.name = hit.transform.gameObject.name; currentVoxel.position = index; currentVoxel.uniqueViews = 0; currentVoxel.timeViewed = 0.0f; currentVoxel.lastViewedAt = Time.time; currentVoxel.gridInterval = gridInterval; if (marker != null) { if (VisualisationOffset != null) { displayPosition = new Vector3(); displayPosition = index; displayPosition = new Vector3(displayPosition[0] * gameObject.transform.localScale[0], displayPosition[1] * gameObject.transform.localScale[1], displayPosition[2] * gameObject.transform.localScale[2]); displayPosition = displayPosition + VisualisationOffset.transform.position; currentVoxel.boundryBox = Instantiate(marker, displayPosition, Quaternion.identity);//, VisualisationOffset.transform); currentVoxel.boundryBox.layer = 3; Debug.DrawLine(previousDisplayPosition, displayPosition, Color.red, 100.0f); } else { displayPosition = new Vector3(); displayPosition = index; displayPosition = new Vector3(displayPosition[0] * gameObject.transform.localScale[0], displayPosition[1] * gameObject.transform.localScale[1], displayPosition[2] * gameObject.transform.localScale[2]); currentVoxel.boundryBox = Instantiate(marker, displayPosition, Quaternion.identity); Debug.DrawLine(previousDisplayPosition, displayPosition, Color.red, 100.0f); } } } } // Save a copy of the last voxel index for easy look ups previousIndex = index; previousDisplayPosition = displayPosition; // If we are tracking camera location, we can do the whole shebang again if (trackLocation) { if (hit.collider) { // Calculate Voxel position in unrotated space vectorFromCenter = viewport.transform.position - gameObject.transform.position; rotatedVectorFromCenter = Quaternion.Inverse(gameObject.transform.rotation) * vectorFromCenter; //Vector3 viewportIndex = new Vector3(rotatedVectorFromCenter[0] - (rotatedVectorFromCenter[0] % viewportGridInterval) + viewportGridInterval / 2, rotatedVectorFromCenter[1] - (rotatedVectorFromCenter[1] % viewportGridInterval) + viewportGridInterval / 2, rotatedVectorFromCenter[2] - (rotatedVectorFromCenter[2] % viewportGridInterval) + viewportGridInterval / 2); //Vector3 viewportIndex = new Vector3(Mathf.Round((1 / viewportGridInterval) * rotatedVectorFromCenter[0]) / (1 / viewportGridInterval) + (viewportGridInterval / 2), Mathf.Round((1 / viewportGridInterval) * rotatedVectorFromCenter[1]) / (1 / viewportGridInterval) + (viewportGridInterval / 2), Mathf.Round((1 / viewportGridInterval) * rotatedVectorFromCenter[2]) / (1 / viewportGridInterval) + (viewportGridInterval / 2)); Vector3 viewportIndex = new Vector3(Mathf.Round((1 / viewportGridInterval[0]) * rotatedVectorFromCenter[0]) / (1 / viewportGridInterval[0]), Mathf.Round((1 / viewportGridInterval[1]) * rotatedVectorFromCenter[1]) / (1 / viewportGridInterval[1]), Mathf.Round((1 / viewportGridInterval[2]) * rotatedVectorFromCenter[2]) / (1 / viewportGridInterval[2])); //viewportIndex = new Vector3(viewportIndex[0] / gameObject.transform.localScale[0], viewportIndex[1] / gameObject.transform.localScale[1], viewportIndex[2] / gameObject.transform.localScale[2]); if (viewportIndex != currentViewportVoxel.position) { viewportChanged = true; // Finish previous instance float elapsedTime = Time.time - currentViewportVoxel.lastViewedAt; currentViewportVoxel.timeViewed += elapsedTime; currentViewportVoxel.uniqueViews += 1; currentViewportVoxel.lastViewedAt = Time.time; currentViewportVoxel.gridInterval = viewportGridInterval; // Save results back to the previous Voxel viewportVoxelDict[currentViewportVoxel.position] = currentViewportVoxel; // Retrieve or Start a new instance if (voxelDict.ContainsKey(viewportIndex)) { currentViewportVoxel = viewportVoxelDict[viewportIndex]; } else { currentViewportVoxel = new Voxel(); // set initial values currentViewportVoxel.name = "Camera"; currentViewportVoxel.position = viewportIndex; currentViewportVoxel.uniqueViews = 0; currentViewportVoxel.timeViewed = 0.0f; currentViewportVoxel.lastViewedAt = Time.time; if (marker != null) { if (VisualisationOffset != null) { viewportDisplayPosition = new Vector3(); viewportDisplayPosition = viewportIndex; viewportDisplayPosition = new Vector3(viewportDisplayPosition[0] * gameObject.transform.localScale[0], viewportDisplayPosition[1] * gameObject.transform.localScale[1], viewportDisplayPosition[2] * gameObject.transform.localScale[2]); viewportDisplayPosition = viewportIndex + VisualisationOffset.transform.position; currentViewportVoxel.boundryBox = Instantiate(viewportMarker, viewportDisplayPosition, Quaternion.identity);//, VisualisationOffset.transform); currentViewportVoxel.boundryBox.layer = 3; Debug.DrawLine(previousViewportDisplayPosition, viewportDisplayPosition, Color.green, 100.0f); } else { viewportDisplayPosition = new Vector3(); viewportDisplayPosition = viewportIndex; //viewportDisplayPosition = new Vector3(viewportDisplayPosition[0] * gameObject.transform.localScale[0], viewportDisplayPosition[1] * gameObject.transform.localScale[1], viewportDisplayPosition[2] * gameObject.transform.localScale[2]); currentViewportVoxel.boundryBox = Instantiate(viewportMarker, viewportDisplayPosition, Quaternion.identity); Debug.DrawLine(previousViewportDisplayPosition, viewportDisplayPosition, Color.green, 100.0f); } } } } previousViewportIndex = viewportIndex; previousViewportDisplayPosition = viewportDisplayPosition; // A horribly messy solution to record the connections /* * A three depth nested dictionary * {Vector3 : { Vector3 : { string : float }}} * {Object : { Viewport : { statistic : value }}} * If either the viewportIndex or the Index has changed, we need to add a connection. */ if (indexChanged || viewportChanged) { // Test if the index has already been index if (!connectionDict.ContainsKey(index)) { // Create the statistic dictionary V3Dictionary statDict = new V3Dictionary(); statDict.Add("uniqueViews", 1.0f); statDict.Add("distance", hit.distance); V2Dictionary viewportDict = new V2Dictionary(); viewportDict.Add(viewportIndex, statDict); connectionDict.Add(index, viewportDict); } else { if (!connectionDict[index].ContainsKey(viewportIndex)) { // Create the statistic dictionary V3Dictionary statDict = new V3Dictionary(); statDict.Add("uniqueViews", 1.0f); statDict.Add("distance", hit.distance); V2Dictionary viewportDict = connectionDict[index]; viewportDict.Add(viewportIndex, statDict); connectionDict[index] = viewportDict; } else { V3Dictionary statDict = connectionDict[index][viewportIndex]; statDict["uniqueViews"] += 1.0f; statDict["distance"] += hit.distance; connectionDict[index][viewportIndex] = statDict; } } Debug.DrawLine(displayPosition, viewportDisplayPosition, Color.blue, 100.0f); } } } } // translate object for 10 seconds. if (exportData) { // translate object for 10 seconds. if (timeLimit < 0) { Debug.Log("Time to Export"); ExportData(); timeLimit = exportTime; } else { timeLimit -= Time.deltaTime; } } } }