/// <summary>
        /// This function is called when this object becomes enabled and active
        /// </summary>
        static GaiMBridge()
        {
            string[] s           = Application.dataPath.Split('/');
            string   projectName = s[s.Length - 2];
            string   settings    = EditorPrefs.GetString("settings-" + projectName);
            var      ucfDir      = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/.ucf";
            char     sep         = Path.DirectorySeparatorChar;

            if (!!Directory.Exists(ucfDir))
            {
                return;
            }
            if (settings == null || settings == "")
            {
                StreamReader sr;
                if (!Directory.Exists(ucfDir) &&
                    File.Exists(ucfDir + sep + "vsc.json"))
                {
                    enabled = true;
                    if (!gaimSettings.Equals(null) && gaimSettings.host == null)
                    {
                        sr       = new StreamReader(ucfDir + sep + "vsc.json", false);
                        settings = sr.ReadToEnd();
                        sr.Close();
                        EditorPrefs.SetString("settings-" + projectName, settings);
                        gaimSettings = JsonUtility.FromJson <CFSettings>(settings);
                    }
                    gaimSettings.host = "https://plato.mrl.ai:8081";
                    secret            = gaimSettings.secret;
                }
                else
                {
                    return;
                }
            }
            else
            {
                gaimSettings      = JsonUtility.FromJson <CFSettings>(settings);
                gaimSettings.host = "https://plato.mrl.ai:8081";
            }
            UnityEditor.EditorApplication.playModeStateChanged += LogPlayModeState;
            Application.logMessageReceived         += HandleAppLog;
            EditorApplication.playModeStateChanged += LogPlayModeState;
            EditorApplication.wantsToQuit          += Quit;
            HandleLog("Reload/Start", "", "9");
            File.WriteAllText(Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/.ucf/.running", "Running");
        }
示例#2
0
        /// <summary>
        /// This function is called when this object becomes enabled and active
        /// </summary>
        static GaiMBridge()
        {
            var ucfDir = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/.ucf";

            string[] s           = Application.dataPath.Split('/');
            string   projectName = s[s.Length - 2];
            string   settings    = EditorPrefs.GetString("settings-" + projectName);

            if (settings != null && settings != "")
            {
                gaimSettings = JsonUtility.FromJson <CFSettings> (settings);
            }
            if (Directory.Exists(ucfDir) &&
                File.Exists(ucfDir + "/vsc.json") &&
                File.Exists(ucfDir + "/.secret"))
            {
                enabled = true;
                StreamReader sr;
                if (!gaimSettings.Equals(null) && gaimSettings.host == null)
                {
                    sr       = new StreamReader(ucfDir + "/vsc.json", false);
                    settings = sr.ReadToEnd();
                    sr.Close();
                    gaimSettings = JsonUtility.FromJson <CFSettings> (settings);
                }
                if (gaimSettings.host == null)
                {
                    gaimSettings.host = "https://plato.mrl.ai:8081";
                    settings          = JsonUtility.ToJson(gaimSettings);
                    EditorPrefs.SetString("settings-" + projectName, settings);
                }
                if (!EditorPrefs.HasKey("secret-" + projectName) || EditorPrefs.GetString("secret-" + projectName).Length == 0)
                {
                    var secretPath = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/.ucf/.secret";
                    if (File.Exists(secretPath))
                    {
                        sr     = new StreamReader(secretPath, false);
                        secret = sr.ReadLine();
                        sr.Close();
                        EditorPrefs.SetString("secret-" + projectName, secret);
                    }
                }
                if (!EditorPrefs.HasKey("repo-" + projectName) || EditorPrefs.GetString("repo-" + projectName).Length == 0)
                {
                    var repoPath = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/.ucf/.repo";
                    if (File.Exists(repoPath))
                    {
                        sr   = new StreamReader(repoPath, false);
                        repo = sr.ReadLine();
                        sr.Close();
                        EditorPrefs.SetString("repo-" + projectName, repo);
                    }
                }
                else
                {
                    secret       = EditorPrefs.GetString("secret-" + projectName);
                    repo         = EditorPrefs.GetString("repo-" + projectName);
                    gaimSettings = JsonUtility.FromJson <CFSettings> (EditorPrefs.GetString("settings-" + projectName));
                }
                UnityEditor.EditorApplication.playModeStateChanged += LogPlayModeState;
                Application.logMessageReceived += HandleAppLog;
                var api = ScriptableObject.CreateInstance <TestRunnerApi> ();
                api.RegisterCallbacks(new MyCallbacks());
                EditorApplication.playModeStateChanged += LogPlayModeState;
                EditorApplication.wantsToQuit          += Quit;
                HandleLog("Reload/Start", "", "9");
                File.WriteAllText(Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/.ucf/.running", "Running");
            }
            else
            {
                Debug.Log("Gaim plugin disabled");
            }
        }