void LoadDatabase(LSDatabase database) { _database = database; bool isValid = false; if (_database != null) { if (database.GetType() != DatabaseType) { //Note: A hacky fix for changing the type of a previously saved database is to turn on Debug mode //and change the script type of the database asset in the inspector. Back it up before attempting! Debug.Log("Loaded database type does not match DatabaseType."); } DatabaseEditor = new EditorLSDatabase(); DatabaseEditor.Initialize(this, Database, out isValid); } if (!isValid) { Debug.Log("Load unsuccesful"); this.DatabaseEditor = null; this._database = null; IsLoaded = false; return; } LSFSettingsManager.GetSettings().Database = database; LSFSettingsModifier.Save(); IsLoaded = true; }
void DrawSettings() { settingsFoldout = EditorGUILayout.Foldout(settingsFoldout, "Data Settings"); if (settingsFoldout) { GUILayout.BeginHorizontal(); /* * const int maxDirLength = 28; * if (GUILayout.Button (DatabasePath.Length > maxDirLength ? "..." + DatabasePath.Substring (DatabasePath.Length - maxDirLength) : DatabasePath, GUILayout.ExpandWidth (true))) { * }*/ SerializedObject obj = new SerializedObject(this); SerializedProperty databaseTypeProp = obj.FindProperty("_databaseType"); EditorGUILayout.PropertyField(databaseTypeProp, new GUIContent("Database Type")); float settingsButtonWidth = 70f; if (GUILayout.Button("Load", GUILayout.MaxWidth(settingsButtonWidth))) { DatabasePath = EditorUtility.OpenFilePanel("Database File", Application.dataPath, "asset"); if (!string.IsNullOrEmpty(DatabasePath)) { LSFSettingsModifier.Save(); if (LoadDatabaseFromPath(DatabasePath) == false) { Debug.LogFormat("Database was not found at path of '{0}'.", DatabasePath); } } } if (GUILayout.Button("Create", GUILayout.MaxWidth(settingsButtonWidth))) { DatabasePath = EditorUtility.SaveFilePanel("Database File", Application.dataPath, "NewDatabase", "asset"); if (!string.IsNullOrEmpty(DatabasePath)) { if (CreateDatabase(DatabasePath)) { Debug.Log("Database creation succesful!"); } else { Debug.Log("Database creation unsuccesful"); } } } GUILayout.EndHorizontal(); //json stuff GUILayout.BeginHorizontal(); jsonFile = (TextAsset)EditorGUILayout.ObjectField("Json", jsonFile, typeof(TextAsset), false); if (GUILayout.Button("Load", GUILayout.MaxWidth(settingsButtonWidth))) { LSDatabaseManager.ApplyJson(jsonFile.text, Database); } if (GUILayout.Button("Save", GUILayout.MaxWidth(settingsButtonWidth))) { System.IO.File.WriteAllText( AssetDatabase.GetAssetPath(jsonFile), LSDatabaseManager.ToJson(Database) ); } GUILayout.EndHorizontal(); if (CanSave) { obj.ApplyModifiedProperties(); } } }