Пример #1
0
        public static BetterPrefs GetEditorInstance()
        {
            if (instance == null || !AssetDatabase.Contains(instance))
            {
                var dirs      = Directory.GetDirectories("Assets", "Vexe", SearchOption.AllDirectories);
                var editorDir = dirs.FirstOrDefault(x => Directory.GetParent(x).Name == "Editor");
                var prefsDir  = Path.Combine(editorDir, "ScriptableAssets");
                if (editorDir == null || !Directory.Exists(prefsDir))
                {
                    Debug.LogError("Unable to create editor prefs asset at Editor/Vexe/ScriptableAssets (couldn't find folder). Please make sure that path exists 'somewhere' in your project");
                    return(instance != null ? instance : instance = CreateInstance <BetterPrefs>());
                }

                var path = Path.Combine(prefsDir, "BetterEditorPrefs.asset");
                //instance = AssetDatabase.LoadAssetAtPath<BetterPrefs>(path);
                AssetDatabase.LoadAssetAtPath(path, typeof(BetterPrefs));
                if (instance == null)
                {
                    instance = ScriptableObject.CreateInstance <BetterPrefs>();
                    AssetDatabase.CreateAsset(instance, path);
                    AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
                    AssetDatabase.Refresh();
                }
            }

            if (instance.Ints == null)
            {
                instance.Ints = new LookupIntInt();
            }
            if (instance.Strings == null)
            {
                instance.Strings = new LookupIntString();
            }
            if (instance.Floats == null)
            {
                instance.Floats = new LookupIntFloat();
            }
            if (instance.Bools == null)
            {
                instance.Bools = new LookupIntBool();
            }
            if (instance.Colors == null)
            {
                instance.Colors = new LookupIntColor();
            }
            if (instance.Vector3s == null)
            {
                instance.Vector3s = new LookupIntVector3();
            }

            return(instance);
        }
Пример #2
0
            static void ResolveTick()
            {
                if (!BetterPrefs.GetEditorInstance().Bools.ValueOrDefault(kReqAuto))
                {
                    return;
                }

                if (EditorApplication.timeSinceStartup > nextTime)
                {
                    Requirements.ResolveScene();
                    nextTime = EditorApplication.timeSinceStartup + ResolveInterval;
                }
            }
Пример #3
0
 public static BetterPrefs GetEditorInstance()
 {
     if (editorInstance == null)
     {
         editorInstance = AssetDatabase.LoadAssetAtPath(EditorPrefsPath, typeof(BetterPrefs)) as BetterPrefs;
         if (editorInstance == null)
         {
             editorInstance = ScriptableObject.CreateInstance <BetterPrefs>();
             AssetDatabase.CreateAsset(editorInstance, EditorPrefsPath);
             AssetDatabase.ImportAsset(EditorPrefsPath, ImportAssetOptions.ForceUpdate);
         }
     }
     return(editorInstance);
 }
Пример #4
0
        public static BetterPrefs GetEditorInstance()
        {
            if (editorInstance == null)
            {
                editorInstance = AssetDatabase.LoadAssetAtPath(EditorPrefsPath, typeof(BetterPrefs)) as BetterPrefs;
                if (editorInstance == null)
                {
                    editorInstance = ScriptableObject.CreateInstance <BetterPrefs>();
                    AssetDatabase.CreateAsset(editorInstance, EditorPrefsPath);
                    AssetDatabase.ImportAsset(EditorPrefsPath, ImportAssetOptions.ForceUpdate);
                }
            }

            AssignIfNull(ref editorInstance.Ints);
            AssignIfNull(ref editorInstance.Strings);
            AssignIfNull(ref editorInstance.Floats);
            AssignIfNull(ref editorInstance.Bools);
            AssignIfNull(ref editorInstance.Colors);
            AssignIfNull(ref editorInstance.Vector3s);

            return(editorInstance);
        }
Пример #5
0
        public static BetterPrefs GetEditorInstance()
        {
            if (instance == null)
            {
                // First attempt is to find the pref instance anywhere in the AssetDatabase
                var prefPath = AssetDatabase.FindAssets("t:BetterPrefs BetterEditorPrefs").Select(x => AssetDatabase.GUIDToAssetPath(x)).FirstOrDefault();
                if (prefPath != null)
                {
                    instance = AssetDatabase.LoadAssetAtPath <BetterPrefs>(prefPath);
                }
                else
                {
                    // Otherwise create one on the spot
                    instance = CreateInstance <BetterPrefs>();
                }
            }

            if (instance.Ints == null)
            {
                instance.Ints = new LookupIntInt();
            }
            if (instance.Strings == null)
            {
                instance.Strings = new LookupIntString();
            }
            if (instance.Floats == null)
            {
                instance.Floats = new LookupIntFloat();
            }
            if (instance.Bools == null)
            {
                instance.Bools = new LookupIntBool();
            }
            if (instance.Colors == null)
            {
                instance.Colors = new LookupIntColor();
            }
            if (instance.Vector3s == null)
            {
                instance.Vector3s = new LookupIntVector3();
            }

            // Add instance to the Asset Database if it isn't there already.
            if (AssetDatabase.Contains(instance))
            {
                return(instance);
            }

            const string root      = "Assets";
            var          dirs      = Directory.GetDirectories(root, "Vexe", SearchOption.AllDirectories);
            var          editorDir = dirs.FirstOrDefault(x => Directory.GetParent(x).Name == "Editor") ?? string.Empty;

            var prefsDir = Path.Combine(editorDir, "ScriptableAssets");

            if (editorDir.IsNullOrEmpty() || !Directory.Exists(prefsDir))
            {
                Debug.LogError("Unable to create editor prefs asset at Editor/Vexe/ScriptableAssets (couldn't find folder). Creating in project root instead...");
                prefsDir = root;
            }

            var path = Path.Combine(prefsDir, "BetterEditorPrefs.asset");

            AssetDatabase.CreateAsset(instance, path);
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
            AssetDatabase.Refresh();
            return(instance);
        }
Пример #6
0
 public static void Automatic()
 {
     BetterPrefs.GetEditorInstance().Bools[kReqAuto] = true;
 }
Пример #7
0
 public static void Manual()
 {
     BetterPrefs.GetEditorInstance().Bools[kReqAuto] = false;
 }