/// <summary> Resets the database to the default values </summary> public bool ResetDatabase() { #if UNITY_EDITOR if (!DoozyUtils.DisplayDialog(UILabels.ResetDatabase, UILabels.AreYouSureYouWantToResetDatabase + "\n\n" + UILabels.OperationCannotBeUndone, UILabels.Yes, UILabels.No)) { return(false); } for (int i = Categories.Count - 1; i >= 0; i--) { ListOfNames category = Categories[i]; Categories.Remove(category); DoozyUtils.MoveAssetToTrash(AssetDatabase.GetAssetPath(category)); } UpdateListOfCategoryNames(); AddDefaultCategories(true); DDebug.Log(UILabels.DatabaseHasBeenReset); #endif return(true); }
/// <summary> Removes the given ListOfNames reference from the database and also deletes its corresponding asset file. Returns TRUE if the operation was successful </summary> /// <param name="category"> Target category to be deleted </param> public bool DeleteCategory(ListOfNames category) { if (category == null) { return(false); } #if UNITY_EDITOR if (!EditorUtility.DisplayDialog(UILabels.Delete + " '" + category.CategoryName + "'", UILabels.AreYouSureYouWantToDeleteDatabase + "\n\n" + UILabels.OperationCannotBeUndone, UILabels.Yes, UILabels.No)) { return(false); } Categories.Remove(category); DoozyUtils.MoveAssetToTrash(AssetDatabase.GetAssetPath(category)); UpdateListOfCategoryNames(); SetDirty(false); #endif return(true); }
/// <summary> [Editor Only] Performs a deep search through the project for any unregistered ListOfNames asset files and adds them to the database. The search is done only in all the Resources folders. </summary> /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param> public void SearchForUnregisteredDatabases(bool saveAssets) { string title = UILabels.Database + ": " + DatabaseType; // ProgressBar Title string info = UILabels.Search; // ProgressBar Info DoozyUtils.DisplayProgressBar(title, info, 0.1f); bool foundUnregisteredDatabase = false; ListOfNames[] array = Resources.LoadAll <ListOfNames>(""); if (array == null || array.Length == 0) { DoozyUtils.ClearProgressBar(); return; } if (Categories == null) { Categories = new List <ListOfNames>(); } for (int i = 0; i < array.Length; i++) { DoozyUtils.DisplayProgressBar(title, info, 0.1f + 0.8f * (i + 1) / array.Length); ListOfNames foundList = array[i]; if (foundList.DatabaseType != DatabaseType) { continue; } if (Categories.Contains(foundList)) { continue; } Categories.Add(foundList); foundUnregisteredDatabase = true; } DoozyUtils.DisplayProgressBar(title, info, 1f); if (!foundUnregisteredDatabase) { DoozyUtils.ClearProgressBar(); return; } UpdateListOfCategoryNames(); SetDirty(saveAssets); DoozyUtils.ClearProgressBar(); }
/// <summary> Creates a new ListOfNames asset, at the given relative path, with the given category name and adds a reference to it to the database. Returns TRUE if the operation was successful </summary> /// <param name="relativePath"> Path where to create the theme asset </param> /// <param name="categoryName"> The category name of the new ListOfNames </param> /// <param name="names"> Names to be added to the list </param> /// <param name="showDialog"> Should a display dialog be shown before executing the action </param> /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param> public bool CreateCategory(string relativePath, string categoryName, List <string> names, bool showDialog = false, bool saveAssets = false) { categoryName = categoryName.Trim(); if (string.IsNullOrEmpty(categoryName)) { #if UNITY_EDITOR if (showDialog) { EditorUtility.DisplayDialog(UILabels.NewCategory, UILabels.EnterCategoryName, UILabels.Ok); } #endif return(false); } if (Contains(categoryName)) { #if UNITY_EDITOR if (showDialog) { EditorUtility.DisplayDialog(UILabels.NewCategory, UILabels.AnotherEntryExists, UILabels.Ok); } #endif return(false); } #if UNITY_EDITOR var listOfNames = AssetUtils.CreateAsset <ListOfNames>(relativePath, GetDatabaseFileName(DatabaseType, categoryName)); #else ListOfNames listOfNames = ScriptableObject.CreateInstance <ListOfNames>(); #endif listOfNames.CategoryName = categoryName; if (names == null) { names = new List <string>(); } listOfNames.AddNames(names, true, false); listOfNames.DatabaseType = DatabaseType; listOfNames.SetDirty(false); Categories.Add(listOfNames); UpdateListOfCategoryNames(); SetDirty(saveAssets); return(true); }
/// <summary> Adds a new list of names to the database. Returns TRUE if the operation was successful </summary> /// <param name="category"> The list of names </param> /// <param name="performUndo"> Record changes? </param> /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param> public bool Add(ListOfNames category, bool performUndo, bool saveAssets) { if (category == null) { return(false); } if (Categories == null) { Categories = new List <ListOfNames>(); } if (performUndo) { UndoRecord(UILabels.AddItem); } Categories.Add(category); category.DatabaseType = DatabaseType; UpdateListOfCategoryNames(); SetDirty(saveAssets); return(true); }
/// <summary> Removes the category with the passed category name (if it exists) </summary> /// <param name="categoryName"> Category name to search for </param> /// <param name="showDialog"> Should a display dialog be shown before executing the action </param> /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param> public void RemoveCategory(string categoryName, bool showDialog, bool saveAssets) { if (!Contains(categoryName)) { return; } #if UNITY_EDITOR if (showDialog) { if (!EditorUtility.DisplayDialog(UILabels.RemoveCategory + " '" + categoryName + "'", UILabels.AreYouSureYouWantToRemoveCategory + "\n\n" + UILabels.OperationCannotBeUndone, UILabels.Yes, UILabels.No)) { return; } } #endif bool needSave = false; for (int i = Categories.Count - 1; i >= 0; i--) { ListOfNames listOfNames = Categories[i]; if (listOfNames.CategoryName != categoryName) { continue; } if (DeleteCategory(listOfNames)) { needSave = true; } } if (needSave) { SetDirty(saveAssets); } }
/// <summary> Adds the default categories to the database by taking into account the database type. Returns TRUE if the operation was successful </summary> /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param> public void AddDefaultCategories(bool saveAssets) { if (!Contains(GENERAL)) { // CreateCategory(GENERAL, new List<string>(), false, false); #if UNITY_EDITOR var listOfNames = AssetUtils.CreateAsset <ListOfNames>(GetPath(DatabaseType), GetDatabaseFileName(DatabaseType, GENERAL)); #else ListOfNames listOfNames = ScriptableObject.CreateInstance <ListOfNames>(); #endif listOfNames.CategoryName = GENERAL; listOfNames.DatabaseType = DatabaseType; Categories.Add(listOfNames); UpdateListOfCategoryNames(); SetDirty(saveAssets); } ListOfNames general = GetCategory(GENERAL); switch (DatabaseType) { case NamesDatabaseType.UIButton: if (!general.Contains(UNNAMED)) { general.AddName(UNNAMED, false); } if (!general.Contains(BACK)) { general.AddName(BACK, false); } break; case NamesDatabaseType.UICanvas: if (!general.Contains(MASTER_CANVAS)) { general.AddName(MASTER_CANVAS, false); } break; case NamesDatabaseType.UIView: if (!general.Contains(UNNAMED)) { general.AddName(UNNAMED, false); } break; case NamesDatabaseType.UIDrawer: if (!general.Contains(UNNAMED)) { general.AddName(UNNAMED, false); } if (!general.Contains(LEFT)) { general.AddName(LEFT, false); } if (!general.Contains(RIGHT)) { general.AddName(RIGHT, false); } if (!general.Contains(UP)) { general.AddName(UP, false); } if (!general.Contains(DOWN)) { general.AddName(DOWN, false); } break; } }