Exemplo n.º 1
0
        static void   DefineByCreation()
        {
            var answeredNo = EditorPrefs.GetBool(noCreationKey, false);

            if (answeredNo)
            {
                return;
            }

            const string title = "TwiceBetter Helpers";

            if (!EditorUtility.DisplayDialog(title, "No Helpers Settings found for current user, create?", "Yes", "No"))
            {
                EditorPrefs.SetBool(noCreationKey, true);
                EditorUtility.DisplayDialog(title, "You can create settings by selecting Window/Twice Better/Helpers/Settings", "OK");
                return;
            }

            settings = ScriptableObject.CreateInstance <TBH_Settings>();
            settings.FillDefaults(SystemInfo.operatingSystemFamily, System.Environment.UserName);
            var path = "Assets/" + SettingsAssetName() + ".asset";

            AssetDatabase.CreateAsset(settings, path);
            EditorPrefs.SetString(lastSettingsPathKey, path);
        }
Exemplo n.º 2
0
        static void   DefineBySearching()
        {
            var existingPaths     = AssetDatabase.FindAssets("t:" + nameof(TBH_Settings));
            var settingsAssetName = SettingsAssetName();

            if (existingPaths.Length == 0)
            {
                existingPaths = AssetDatabase.FindAssets(settingsAssetName);
            }
            var match = $"/{settingsAssetName}.asset";

            for (int i = 0; i < existingPaths.Length; i++)
            {
                var existingPath = AssetDatabase.GUIDToAssetPath(existingPaths[i]);
                if (match.Equals(existingPath.Substring(existingPath.Length - match.Length)))
                {
                    settings = AssetDatabase.LoadAssetAtPath <TBH_Settings>(existingPath);
                    if (settings != null)
                    {
                        EditorPrefs.SetString(lastSettingsPathKey, existingPath);
                    }
                    return;
                }
            }
        }
Exemplo n.º 3
0
        public static void Initialize()
        {
            TBH_Settings settings = TBH_Settings.Get();

            if (settings == null)
            {
                return;
            }
            if (!settings.enabled)
            {
                if (initialized)
                {
                    TBH_Refresher.Shutdown();
                    TBH_Hotkeys.Shutdown();
                    initialized = false;
                }
                return;
            }

            // Refresher
            TBH_Refresher.Initialize(ref settings.refresher);

            // Yaml Merge Registrator
            if (settings.registerYamlMerge)
            {
                TBH_YamlMergeRegistrator.Register();
            }

            // Hotkeys
            TBH_Hotkeys.Initialize(ref settings.hotkeys);

            initialized = true;
        }
Exemplo n.º 4
0
        static async void DelayedInit()
        {
            EditorApplication.update -= DelayedInit;
            await Task.Delay(200);

            TBH_Settings.Define();
            Initialize();
        }
Exemplo n.º 5
0
        public static void   Define()
        {
            settings = null;

            var lastSettingsPath = EditorPrefs.GetString(lastSettingsPathKey, null);

            settings = AssetDatabase.LoadAssetAtPath <TBH_Settings>(lastSettingsPath);

            if (settings == null)
            {
                DefineBySearching();
            }

            if (settings == null)
            {
                DefineByCreation();
            }
        }