private void CreateNewPackage()
        {
            string nameBase = "Package";
            string name     = nameBase;
            string path     = null;
            int    i        = 0;

            while (true)
            {
                path = BuilderPackage.PackagesDir + name + ".json";
                if (!File.Exists(path))
                {
                    break;
                }

                name = nameBase + (++i).ToString();
            }

            var package = new BuilderPackage();

            package.name = name;
            package.InitializeNew();
            var obj = new JObject();

            package.ToJson(obj);
            File.WriteAllText(path, obj.ToString(Newtonsoft.Json.Formatting.Indented), Encoding.UTF8);

            this._currentPackageName  = name;
            this._currentPackage      = package;
            this._currentPackageDirty = false;
        }
        private void OnGUI()
        {
            var packages = GetPackages();

            int oldConfigIndex = this._currentPackageName != null?System.Array.IndexOf(packages, this._currentPackageName) : -1;

            int newConfigIndex = EditorGUILayout.Popup(
                oldConfigIndex,
                packages
                );

            if (newConfigIndex != oldConfigIndex)
            {
                this._currentPackageName = newConfigIndex != -1 ? packages[newConfigIndex] : null;
                this._currentPackage     = null;
            }

            BuilderPreferences.lastPackage = this._currentPackageName;

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("New"))
            {
                this.CreateNewPackage();
            }

            var bg = GUI.backgroundColor;

            if (this._currentPackage != null && this._currentPackageDirty)
            {
                GUI.backgroundColor = Color.yellow;
            }
            if (GUILayout.Button(this._currentPackage != null && this._currentPackageDirty ? "Save*" : "Save"))
            {
                this.SaveCurrentPackage();
            }
            GUI.backgroundColor = bg;

            EditorGUILayout.EndHorizontal();

            if (this._currentPackage == null && this._currentPackageName != null)
            {
                this._currentPackage      = this.LoadPackage(this._currentPackageName);
                this._currentPackageDirty = false;
            }

            this._scrollPos = EditorGUILayout.BeginScrollView(this._scrollPos);
            if (this._currentPackage != null)
            {
                this._currentPackageDirty |= this._currentPackage.OnGUI();
            }
            EditorGUILayout.EndScrollView();
        }
        private BuilderPackage LoadPackage(string name)
        {
            var config = new BuilderPackage();

            string path = BuilderPackage.PackagesDir + name + ".json";

            config.name = name;
            if (File.Exists(path))
            {
                config.FromJson(JObject.Parse(File.ReadAllText(path)));
            }
            else
            {
                config.InitializeNew();
            }

            return(config);
        }
        public static BuilderPackage GetPackage(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            var path = PackagesDir + name + ".json";

            if (!File.Exists(path))
            {
                return(null);
            }

            var package = new BuilderPackage();

            package.name = name;
            package.FromJson(JObject.Parse(File.ReadAllText(path)));
            return(package);
        }
        private void OnEnable()
        {
            if (!this._initialized)
            {
                this._currentPackageName = BuilderPreferences.lastPackage;
                this._initialized        = true;
                return;
            }

            if (!string.IsNullOrEmpty(this._currentPackageSerialized))
            {
                this._currentPackage      = new BuilderPackage();
                this._currentPackage.name = this._currentPackageName;
                this._currentPackage.FromJson(JObject.Parse(this._currentPackageSerialized));
            }
            else
            {
                this._currentPackage = null;
            }

            this._currentPackageSerialized = null;
        }
Exemple #6
0
        public void Configure(List <string> availablePackages)
        {
            this._ignore.Clear();

            var allPackages = BuilderPackagesWindow.GetPackages();

            foreach (var name in allPackages)
            {
                var p = BuilderPackage.GetPackage(name);
                if (p == null)
                {
                    continue;
                }

                p.FillGuids(this._ignore);
            }
            if (this._ignore.Count == 0 || availablePackages == null || availablePackages.Count == 0)
            {
                return;
            }

            foreach (var name in availablePackages)
            {
                var p = BuilderPackage.GetPackage(name);
                if (p == null)
                {
                    continue;
                }

                p.FillGuids(this._guids);
                foreach (var guid in this._guids)
                {
                    this._ignore.Remove(guid);
                }
                this._guids.Clear();
            }
        }