void FixedUpdate()
    {
        //OVRInput.FixedUpdate();
        //leftTriggerValue = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.LTouch);
        //rightTriggerValue = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.RTouch);

        totalValue = Mathf.Clamp(leftTriggerValue + rightTriggerValue, 0f, MAX_VALUE);

        if (valueVisualizer != null)
        {
            valueVisualizer.value = totalValue;
            if (totalValue < (lowerThreshold * MAX_VALUE))
            {
                fillImage.color = colorLow;
            }
            else if (totalValue < (upperThreshold * MAX_VALUE))
            {
                fillImage.color = colorMid;
            }
            else
            {
                fillImage.color = colorHigh;
            }
        }

        if (ExciteOMeterManager.currentlyRecordingSession)
        {
            // Timer control
            elapsedTime += Time.deltaTime;

            // Send data each "sendingPeriod"
            if (elapsedTime >= sendingPeriod)
            {
                // Reset timer for next event
                elapsedTime = 0.0f;

                logIsWriting = LoggerController.instance.WriteLine(logToWrite,
                                                                   ExciteOMeterManager.GetTimestampString() + "," +
                                                                   leftTriggerValue.ToString("F3") + "," +
                                                                   rightTriggerValue.ToString("F3") + "," +
                                                                   totalValue.ToString("F3")
                                                                   );

                if (!logIsWriting)
                {
                    Debug.LogWarning("Error writing movement data. Please setup LoggerController with a file with LogID is" + logToWrite.ToString());
                }
            }
        }
    }
        // ====================================================================================================
        #region Sessions Disk & Menu

        void GetSessionDataFromDisk()
        {
            mainLogFolder   = SettingsManager.Values.logSettings.mainLogFolder;
            sessionFilename = SettingsManager.Values.logSettings.sessionJsonFilename;
            // Folders with available sessions
            string[] dirs = Directory.GetDirectories(mainLogFolder);

            // Temp variables for string processing
            int    rootLength = mainLogFolder.Length;
            string dirName    = ""; // Variable to store the dirname without full path.

            string[] dirNameParts;  // Separate between date and sessionId
            string[] sessionFiles;

            // Copy predefined sessioncolor options
            sessionColors.AddRange(VisualStyle.SessionsColorTable);
            int sessionCounter = -1;

            foreach (string dir in dirs)
            {
                // Extract folder name without whole path
                dirName = dir.Substring(rootLength);

                // Check if the folder has a valid file with a sessionFilename
                sessionFiles = Directory.GetFiles(dir, sessionFilename, SearchOption.TopDirectoryOnly);

                if (sessionFiles.Length == 1) // There should be only one session file per folder
                {
                    // Process the folder
                    dirNameParts = dirName.Split('_');

                    // Every session data gets a unique key
                    sessionCounter++;

                    // Make a session and define a color for it
                    int         sessionColorIndex = UnityEngine.Random.Range(0, sessionColors.Count);
                    SessionData newSession        = new SessionData(sessionColors[sessionColorIndex], sessionCounter);
                    sessionColors.RemoveAt(sessionColorIndex);
                    if (sessionColors.Count == 0)
                    {
                        sessionColors.AddRange(VisualStyle.SessionsColorTable);
                    }

                    // Add folder info
                    SessionFolder newSessionFolder = new SessionFolder();
                    newSessionFolder.sessionFilepath = sessionFiles[0];         // Full path to json file
                    newSessionFolder.folderPath      = dir;                     // Full path to session folder
                    newSessionFolder.datetime        = DateTime.ParseExact(dirNameParts[0], ExciteOMeterManager.GetFormatTimestampDateTime(), System.Globalization.CultureInfo.InvariantCulture);
                    newSessionFolder.sessionId       = dirName.Substring(dirNameParts[0].Length + 1);
                    newSession.sessionFolder         = newSessionFolder;

                    // Add to list of sessions
                    sessions.Add(newSession);
                }
                else
                {
                    // Move to the next folder and avoid processing this folder
                    Debug.Log("Skipping folder " + dirName + " because session filename " + sessionFilename + " was not found.");
                }
            }
        }
Ejemplo n.º 3
0
    public string CaptureScreenshot()
    {
        // Screenshot recorder has not been setup
        if (!isScreenRecorderSetup)
        {
            Debug.LogError("ScreenRecorder needs to be setup");
            return(null);
        }

        // create screenshot objects if needed
        if (renderTexture == null)
        {
            // creates off-screen render texture that can rendered into
            rect          = new Rect(0, 0, captureWidth, captureHeight);
            renderTexture = new RenderTexture(captureWidth, captureHeight, 24);
            screenShot    = new Texture2D(captureWidth, captureHeight, TextureFormat.RGB24, false);
        }

        // get main camera and manually render scene into rt
        recordingCamera.targetTexture = renderTexture;
        recordingCamera.Render();

        // read pixels will read from the currently active render texture so make our offscreen
        // render texture active and then read the pixels
        RenderTexture.active = renderTexture;
        screenShot.ReadPixels(rect, 0, 0);

        // reset active camera texture and render texture
        recordingCamera.targetTexture = null;
        RenderTexture.active          = null;

        // get our unique filename
        string filename = uniqueFilename((int)rect.width, (int)rect.height);

        // pull in our file header/data bytes for the specified image format (has to be done from main thread)
        byte[] fileHeader = null;
        byte[] fileData   = null;
        if (format == Format.RAW)
        {
            fileData = screenShot.GetRawTextureData();
        }
        else if (format == Format.PNG)
        {
            fileData = screenShot.EncodeToPNG();
        }
        else if (format == Format.JPG)
        {
            fileData = screenShot.EncodeToJPG();
        }
        else         // ppm
        {
            // create a file header for ppm formatted file
            string headerStr = string.Format("P6\n{0} {1}\n255\n", rect.width, rect.height);
            fileHeader = System.Text.Encoding.ASCII.GetBytes(headerStr);
            fileData   = screenShot.GetRawTextureData();
        }

        // create new thread to save the image to file (only operation that can be done in background)
        new System.Threading.Thread(() =>
        {
            // create file and write optional header with image bytes
            var f = System.IO.File.Create(filename);
            if (fileHeader != null)
            {
                f.Write(fileHeader, 0, fileHeader.Length);
            }
            f.Write(fileData, 0, fileData.Length);
            f.Close();
            ExciteOMeterManager.DebugLog(string.Format("Wrote screenshot {0} of size {1}", filename, fileData.Length));
        }).Start();


        // cleanup if needed
        if (optimizeForManyScreenshots == false)
        {
            Destroy(renderTexture);
            renderTexture = null;
            screenShot    = null;
        }

        return(last_screenshot_filename);
    }