public static void ReceiveEvent(STKEvent e) { if (savedEvents.ContainsKey(e.eventName)) { List <STKEvent> eventsList = (List <STKEvent>)savedEvents[e.eventName]; eventsList.Add(e); savedEvents[e.eventName] = eventsList; if (settings.useSlidingWindow && eventsList.Count > settings.EventMaximum) //Reduces Data volume when too many Events were received { eventsList.RemoveAt(0); //Removes first Element (Sliding window) } else if (settings.useDataReduction && eventsList.Count > settings.EventMaximum) { eventsList = ReduceListData(eventsList); } else if (settings.createFileWhenFull && eventsList.Count > settings.EventMaximum) { STKJsonParser.SaveRunning(); //Saves all current Events and starts again with 0 Events } } else { savedEvents[e.eventName] = new List <STKEvent>(); List <STKEvent> eventsList = (List <STKEvent>)savedEvents[e.eventName]; eventsList.Add(e); savedEvents[e.eventName] = eventsList; } }
public static float GetLastTimestampOfCurrentStage() { foreach (GameObject g in trackedObjects) // Goes through events with Eventsenders and finds their respective events in the JSON file { if (g != null && g.GetComponent <STKEventSender>() != null && g.GetComponent <STKEventSender>().eventBase != null) { STKEventSender[] senders = g.GetComponents <STKEventSender>(); g.SetActive(false); foreach (STKEventSender s in senders) { STKEvent eventBase = s.eventBase; JSONNode currentEvent = parsedJson; JSONNode events = parsedJson[("Stage" + stage.ToString())][eventBase.eventName]; if (events != null) { string timestamp = events[events.Count - 1]["time"]; if (timestamp != null) { return(float.Parse(timestamp)); } } } } } return(0); }
public static float GoToNextPoint(float currentTime) { foreach (GameObject g in trackedObjects) // Goes through events with Eventsenders and finds their respective events in the JSON file { if (g != null && g.GetComponent <STKEventSender>() != null && g.GetComponent <STKEventSender>().eventBase != null) { if (g.activeSelf == false) { g.SetActive(true); MonoBehaviour[] components = g.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour c in components) { c.enabled = false; } Rigidbody[] rigidbodies = g.GetComponents <Rigidbody>(); foreach (Rigidbody r in rigidbodies) { r.isKinematic = true; } } STKEventSender[] senders = g.GetComponents <STKEventSender>(); g.SetActive(false); foreach (STKEventSender s in senders) { STKEvent eventBase = s.eventBase; JSONNode currentEvent = parsedJson; JSONNode events = parsedJson[("Stage" + stage.ToString())][eventBase.eventName]; if (events != null) { string newFrameTime = "0"; for (int i = 0; i < events.Count; i++) { if (float.Parse(events[i]["time"]) > currentTime) { currentEvent = events[i]; newFrameTime = events[i]["time"]; break; } } foreach (EventParameter param in eventBase.parameters) { Component component = s.GetComponentFromParameter(param.name); string name = s.GetVariableNameFromEventVariable(param.name); if (name != null && name != "") { SetVariable(currentEvent[param.name], name, component, g); } } return(float.Parse(newFrameTime)); } } } } return(0.0f); }
public void Deploy() { if (trackedComponents != null) //Get Values if this is a tracker { for (int i = 0; i < trackedComponents.Length; i++) { for (int j = 0; j < trackedVariableNames.array[i].array.Length; j++) { if (trackedComponents[i].GetType().GetProperty(trackedVariableNames.array[i].array[j]) != null) { eventToSend.SetValue(eventVariableNames.array[i].array[j], trackedComponents[i].GetType().GetProperty(trackedVariableNames.array[i].array[j]).GetValue(trackedComponents[i])); } else if (trackedComponents[i].GetType().GetField(trackedVariableNames.array[i].array[j]) != null) { eventToSend.SetValue(eventVariableNames.array[i].array[j], trackedComponents[i].GetType().GetField(trackedVariableNames.array[i].array[j]).GetValue(trackedComponents[i])); } } } } eventToSend.time = STKTestStage.GetTime(); STKEventReceiver.ReceiveEvent(eventToSend); eventToSend = Instantiate(eventBase); }
private void CreateEvent() { //Create Event itself STKEvent newEvent = (STKEvent)ScriptableObject.CreateInstance("STKEvent"); newEvent.eventName = trackedObject.gameObject.name + trackedObject.gameObject.GetInstanceID().ToString(); int numberOfProperties = 0; int numberOfFields = 0; List <string> savedNames = new List <string>(); for (int i = 0; i < trackedObject.GetComponents(typeof(Component)).Length; i++) { Component c = trackedObject.GetComponents(typeof(Component))[i]; //Cycle through variables if (trackedComponents[i] == true) { for (int j = 0; j < c.GetType().GetProperties().Length; j++) { if (trackedVariables[i][j]) { savedNames.Add(string.Join("", new string[] { c.GetType().GetProperties()[j].Name, "_", c.GetType().Name })); numberOfProperties++; } } for (int j = c.GetType().GetProperties().Length; j < c.GetType().GetFields().Length + c.GetType().GetProperties().Length; j++) { if (trackedVariables[i][j]) { savedNames.Add(string.Join("", new string[] { c.GetType().GetFields()[j - c.GetType().GetProperties().Length].Name, "_", c.GetType().Name })); numberOfFields++; } } } } try { STKTrackedObjects g = GameObject.Find("STKTrackedObjects").GetComponent <STKTrackedObjects>(); Undo.RegisterCompleteObjectUndo(g, "Added to tracked objects"); Undo.FlushUndoRecordObjects(); g.trackedObjects.Add(trackedObject); EditorUtility.SetDirty(g); } catch (NullReferenceException e) { Debug.LogError("The STKTrackedObjects GameObject was not found in the scene. Please add it to the scene from the prefabs folder."); } //Attach Eventsender STKEventSender s = trackedObject.AddComponent <STKEventSender>(); s.eventBase = newEvent; s.SetTrackedVar(trackedComponents, trackedVariables, savedNames); AssetDatabase.CreateAsset(newEvent, "Assets/VRScientificToolkit/Events/Track" + trackedObject.gameObject.name + trackedObject.gameObject.GetInstanceID().ToString() + ".asset"); Undo.RecordObject(newEvent, "Created Event"); AssetDatabase.Refresh(); s.eventBase = (STKEvent)AssetDatabase.LoadAssetAtPath("Assets/VRScientificToolkit/Events/Track" + trackedObject.gameObject.name + trackedObject.gameObject.GetInstanceID().ToString() + ".asset", typeof(STKEvent)); AssetDatabase.SaveAssets(); }
private void Start() { timeToSend = interval; eventToSend = Instantiate(eventBase); }