private void PaintRecipes() { int removeIndex = -1; int recipeCatalogueSize = this.spRecipes.arraySize; if (recipeCatalogueSize == 0) { EditorGUILayout.HelpBox(MSG_EMPTY_RECIPES, MessageType.Info); } for (int i = 0; i < recipeCatalogueSize; ++i) { bool removeRecipe = this.recipesData[i].cachedEditor.OnPreferencesWindowGUI(this, i); if (removeRecipe) { removeIndex = i; } } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Create Recipe", GUILayout.MaxWidth(200))) { this.ResetSearch(); int insertIndex = recipeCatalogueSize; this.spRecipes.InsertArrayElementAtIndex(insertIndex); Recipe recipe = Recipe.CreateRecipeInstance(); this.spRecipes.GetArrayElementAtIndex(insertIndex).objectReferenceValue = recipe; this.recipesData.Insert(insertIndex, new RecipeData(this.spRecipes.GetArrayElementAtIndex(insertIndex))); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (removeIndex != -1) { this.recipesData[removeIndex].cachedEditor.OnDestroyRecipe(); UnityEngine.Object deleteRecipe = this.recipesData[removeIndex].cachedEditor.target; this.spRecipes.RemoveFromObjectArrayAt(removeIndex); this.recipesData.RemoveAt(removeIndex); string path = AssetDatabase.GetAssetPath(deleteRecipe); DestroyImmediate(deleteRecipe, true); AssetDatabase.ImportAsset(path); } EditorSortableList.SwapIndexes swapIndexes = this.editorSortableListRecipes.GetSortIndexes(); if (swapIndexes != null) { this.spRecipes.MoveArrayElement(swapIndexes.src, swapIndexes.dst); RecipeData tempRecipt = this.recipesData[swapIndexes.src]; this.recipesData[swapIndexes.src] = this.recipesData[swapIndexes.dst]; this.recipesData[swapIndexes.dst] = tempRecipt; } }
private void PaintCatalogue() { int removeIndex = -1; this.PaintSearch(); int itemsCatalogueSize = this.spItems.arraySize; if (itemsCatalogueSize == 0) { EditorGUILayout.HelpBox(MSG_EMPTY_CATALOGUE, MessageType.Info); } for (int i = 0; i < itemsCatalogueSize; ++i) { if (this.itemsData[i].cachedEditor == null) { continue; } bool removeItem = this.itemsData[i].cachedEditor.OnPreferencesWindowGUI(this, i); if (removeItem) { removeIndex = i; } } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Create Item", GUILayout.MaxWidth(200))) { this.ResetSearch(); int insertIndex = itemsCatalogueSize; this.spItems.InsertArrayElementAtIndex(insertIndex); Item item = Item.CreateItemInstance(); this.spItems.GetArrayElementAtIndex(insertIndex).objectReferenceValue = item; this.itemsData.Insert(insertIndex, new ItemsData(this.spItems.GetArrayElementAtIndex(insertIndex))); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (removeIndex != -1) { this.itemsData[removeIndex].cachedEditor.OnDestroyItem(); UnityEngine.Object deleteItem = this.itemsData[removeIndex].cachedEditor.target; this.spItems.RemoveFromObjectArrayAt(removeIndex); this.itemsData.RemoveAt(removeIndex); string path = AssetDatabase.GetAssetPath(deleteItem); DestroyImmediate(deleteItem, true); AssetDatabase.ImportAsset(path); } EditorSortableList.SwapIndexes swapIndexes = this.editorSortableListItems.GetSortIndexes(); if (swapIndexes != null) { this.spItems.MoveArrayElement(swapIndexes.src, swapIndexes.dst); ItemsData tempItem = this.itemsData[swapIndexes.src]; this.itemsData[swapIndexes.src] = this.itemsData[swapIndexes.dst]; this.itemsData[swapIndexes.dst] = tempItem; } }
// PAINT METHODS: ------------------------------------------------------------------------- public override void OnInspectorGUI() { if (target == null || serializedObject == null) { return; } serializedObject.Update(); this.UpdateSubEditors(this.instance.stats); int removeIndex = -1; bool forceRepaint = false; int spActionsSize = this.spStats.arraySize; for (int i = 0; i < spActionsSize; ++i) { bool forceSortRepaint = this.editorSortableList.CaptureSortEvents(this.handleRect[i], i); forceRepaint = forceSortRepaint || forceRepaint; GUILayout.BeginVertical(); if (this.PaintStatHeader(i)) { removeIndex = i; } using (var group = new EditorGUILayout.FadeGroupScope(this.isExpanded[i].faded)) { if (group.visible) { EditorGUILayout.BeginVertical(CoreGUIStyles.GetBoxExpanded()); if (this.subEditors[i] != null) { this.subEditors[i].OnInspectorGUI(); } else { EditorGUILayout.HelpBox(MSG_UNDEF_STAT_1, MessageType.Warning); EditorGUILayout.HelpBox(MSG_UNDEF_STAT_2, MessageType.None); } EditorGUILayout.EndVertical(); } } GUILayout.EndVertical(); if (Event.current.type == EventType.Repaint) { this.objectRect[i] = GUILayoutUtility.GetLastRect(); } this.editorSortableList.PaintDropPoints(this.objectRect[i], i, spActionsSize); } if (GUILayout.Button("Create Stat")) { StatAsset statAsset = DatabaseStatsEditor.AddStatsAsset(); int addIndex = this.spStats.arraySize; this.spStats.InsertArrayElementAtIndex(addIndex); this.spStats.GetArrayElementAtIndex(addIndex).objectReferenceValue = statAsset; this.AddSubEditorElement(statAsset, addIndex, true); } if (removeIndex >= 0) { StatAsset source = (StatAsset)this.spStats.GetArrayElementAtIndex(removeIndex).objectReferenceValue; this.spStats.RemoveFromObjectArrayAt(removeIndex); this.RemoveSubEditorsElement(removeIndex); DestroyImmediate(source, true); } EditorSortableList.SwapIndexes swapIndexes = this.editorSortableList.GetSortIndexes(); if (swapIndexes != null) { this.spStats.MoveArrayElement(swapIndexes.src, swapIndexes.dst); this.MoveSubEditorsElement(swapIndexes.src, swapIndexes.dst); } if (EditorApplication.isPlaying) { forceRepaint = true; } if (forceRepaint) { this.Repaint(); } serializedObject.ApplyModifiedPropertiesWithoutUndo(); }
private void PaintCatalogue() { ItemEditor.ItemReturnOperation returnOp = new ItemEditor.ItemReturnOperation(); int removeIndex = -1; int duplicateIndex = -1; this.PaintSearch(); int itemsCatalogueSize = this.spItems.arraySize; if (itemsCatalogueSize == 0) { EditorGUILayout.HelpBox(MSG_EMPTY_CATALOGUE, MessageType.Info); } for (int i = 0; i < itemsCatalogueSize; ++i) { if (this.itemsData[i].cachedEditor == null) { continue; } returnOp = this.itemsData[i].cachedEditor.OnPreferencesWindowGUI(this, i); if (returnOp.removeIndex) { removeIndex = i; } if (returnOp.duplicateIndex) { duplicateIndex = i; } } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Create Item", GUILayout.MaxWidth(200))) { this.ResetSearch(); int insertIndex = itemsCatalogueSize; this.spItems.InsertArrayElementAtIndex(insertIndex); Item item = Item.CreateItemInstance(); this.spItems.GetArrayElementAtIndex(insertIndex).objectReferenceValue = item; this.itemsData.Insert(insertIndex, new ItemsData(this.spItems.GetArrayElementAtIndex(insertIndex))); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (removeIndex != -1) { this.itemsData[removeIndex].cachedEditor.OnDestroyItem(); UnityEngine.Object deleteItem = this.itemsData[removeIndex].cachedEditor.target; this.spItems.RemoveFromObjectArrayAt(removeIndex); this.itemsData.RemoveAt(removeIndex); string path = AssetDatabase.GetAssetPath(deleteItem); DestroyImmediate(deleteItem, true); AssetDatabase.ImportAsset(path); } else if (duplicateIndex != -1) { this.ResetSearch(); int srcIndex = duplicateIndex; int insertIndex = duplicateIndex + 1; this.spItems.InsertArrayElementAtIndex(insertIndex); Item item = Item.CreateItemInstance(); EditorUtility.CopySerialized( this.spItems.GetArrayElementAtIndex(srcIndex).objectReferenceValue, item ); SerializedProperty newItem = this.spItems.GetArrayElementAtIndex(insertIndex); newItem.objectReferenceValue = item; newItem.serializedObject.ApplyModifiedPropertiesWithoutUndo(); newItem.serializedObject.Update(); ItemsData newItemData = new ItemsData(newItem); newItemData.cachedEditor.serializedObject .FindProperty("actionsOnClick") .objectReferenceValue = this.MakeCopyOf(item.actionsOnClick); newItemData.cachedEditor.serializedObject .FindProperty("actionsOnEquip") .objectReferenceValue = this.MakeCopyOf(item.actionsOnEquip); newItemData.cachedEditor.serializedObject .FindProperty("actionsOnUnequip") .objectReferenceValue = this.MakeCopyOf(item.actionsOnUnequip); newItemData.cachedEditor.serializedObject .FindProperty("conditionsEquip") .objectReferenceValue = this.MakeCopyOf(item.conditionsEquip); int uuid = Mathf.Abs(Guid.NewGuid().GetHashCode()); newItemData.cachedEditor.spUUID.intValue = uuid; newItemData.cachedEditor.serializedObject.ApplyModifiedPropertiesWithoutUndo(); newItemData.cachedEditor.serializedObject.Update(); newItemData.cachedEditor.OnEnable(); this.itemsData.Insert(insertIndex, newItemData); } EditorSortableList.SwapIndexes swapIndexes = this.editorSortableListItems.GetSortIndexes(); if (swapIndexes != null) { this.spItems.MoveArrayElement(swapIndexes.src, swapIndexes.dst); ItemsData tempItem = this.itemsData[swapIndexes.src]; this.itemsData[swapIndexes.src] = this.itemsData[swapIndexes.dst]; this.itemsData[swapIndexes.dst] = tempItem; } }
private void PaintVariablesList(bool usingSearch) { int removeReferenceIndex = -1; bool forceRepaint = false; int spReferencesSize = this.spReferences.arraySize; for (int i = 0; i < spReferencesSize; ++i) { if (usingSearch) { if (!this.MatchSearch(i, this.search, this.tagsMask)) { continue; } } else { bool forceSortRepaint = this.editorSortableList.CaptureSortEvents(this.handleRect[i], i); forceRepaint = forceSortRepaint || forceRepaint; } EditorGUILayout.BeginVertical(); ItemReturnOperation returnOperation = this.PaintReferenceHeader(i, usingSearch); if (returnOperation.removeIndex) { removeReferenceIndex = i; } using (var group = new EditorGUILayout.FadeGroupScope(this.isExpanded[i].faded)) { if (group.visible) { EditorGUILayout.BeginVertical(CoreGUIStyles.GetBoxExpanded()); if (this.subEditors[i] != null) { this.BeforePaintSubEditor(i); this.subEditors[i].OnInspectorGUI(); } EditorGUILayout.EndVertical(); } } EditorGUILayout.EndVertical(); if (Event.current.type == EventType.Repaint) { this.objectRect[i] = GUILayoutUtility.GetLastRect(); } this.editorSortableList.PaintDropPoints(this.objectRect[i], i, spReferencesSize); } EditorGUILayout.Space(); if (removeReferenceIndex >= 0) { this.DeleteReferenceInstance(removeReferenceIndex); } EditorSortableList.SwapIndexes swapIndexes = this.editorSortableList.GetSortIndexes(); if (swapIndexes != null) { this.spReferences.MoveArrayElement(swapIndexes.src, swapIndexes.dst); this.MoveSubEditorsElement(swapIndexes.src, swapIndexes.dst); } if (EditorApplication.isPlaying) { forceRepaint = true; } if (forceRepaint) { this.Repaint(); } }