예제 #1
0
 private void RefreshDbs()
 {
     for (int i = 0; i < _dbList.Count; i++)
     {
         ScriptableDatabaseEditorExtension.RefreshDbProjectAssets(_dbList[i]);
     }
 }
        public override void OnInspectorGUI()
        {
            var script = (ScriptableDatabase)target;

            if (GUILayout.Button("Add All Types"))
            {
                ScriptableDatabaseEditorExtension.RefreshDbProjectAssets(script);
            }
            if (GUILayout.Button("Save Json"))
            {
                string path = EditorUtility.SaveFilePanel("DB Backup location", Application.streamingAssetsPath, script.name, "json");
                if (path.Length == 0)
                {
                    return;
                }
                var serialized = JsonConvert.SerializeObject(new SerializedScriptableObjectCollection(script, script.AllObjects),
                                                             Formatting
                                                             .Indented,
                                                             Serializer.ConverterSettings);
                // var jsonOutput = EditorJsonUtility.ToJson(target, true);
                // var sb = new System.Text.StringBuilder(jsonOutput);
                // foreach (var allObject in script.AllObjects) {
                //     sb.AppendNewLine();
                // }
                // sb.AppendNewLine();
                FileUtility.SaveFile(path, serialized);
            }
            if (GUILayout.Button("Load Json"))
            {
                string path = EditorUtility.OpenFilePanel("DB Backup location", Application.streamingAssetsPath, "json");
                if (path.Length == 0)
                {
                    return;
                }
                // var loaded = FileUtility.ReadFile(path);
                // var assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(EditorFolder + script.GetType().Name + ".asset");
                // var created = CreateInstance(script.GetType());
                // AssetDatabase.CreateAsset(created, assetPathAndName);
                // AssetDatabase.SaveAssets();
                // AssetDatabase.Refresh();
                //EditorJsonUtility.FromJsonOverwrite(loaded, created);
                var converted = JsonConvert.DeserializeObject <SerializedScriptableObjectCollection>(FileUtility.ReadFile(path), Serializer
                                                                                                     .ConverterSettings);
                converted.Restore();
                var main = converted.Main.Value as ScriptableDatabase;
                if (main == null || converted.Children == null)
                {
                    return;
                }
                for (int i = 0; i < converted.Children.Count(); i++)
                {
                    main.AddObject(converted.Children[i].Value);
                }
            }
            base.OnInspectorGUI();
        }