// 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);
        }
    }