Exemplo n.º 1
0
        void DrawLoader()
        {
            loadFoldout = EditorGUILayout.Foldout(loadFoldout, "Database Directory");
            if (loadFoldout)
            {
                GUILayout.BeginHorizontal();

                const int maxDirLength = 28;
                if (GUILayout.Button(DatabaseDirectory.Length > maxDirLength ? "..." + DatabaseDirectory.Substring(DatabaseDirectory.Length - maxDirLength) : DatabaseDirectory, GUILayout.ExpandWidth(true)))
                {
                    DatabaseDirectory = EditorUtility.OpenFolderPanel("Database Folder", DatabaseDirectory, DatabaseDirectory);
                    EditorPrefs.SetString("*DataDir", DatabaseDirectory);

                    LSFSettingsModifier.Save();
                }
                if (GUILayout.Button("Load", GUILayout.MaxWidth(50f)))
                {
                    string databasePath = DatabaseDirectory + "/" + LSDatabaseManager.DatabaseFileName;
                    if (LoadDatabaseFromPath(databasePath) == false)
                    {
                        CreateDatabase(databasePath);
                        Debug.LogFormat("Database was not found at directory of {0} so one was created", DatabaseDirectory);
                    }
                }
                GUILayout.EndHorizontal();
            }
            SerializedObject   obj            = new SerializedObject(this);
            SerializedProperty editorTypeProp = obj.FindProperty("_databaseEditorType");

            EditorGUILayout.PropertyField(editorTypeProp, new GUIContent("Editor Type"));
            SerializedProperty databaseTypeProp = obj.FindProperty("_databaseType");

            EditorGUILayout.PropertyField(databaseTypeProp, new GUIContent("Database Type"));
        }
        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!
                }
                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;
        }
Exemplo n.º 3
0
 void LoadDatabase(LSDatabase database)
 {
     _database       = database;
     _databaseEditor = (EditorLSDatabase)Activator.CreateInstance(DatabaseEditorType);
     _databaseEditor.Initialize(this, Database);
     LSFSettingsManager.GetSettings().Database = database;
     LSFSettingsModifier.Save();
 }
Exemplo n.º 4
0
        void DrawSettings()
        {
            settingsFoldout = EditorGUILayout.Foldout(settingsFoldout, "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"));
                EditorPrefs.SetString(databaseTypeKey, _databaseType.Type != null ? _databaseType.Type.AssemblyQualifiedName : typeof(DefaultLSDatabase).AssemblyQualifiedName);


                if (GUILayout.Button("Load", GUILayout.MaxWidth(50f)))
                {
                    DatabasePath = EditorUtility.OpenFilePanel("Database File", "NewDatabase", "asset");
                    if (!string.IsNullOrEmpty(DatabasePath))
                    {
                        EditorPrefs.SetString(databasePathKey, DatabasePath);
                        LSFSettingsModifier.Save();
                        if (LoadDatabaseFromPath(DatabasePath) == false)
                        {
                            Debug.LogFormat("Database was not found at path of '{0}'.", DatabasePath);
                        }
                    }
                }
                if (GUILayout.Button("Create", GUILayout.MaxWidth(50f)))
                {
                    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();


                obj.ApplyModifiedProperties();
            }
        }
Exemplo n.º 5
0
        void LoadDatabase(LSDatabase database)
        {
            _database       = database;
            _databaseEditor = (EditorLSDatabase)Activator.CreateInstance(typeof(EditorLSDatabase));
            bool isValid;

            _databaseEditor.Initialize(this, Database, out isValid);
            if (!isValid)
            {
                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();
                }
            }
        }