コード例 #1
0
    // 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;
    }
コード例 #2
0
    // 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;
    }