Exemple #1
0
    // ********************************************************************** //
    

 void SavePlanet() 

    {
        // Take a screenshot of this new planet and save it to file
        string planetName = PlanetIDGenerator(5); 


            planetPath = filePath + planetName + ".jpg";
        
 recorder.CaptureScreenshot(planetName);

        Debug.Log("Saving image to .jpg file and details to .json file."); 



        // Add all the details about this random planet to the stimulus set .json file

            planetData = CurrentPlanetSettings(planetName); 


        // Add new planet to the List of all existing planets (could be 100k objects in this list, so beware performance HRS)

        allExistingPlanets.allPlanetData.Add(planetData); 



        // convert the data to JSON format

            dataAsJson = JsonUtility.ToJson(allExistingPlanets); 
 Debug.Log(recordFilePath);

        File.WriteAllText(recordFilePath, dataAsJson);

        

    }
 // ********************************************************************** //

    string PlanetIDGenerator(int ndigits=5) 
    {
        // Create a random code of N digits in length
        int code = rnd.Next(0, (int)Math.Pow(10, ndigits-1));          // This will specify a subject-unique (probably) confirmation code for them to enter after finishing experiment to show completion
        string IDcode = code.ToString();

        while (IDcode.Length < 7)       // pad the code string with zeros until its 7 digits
        {
            IDcode = "0" + IDcode;
        }

        // convert the planet ID number to real planet information code
        string planetName = "planet";
        planetName = planetName + "_" + IDcode + "_" + GetDateTime();

        return planetName;
    }

    // ********************************************************************** //

    void SavePlanet() 
    {
     // Take a screenshot of this new planet and save it to file
     string planetName = PlanetIDGenerator(5);
        planetPath = filePath + planetName + ".jpg";
        recorder.CaptureScreenshot(planetName);
     Debug.Log("Saving image to .jpg file and details to .json file.");

        // Add all the details about this random planet to the stimulus set .json file
        planetData = CurrentPlanetSettings(planetName);

     // Add new planet to the List of all existing planets (could be 100k objects in this list, so beware performance HRS)
        allExistingPlanets.allPlanetData.Add(planetData);

        // convert the data to JSON format
        dataAsJson = JsonUtility.ToJson(allExistingPlanets);

        File.WriteAllText(recordFilePath, dataAsJson);
     
    }

    // ********************************************************************** //

    string GetDateTime() 
    {
        DateTime dateTime = DateTime.Now;
    
        string stringDateTime = dateTime.ToString("dd-MM-yy", DateTimeFormatInfo.InvariantInfo) + '_' + dateTime.ToString("T", DateTimeFormatInfo.InvariantInfo);
        stringDateTime = stringDateTime.Replace("/", "-");   // make sure you don't have conflicting characters for writing to web server
        stringDateTime = stringDateTime.Replace(":", "-");   

        return stringDateTime;
    }

    // ********************************************************************** //

    public void LoadExistingPlanets(string filepath)
    {
        // may need to write an exception case here HRS
        string json = File.ReadAllText(filepath);
        allExistingPlanets = JsonUtility.FromJson<AllPlanetData>(json);

        Debug.Log("Just loaded data from " + allExistingPlanets.allPlanetData.Count + " generated planets.");
    }

    // ********************************************************************** //

    public PlanetData CurrentPlanetSettings(string planetName) 
    {
        // This function generates local variable copies of the settings that we want to save for this planet

        planetData = new PlanetData();              // new to create a new object to store this planet's parameters