// Called at the first frame when the component is enabled void Start() { // Ensure we only read data if the application is playing // and we have a state file to initialize the engine with if (!Application.isPlaying || initialStateFile == null) { return; } // Allocate PulseEngine with log file path string dateAndTimeVar = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); string logFilePath = Application.persistentDataPath + "/" + gameObject.name + dateAndTimeVar + ".log"; // Set the data_directory for Pulse to find all the data files it expects // This code will derive the data directory based on how this project was // included in the editor. Still investigating how to set data_dir in a package UnityEditor.MonoScript ms = UnityEditor.MonoScript.FromMonoBehaviour(this); string path = UnityEditor.AssetDatabase.GetAssetPath(ms); path = System.IO.Path.GetDirectoryName(path) + "/../Data"; engine = new PulseEngine(logFilePath, path); // Initialize engine state from tje state file content engine.SerializeFromString(initialStateFile.text, null, // requested data currently hardcoded serializationFormat, Time.time); previousTime = Time.time; }
// Called at the first frame when the component is enabled void Start() { // Ensure we only read data if the application is playing // and we have a state file to initialize the engine with if (!Application.isPlaying || initialStateFile == null) { return; } // Allocate PulseEngine with path to logs and needed data files string dateAndTimeVar = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); string logFilePath = Application.persistentDataPath + "/" + gameObject.name + dateAndTimeVar + ".log"; string pulseDataPath = Application.streamingAssetsPath + "/" + engineDataPath; DirectoryInfo directoryInfo = new DirectoryInfo(pulseDataPath); if (!directoryInfo.Exists) { string error = "Data files for " + name + " not found. Expected at " + pulseDataPath + ".\n" + "Make sure you have copied them from the Pulse package inner 'StreamingAssets' folder."; throw new Exception(error); } engine = new PulseEngine(logFilePath, pulseDataPath); SEDataRequestManager data_mgr = new SEDataRequestManager(data_requests); // Initialize engine state from tje state file content engine.SerializeFromString(initialStateFile.text, data_mgr, Time.time, serializationFormat); previousTime = Time.time; }
// Called at the first frame when the component is enabled protected virtual void Start() { // Ensure we only read data if the application is playing // and we have a state file to initialize the engine with if (!Application.isPlaying) { return; } // Allocate PulseEngine with path to logs and needed data files string dateAndTimeVar = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); string logFilePath = Application.persistentDataPath + "/" + gameObject.name + dateAndTimeVar + ".log"; engine = new PulseEngine(); engine.SetLogFilename(logFilePath); SEDataRequestManager data_mgr = new SEDataRequestManager(data_requests); // NOTE, there are other ways to initialize the engine, see here // https://gitlab.kitware.com/physiology/engine/-/blob/3.x/src/csharp/howto/HowTo_EngineUse.cs // Initialize engine state from tje state file content if (initialStateFile != null) { if (!engine.SerializeFromString(initialStateFile.text, data_mgr, serializationFormat)) { Debug.unityLogger.LogError("PulsePhysiologyEngine", "Unable to load state file " + initialStateFile); } } else { // You do not have to use the Editor control if you don't want to, // You could simply specify a file on disk via use of the Streaming Assets folder string state = Application.streamingAssetsPath + "/Pulse/[email protected]"; if (!engine.SerializeFromFile(state, data_mgr)) { Debug.unityLogger.LogError("PulsePhysiologyEngine", "Unable to load state file " + state); } } previousTime = Time.time; }