public static Configuration LoadTaskConfigurationDataFromJSON(string fullJSONFilePathAndName) { //Get the JSON contents from file string contents = getFileContents(fullJSONFilePathAndName); //Create the root task node for parsing JSONNode rootNode = JSONNode.Parse(contents); JSONClass rootClass = rootNode.AsObject; //Validate that the file is at least remotely formatted correctly by checking for the Task property (which contains everything) if (rootClass["Task"] == null) { Debug.LogError("Error: JSON does not include root Task object. See example JSON for help."); Application.Quit(); } JSONClass taskClass = rootClass["Task"].AsObject; //From here on out, individual items in the Task class can be parsed //REQUIRED INPUTS //Construct the interface configuration from the Task JSONClass InterfaceConfiguration interfaceConfig = InterfaceConfiguration.getInterfaceConfigurationFromJSON(taskClass); //Construct the task procedure from the Task JSON Class TaskProcedure taskProc = TaskProcedure.getTaskProcedureFromJSON(taskClass); //Construct the default configuration given the required interface and task procedure inputs Configuration c = new Configuration(interfaceConfig, taskProc); //OPTIONAL INPUTS //Attempt to load GlobalPauseEnabled property if present if (taskClass["GlobalPauseEnabled"] == null) Debug.LogWarning("Warning: No GlobalPauseEnabled property set, defaulting to " + c.GlobalPauseEnabled + " for value."); else c.GlobalPauseEnabled = taskClass["GlobalPauseEnabled"].AsBool; //Attempt to set maximum allowable pause time if (taskClass["MaximumAllowablePauseTime"] == null) Debug.LogWarning("Warning: No MaximumAllowablePauseTime property set, defaulting to " + c.MaximumAllowablePauseTime + " for value."); else c.MaximumAllowablePauseTime = taskClass["MaximumAllowablePauseTime"].AsFloat; //Attempt to load BackgroundColor property if present if (taskClass["BackgroundColor"] == null) Debug.LogWarning("Warning: No BackgroundColor property set, defaulting to " + c.BackgroundColor + " for value."); else c.BackgroundColor = HexToColor(taskClass["BackgroundColor"]); return c; }
// Use this for initialization void Start() { //Setup the logger and notification manager NotificationManager.NotificationObject = FindObjectOfType<NotificationManager>().gameObject; log = FindObjectOfType<DataLogger>(); DataLogger.Log = log; Camera.main.orthographicSize = Screen.height / 2; //Load the JSON file which contains the task state machine and controller configuration if (PlayerPrefs.HasKey(conditionConfigurationFilenamePlayerPrefsString)) config = JSONDataLoader.JSONDataLoader.LoadTaskConfigurationDataFromJSON(Application.persistentDataPath + "/" + PlayerPrefs.GetString(conditionConfigurationFilenamePlayerPrefsString)); else config = JSONDataLoader.JSONDataLoader.LoadTaskConfigurationDataFromJSON(Application.persistentDataPath + "/" + fallBackFilename); ///GLOBAL CONFIG /// globalPauseInEffect = false; prevGlobalPauseKeyState = false; Camera.main.backgroundColor = config.BackgroundColor; /// //Create a controller interface using the controller configuration from the JSON controller = new ThreePhaseController(config.Interfaces); controller.SetConfig(config); log.LogConfig("Participant ID: " + PlayerPrefs.GetString("participantID")); log.LogConfig("Researcher Holding Baby: " + PlayerPrefs.GetString("researcherHoldingBaby")); log.LogConfig("Researcher Running Computer: " + PlayerPrefs.GetString("researcherRunningComputer")); log.LogConfig("Researcher Second Coder: " + PlayerPrefs.GetString("researcherSecondCoder")); log.LogConfig("Current Date: " + PlayerPrefs.GetString("currentDate")); log.LogConfig("Current Time: " + PlayerPrefs.GetString("currentTime")); log.LogConfig("Baby Birth Date: " + PlayerPrefs.GetString("babyBirthDate")); log.LogConfig("Baby Birth Time: " + PlayerPrefs.GetString("babyBirthTime")); log.LogConfig("Age: " + PlayerPrefs.GetString("age")); log.LogConfig("Gender: " + PlayerPrefs.GetString("gender")); log.LogConfig("Condition Configuration Filename: " + PlayerPrefs.GetString("conditionConfigurationFilename")); log.LogConfig("Place Number: " + PlayerPrefs.GetInt("placeNumber")); log.LogConfig("Controller Configuration"); log.LogConfig("Keyboard Enabled=" + config.Interfaces.KeyboardInterfacePresent); log.LogConfig("Keyboard Keys=" + String.Join(",", config.Interfaces.KeyboardKeys)); log.LogConfig("Keyboard Commands=" + String.Join(",", config.Interfaces.KeyboardCommands)); log.LogConfig("XBox Controller Enabled=" + config.Interfaces.XBoxControllerInterfacePresent); log.LogConfig("XBox Controller Keys=" + String.Join(",", config.Interfaces.XBoxControllerKeys)); log.LogConfig("XBox Controller Commands=" + String.Join(",", config.Interfaces.XBoxControllerCommands)); log.LogConfig("TCP Enabled=" + config.Interfaces.TcpInterfacePresent); log.LogConfig("TCP Keys=" + String.Join(",", config.Interfaces.TcpKeys)); log.LogConfig("TCP Commands=" + String.Join(",", config.Interfaces.TcpCommands)); log.LogConfig("TCP Port=" + config.Interfaces.TcpPort); string masterInterfaceString = "No Master Interface Set"; if (config.Interfaces.MasterInterface == InterfaceConfiguration.InterfaceType.Keyboard) masterInterfaceString = "Keyboard"; else if (config.Interfaces.MasterInterface == InterfaceConfiguration.InterfaceType.XBoxController) masterInterfaceString = "XBoxController"; else if (config.Interfaces.MasterInterface == InterfaceConfiguration.InterfaceType.TCP) masterInterfaceString = "TCP"; log.LogConfig("Master Interface: " + masterInterfaceString); log.LogConfig("Global Pause is " + (config.GlobalPauseEnabled?"Enabled":"Disabled")); log.LogConfig("Global Pause Maximum Timeout: " + config.MaximumAllowablePauseTime); log.LogConfig("Background Color: " + config.BackgroundColor.ToString()); log.LogConfig("There are " + config.TaskProcedure.Tasks.Count + " states in this task procedure."); Debug.Log("Beginning Task"); log.LogState("Finished loading configuration, beginning task..."); //Begin the task config.TaskProcedure.startFromBeginning(); if (PlayerPrefs.HasKey(placeNumberPlayerPrefsString)) { int startIndex = PlayerPrefs.GetInt(placeNumberPlayerPrefsString); if (!(startIndex < 0 || startIndex > config.TaskProcedure.Tasks.Count)) config.TaskProcedure.setTask(startIndex); } }