Пример #1
0
 /**
  * This method is called by the dataManager object in the RunExperiment script. It sets the appropriate
  * experiment-level variables specified in the config file. Setting these config fields is necessary
  * so that Unity's JsonUtility class can correctly convert the data to JSON.
  */
 public void SetConfigInfo(ReadConfig.Config config)
 {
     this.subjNum           = config.subjNum;
     this.subjSex           = config.subjSex;
     this.session           = config.session;
     this.group             = config.group;
     this.trialFile         = config.trialFile;
     this.trackHeadPos      = config.trackHeadPos;
     this.showFeedback      = config.showFeedback;
     this.feedbackType      = config.feedbackType;
     this.collectConfidence = config.collectConfidence;
     this.feedbackPos       = config.feedbackPos;
     this.feedbackSize      = config.feedbackSize;
     this.feedbackColor     = config.feedbackColor;
 }
    private GameObject audioSourceObject;      // The object which will play the audio files.


    /**
     * Initializes all trial data once the experiment begins. This includes loading the
     * config file, loading in the trial-information, and setting all experiment-wide variables.
     */
    void Start()
    {
        // Set the target framerate for the application
        Application.targetFrameRate = 90;
        rate = 90.0f;

        // Set the step size for the objects' motion based on the rate
        stepSize = (1.0f / rate);

        // Load the config file
        string configFilepath = Application.dataPath + "/config.json";

        config = GetComponent <ReadConfig>().LoadConfig(configFilepath.Replace("/", "\\"));

        if (config.debugging)
        {
            Debug.Log(configFilepath);
        }

        // Set the feedback display configurations based on the config file
        uiManager.SetFeedbackColor(config.feedbackColor);
        uiManager.SetFeedbackSize(config.feedbackSize);
        if (config.cameraLock)
        {
            uiManager.SetFeedbackPosition(config.feedbackPos[0], config.feedbackPos[1], config.feedbackPos[2], true);
        }
        else
        {
            uiManager.SetFeedbackPosition(config.feedbackPos[0], config.feedbackPos[1], config.feedbackPos[2]);
        }

        // Load the data from the desired input file
        trials = GetComponent <ManageTrials>().LoadTrialData(config.trialFile.Replace("/", "\\"), Time.time);

        // Initialize the TrialData array to be the correct size in the experiment's data manager
        dataManager.InitDataArray(trials.Length, Time.time);

        // Add the config info to the data manager
        dataManager.SetConfigInfo(config);

        // Initialize global variables
        curTrial    = 0;
        isRunning   = false;
        expComplete = false;

        // Set the head position transform to track the participant's movements
        headPos       = GameObject.Find("Camera (eye)").transform;
        controllerPos = GameObject.Find("/CameraManager/[CameraRig]/Controller (right)").transform;
        movingObj     = GameObject.Find("MovingObj");

        // Set the audio source
        audioSourceObject = GameObject.Find("Camera (ears)");

        // Load all audio sources
        for (int i = 0; i < trials.Length; i++)
        {
            ManageTrials.Trial trial = trials[i];

            if (trial.playSound)
            {
                ReadAudioFiles("Assets/Trials/soundFiles/" + trials[i].soundFile);
            }
        }



        // Set up environment.
        if (config.ground)          // Toggle ground visibility.
        {
            ground.SetActive(true); // Make the ground visible.
        }
        else
        {
            ground.SetActive(false); // Toggle off ground visibility.
        }

        if (config.road)                                                                                    // Toggle and set up road.
        {
            road.SetActive(true);                                                                           // Make the ground visible.
            road.transform.position = new Vector3(config.roadPos[0], config.roadPos[1], config.roadPos[2]); // Set position.
        }
        else
        {
            road.SetActive(false); // Toggle off road visibility.
        }
    }