public void CreateCategory(string _categoryName, string _categoryDescription, SceneAsset _firstScene) { LazyScene allItems = null; if (allItems == null) { allItems = AssetDatabase.LoadAssetAtPath("Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Scenes.asset", typeof(LazyScene)) as LazyScene; } EditorUtility.SetDirty(allItems); LazySceneCategorys tempItem = CreateInstance(typeof(LazySceneCategorys)) as LazySceneCategorys; tempItem.categoryDescription = _categoryDescription; tempItem.categoryTitle = _categoryName; tempItem.Scenes.Add(_firstScene); string assetName; if (string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID("Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Categories/" + _categoryName + ".asset"))) { assetName = _categoryName; } else { assetName = _categoryName + Random.Range(0, 9999); } AssetDatabase.CreateAsset(tempItem, "Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Categories/" + assetName + ".asset"); allItems.allCategorys.Add(tempItem); AssetDatabase.SaveAssets(); LazySceneLoaderCategoryWindow._window.Close(); }
private void CreateResources() { if (AssetDatabase.IsValidFolder("Assets/Editor/LazyHelpers/LazySceneLoader/Resources")) { _Items = AssetDatabase.LoadAssetAtPath("Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Scenes.asset", typeof(LazyScene)) as LazyScene; if (_Items == null) { //Debug.Log("no asset file found, could not reload"); _Items = CreateInstance(typeof(LazyScene)) as LazyScene; AssetDatabase.CreateAsset(_Items, "Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Scenes.asset"); GUI.changed = true; } } else { AssetDatabase.CreateFolder("Assets/Editor/LazyHelpers/LazySceneLoader", "Resources"); _Items = AssetDatabase.LoadAssetAtPath("Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Scenes.asset", typeof(LazyScene)) as LazyScene; if (_Items == null) { //Debug.Log("no asset file found, could not reload"); _Items = CreateInstance(typeof(LazyScene)) as LazyScene; AssetDatabase.CreateAsset(_Items, "Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Scenes.asset"); GUI.changed = true; } } if (!AssetDatabase.IsValidFolder("Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Categories")) { AssetDatabase.CreateFolder("Assets/Editor/LazyHelpers/LazySceneLoader/Resources", "Categories"); } }
public void DrawItemArea() { GUILayout.BeginArea(itemSection); LazyScene allItems = null; if (allItems == null) { allItems = AssetDatabase.LoadAssetAtPath("Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Scenes.asset", typeof(LazyScene)) as LazyScene; } List <string> categoryOptions = new List <string>(); for (int i = 0; i < allItems.allCategorys.Count; i++) { categoryOptions.Add(allItems.allCategorys[i].categoryTitle); } _options = categoryOptions.ToArray(); GUILayout.BeginVertical(evenBoxStyle); EditorGUILayout.HelpBox("Select the Category that the scene will be added to", MessageType.Info); GUILayout.BeginHorizontal(); GUILayout.Label("Category", generalStyle, GUILayout.MaxWidth(70), GUILayout.MinWidth(70)); _selected = EditorGUILayout.Popup(_selected, _options); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.Space(5); GUILayout.BeginVertical(oddBoxStyle); EditorGUILayout.HelpBox("Scene to add", MessageType.Info); source = EditorGUILayout.ObjectField(source, typeof(SceneAsset), false); GUILayout.EndVertical(); GUILayout.Space(5); GUILayout.BeginVertical(evenBoxStyle); if (source != null) { if (GUILayout.Button("Add Scene", GUILayout.MaxHeight(20), GUILayout.MaxWidth(120))) { AddSceneToCategory((SceneAsset)source, _selected); } } else { EditorGUILayout.HelpBox("Scene cannot be null", MessageType.Error); } GUILayout.EndVertical(); GUILayout.EndArea(); }
private void AddSceneToCategory(SceneAsset scene, int categoryNum) { LazyScene allItems = null; if (allItems == null) { allItems = AssetDatabase.LoadAssetAtPath("Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Scenes.asset", typeof(LazyScene)) as LazyScene; } EditorUtility.SetDirty(allItems.allCategorys[categoryNum]); if (!allItems.allCategorys[categoryNum].Scenes.Contains(scene)) { allItems.allCategorys[categoryNum].Scenes.Add(scene); } source = null; AssetDatabase.SaveAssets(); LazySceneLoaderSceneAdderWindow._window.Close(); }
public void EditCategoryDisplay() { GUILayout.BeginArea(itemSection); GUILayout.Space(2); LazyScene allItems = null; if (allItems == null) { allItems = AssetDatabase.LoadAssetAtPath("Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Scenes.asset", typeof(LazyScene)) as LazyScene; } for (int i = 0; i < allItems.allCategorys.Count; i++) { bool isEven = i % 2 == 0; GUIStyle itemStyle = new GUIStyle(); if (isEven) { itemStyle = evenBoxStyle; } else { itemStyle = oddBoxStyle; } GUILayout.BeginHorizontal(itemStyle); allItems.allCategorys[i].categoryTitle = GUILayout.TextField(allItems.allCategorys[i].categoryTitle, 16, GUILayout.MaxWidth(120), GUILayout.MinWidth(120)); GUILayout.FlexibleSpace(); if (GUILayout.Button("Delete Category")) { EditorUtility.SetDirty(allItems); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(allItems.allCategorys[i])); allItems.allCategorys.RemoveAt(i); AssetDatabase.SaveAssets(); } GUILayout.EndHorizontal(); } GUILayout.EndArea(); }
public void CreateCategoryDisplay() { LazyScene allItems = null; if (allItems == null) { allItems = AssetDatabase.LoadAssetAtPath("Assets/Editor/LazyHelpers/LazySceneLoader/Resources/Scenes.asset", typeof(LazyScene)) as LazyScene; } GUILayout.BeginArea(itemSection); GUILayout.Space(2); GUILayout.BeginVertical(); GUILayout.BeginVertical(oddBoxStyle); //First Scene object GUILayout.Label("First Scene", secondaryHeaderStyle); GUILayout.Label("First Scene of the category", generalStyle); source = EditorGUILayout.ObjectField(source, typeof(SceneAsset), false); GUILayout.EndVertical(); GUILayout.Space(5); //Category Name GUILayout.BeginVertical(evenBoxStyle); GUILayout.Label("Category Name", secondaryHeaderStyle); GUILayout.Label("Only the 3 first letters of the name will appear on the buttons", generalStyle); categoryName = GUILayout.TextField(categoryName, 16); GUILayout.EndVertical(); GUILayout.Space(5); //Text Area Name GUILayout.BeginVertical(oddBoxStyle); GUILayout.Label("Category Description", secondaryHeaderStyle); GUILayout.Label("A small description of the category", generalStyle); categoryDescription = GUILayout.TextArea(categoryDescription, 256); GUILayout.EndVertical(); GUILayout.BeginVertical(evenBoxStyle); if (source == null) { EditorGUILayout.HelpBox("First Scene File Cannot Be Null", MessageType.Error); } else { if (categoryName == string.Empty) { EditorGUILayout.HelpBox("Name Cannot Be Empty", MessageType.Error); } else { if (categoryDescription == string.Empty) { EditorGUILayout.HelpBox("Description Cannot Be Empty", MessageType.Error); } else { bool nameAlreadyTaken = false; for (int i = 0; i < allItems.allCategorys.Count; i++) { if (allItems.allCategorys[i].categoryTitle == categoryName) { nameAlreadyTaken = true; } } if (nameAlreadyTaken) { EditorGUILayout.HelpBox("Name Already Taken Please Choose A Different Name", MessageType.Error); } else { if (GUILayout.Button("Create Catagory")) { CreateCategory(categoryName, categoryDescription, (SceneAsset)source); } } } } } GUILayout.EndVertical(); GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.EndArea(); }