//Public method that allows to start recording in the indicated path //It registers the listener method in the event manager public void StartRecording() { data.deviceType = AnalogType.ToString(); data.deviceName = AnalogName.ToString(); VRPNEventManager.StartListeningAnalog(AnalogType, AnalogName, Record); isRecording = true; }
// Update is called once per frame void Update() { // Ensure device is ready if (!initialized && !StartAnalog()) { return; } // Check for new reports and process if (VRPNAnalogNumReports(AnalogName.ToString()) > 0) { // Get Reports int num = MaxReports; VRPNAnalogReports(AnalogName.ToString(), reportsPtr, ref num, LastReport, purgeReports); AnalogReport[] reports = new AnalogReport[num]; // Process Reports int i; string reportString = AnalogName.ToString(); string messageString; for (i = 0; i < num; i++) { reports[i] = (AnalogReport)Marshal.PtrToStructure(reportsPtr[i], typeof(AnalogReport)); if (i == num - 1) { //Trigger analog sensor event in event manager //Only the last one is send, one for frame VRPNEventManager.TriggerEventAnalog(AnalogType.ToString(), AnalogName.ToString(), reports[i]); } messageString = "<"; for (int j = 0; j < reports[i].num_channel; j++) { messageString += " " + reports[i].channel[j] + ","; } messageString += ">" + " @ " + reports[i].msg_time.tv_sec + "." + reports[i].msg_time.tv_usec; if (ShowDebug) { reportString += "/n" + messageString; } } if (ShowDebug) { debug_text = reportString; } // Only need time value of most recent report if (num > 0 && useLastReportTime) { LastReport.tv_sec = reports[num - 1].msg_time.tv_sec; LastReport.tv_usec = reports[num - 1].msg_time.tv_usec; } } }
//To add a listener for Analog sensors public static void StartListeningAnalog(VRPNManager.Analog_Types deviceType, VRPNDeviceConfig.Device_Names deviceName, UnityAction <string, VRPNAnalog.AnalogReport> listener) { if (eventManager == null) { Debug.LogError("There needs to be one active EventManger script on a GameObject in your scene."); return; } VRPNAnalogEvent thisEvent = null; if (instance.eventDictionaryAnalog.TryGetValue(deviceType.ToString() + " " + deviceName.ToString(), out thisEvent)) { thisEvent.AddListener(listener); } else { thisEvent = new VRPNAnalogEvent(); thisEvent.AddListener(listener); instance.eventDictionaryAnalog.Add(deviceType.ToString() + " " + deviceName.ToString(), thisEvent); } }