public void SelectFolder()
        {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
            string   current  = (string)inputField.GetContents();
            string[] selected = SFB.StandaloneFileBrowser.OpenFolderPanel("Select data directory", current, false);
            if (selected != null && selected.Length > 0)
            {
                inputField.SetContents(selected[0]);
            }
#else
            Debug.LogError("Cannot select directory unless on PC platform!");
#endif
        }
Ejemplo n.º 2
0
        IEnumerator TryBeginSessionFromUISequence()
        {
            bool error = false;

            // EXPERIMENT NAME
            string newExperimentName;

            switch (settingsMode)
            {
            case SettingsMode.AcquireFromUI:
                newExperimentName = settingsElement
                                    .GetContents()
                                    .ToString()
                                    .Replace(".json", "");
                break;

            case SettingsMode.DownloadFromURL:
            case SettingsMode.Empty:
                newExperimentName = experimentName;
                break;

            default:
                throw new Exception();
            }

            // DATA PATH
            if (RequiresFilePathElement)
            {
                if (!localFilePathElement.gameObject.activeSelf)
                {
                    Debug.LogError("Cannot start session - need Local Data Directory element, but it is not active.");
                    yield break;
                }

                string localFilePath = (string)localFilePathElement.GetContents();
                if (localFilePath.Trim() == string.Empty)
                {
                    localFilePathElement.DisplayFault();
                    Debug.LogError("Local data directory is empty");
                    error = true;
                }
                else if (!Directory.Exists(localFilePath))
                {
                    localFilePathElement.DisplayFault();
                    Debug.LogErrorFormat("Cannot start session - local data directory {0} does not exist.", localFilePath);
                    error = true;
                }

                foreach (var dh in ActiveLocalFileDataHandlers)
                {
                    dh.storagePath = localFilePath;
                }
            }

            // PPID & SESSION NUM
            string newPpid    = "";
            int    sessionNum = 1;

            switch (ppidMode)
            {
            case PPIDMode.AcquireFromUI:
                newPpid = ppidElement
                          .GetContents()
                          .ToString()
                          .Trim();
                if (newPpid == string.Empty)
                {
                    ppidElement.DisplayFault();
                    error = true;
                }
                if (sessionNumMode == SessionNumMode.AcquireFromUI)
                {
                    int newSessionNum = Convert.ToInt32(sessionNumElement.GetContents());
                    if (newSessionNum <= 0)
                    {
                        sessionNumElement.DisplayFault();
                        error = true;
                    }
                    else
                    {
                        sessionNum = newSessionNum;
                    }
                }
                break;

            case PPIDMode.GenerateUnique:
                newPpid = GenerateUniquePPID();
                break;

            default:
                throw new Exception();
            }

            // PARTICIPANT DETAILS
            Dictionary <string, object> newParticipantDetails;
            var  validityList = SidebarStateIsValid(out newParticipantDetails);
            bool sidebarValid = true;

            foreach (var v in validityList)
            {
                sidebarValid = sidebarValid && v.valid;
                if (!v.valid && v.entry.element != null)
                {
                    v.entry.element.DisplayFault();
                }
            }
            if (!sidebarValid)
            {
                error = true;
            }

            // TERMS AND CONDITIONS
            bool acceptedTsAndCs = (bool)tsAndCsToggle.GetContents();

            if (!acceptedTsAndCs)
            {
                tsAndCsToggle.DisplayFault();
                error = true;
            }


            // SETTINGS
            Settings newSettings = null;

            switch (settingsMode)
            {
            case SettingsMode.AcquireFromUI:
                string settingsPath = Path.Combine(Application.streamingAssetsPath, settingsElement.GetContents().ToString());
                string settingsText;
                try
                {
                    settingsText = File.ReadAllText(settingsPath);
                }
                catch (FileNotFoundException e)
                {
                    Debug.LogException(e);
                    settingsElement.DisplayFault();
                    error = true;
                    break;
                }
                Dictionary <string, object> deserializedJson = (Dictionary <string, object>)MiniJSON.Json.Deserialize(settingsText);
                if (deserializedJson == null)
                {
                    Debug.LogErrorFormat("Cannot deserialize json file: {0}.", settingsPath);
                    settingsElement.DisplayFault();
                    error = true;
                }
                else
                {
                    newSettings = new Settings(deserializedJson);
                }
                break;

            case SettingsMode.DownloadFromURL:
                yield return(GetJsonUrl());

                if (jsonText == string.Empty)
                {
                    error = true;
                    Debug.LogErrorFormat("Error downloading data from URL: {0}. Using blank settings instead.", jsonURL);
                    newSettings = Settings.empty;
                }
                try
                {
                    newSettings = new Settings((Dictionary <string, object>)MiniJSON.Json.Deserialize(jsonText));
                }
                catch (InvalidCastException)
                {
                    error = true;
                    Debug.LogErrorFormat("Text downloaded from {0} is cannot be parsed, empty settings used instead. Check the data is valid json ({1})", jsonURL, jsonText);
                    newSettings = Settings.empty;
                }
                break;

            case SettingsMode.Empty:
                newSettings = Settings.empty;
                break;

            default:
                throw new Exception();
            }

            uiStartRoutine = null;
            if (error)
            {
                yield break;
            }
            gameObject.SetActive(false);

            // BEGIN!
            session.Begin(
                newExperimentName,
                newPpid,
                sessionNum,
                newParticipantDetails,
                newSettings
                );
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function is called when the MonoBehaviour will be destroyed.
        /// </summary>
        void OnDestroy()
        {
            string current = (string)dropdown.GetContents();

            PlayerPrefs.SetString(profileKey, current);
        }