public ItemReturnOperation OnPreferencesWindowGUI(DatabaseInventoryEditor inventoryEditor, int index) { serializedObject.Update(); inventoryEditor.searchText = inventoryEditor.searchText.ToLower(); string spNameString = this.spName.FindPropertyRelative("content").stringValue; string spDescString = this.spDescription.FindPropertyRelative("content").stringValue; if (!string.IsNullOrEmpty(inventoryEditor.searchText) && !spNameString.ToLower().Contains(inventoryEditor.searchText) && !spDescString.ToLower().Contains(inventoryEditor.searchText)) { return(new ItemReturnOperation()); } ItemReturnOperation result = this.PaintHeader(inventoryEditor, index); using (var group = new EditorGUILayout.FadeGroupScope(this.animUnfold.faded)) { if (group.visible) { EditorGUILayout.BeginVertical(CoreGUIStyles.GetBoxExpanded()); this.PaintContent(); EditorGUILayout.EndVertical(); } } serializedObject.ApplyModifiedPropertiesWithoutUndo(); return(result); }
// INSPECTOR: ----------------------------------------------------------------------------- public override void OnInspectorGUI() { if (target == null || serializedObject == null) { return; } serializedObject.Update(); this.UpdateSubEditors(this.instance.conditions); int removConditionIndex = -1; int duplicateConditionIndex = -1; int copyConditionIndex = -1; bool forceRepaint = false; bool conditionsCollapsed = true; int spConditionsSize = this.spConditions.arraySize; for (int i = 0; i < spConditionsSize; ++i) { bool forceSortRepaint = this.editorSortableList.CaptureSortEvents(this.handleRect[i], i); forceRepaint = forceSortRepaint || forceRepaint; GUILayout.BeginVertical(); ItemReturnOperation returnOperation = this.PaintConditionsHeader(i); if (returnOperation.removeIndex) { removConditionIndex = i; } if (returnOperation.duplicateIndex) { duplicateConditionIndex = i; } if (returnOperation.copyIndex) { copyConditionIndex = i; } conditionsCollapsed &= this.isExpanded[i].target; 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_CONDITION_1, MessageType.Warning); EditorGUILayout.HelpBox(MSG_UNDEF_CONDITION_2, MessageType.None); } EditorGUILayout.EndVertical(); } } GUILayout.EndVertical(); if (UnityEngine.Event.current.type == EventType.Repaint) { this.objectRect[i] = GUILayoutUtility.GetLastRect(); } this.editorSortableList.PaintDropPoints(this.objectRect[i], i, spConditionsSize); } Rect rectControls = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn()); Rect rectAddConditions = new Rect( rectControls.x, rectControls.y, SelectTypePanel.WINDOW_WIDTH, rectControls.height ); Rect rectPaste = new Rect( rectAddConditions.x + rectAddConditions.width, rectControls.y, 25f, rectControls.height ); Rect rectPlay = new Rect( rectControls.x + rectControls.width - 25f, rectControls.y, 25f, rectControls.height ); Rect rectCollapse = new Rect( rectPlay.x - 25f, rectPlay.y, 25f, rectPlay.height ); Rect rectUnused = new Rect( rectPaste.x + rectPaste.width, rectControls.y, rectControls.width - ((rectPaste.x + rectPaste.width) - rectControls.x) - rectPlay.width - rectCollapse.width, rectControls.height ); if (GUI.Button(rectAddConditions, "Add Condition", CoreGUIStyles.GetToggleButtonLeftAdd())) { SelectTypePanel selectTypePanel = new SelectTypePanel(this.AddNewCondition, "Conditions", typeof(ICondition)); PopupWindow.Show(this.addConditionsButtonRect, selectTypePanel); } if (UnityEngine.Event.current.type == EventType.Repaint) { this.addConditionsButtonRect = rectAddConditions; } GUIContent gcPaste = ClausesUtilities.Get(ClausesUtilities.Icon.Paste); EditorGUI.BeginDisabledGroup(CLIPBOARD_ICONDITION == null); if (GUI.Button(rectPaste, gcPaste, CoreGUIStyles.GetButtonMid())) { ICondition conditionCreated = (ICondition)this.instance.gameObject.AddComponent(CLIPBOARD_ICONDITION.GetType()); EditorUtility.CopySerialized(CLIPBOARD_ICONDITION, conditionCreated); this.spConditions.AddToObjectArray(conditionCreated); this.AddSubEditorElement(conditionCreated, -1, true); DestroyImmediate(CLIPBOARD_ICONDITION.gameObject, true); if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene); } CLIPBOARD_ICONDITION = null; } EditorGUI.EndDisabledGroup(); GUI.Label(rectUnused, "", CoreGUIStyles.GetToggleButtonMidOn()); GUIContent gcToggle = (conditionsCollapsed ? ClausesUtilities.Get(ClausesUtilities.Icon.Collapse) : ClausesUtilities.Get(ClausesUtilities.Icon.Expand) ); EditorGUI.BeginDisabledGroup(this.instance.conditions.Length == 0); if (GUI.Button(rectCollapse, gcToggle, CoreGUIStyles.GetButtonMid())) { for (int i = 0; i < this.subEditors.Length; ++i) { this.SetExpand(i, !conditionsCollapsed); } } EditorGUI.EndDisabledGroup(); GUIContent gcPlay = ClausesUtilities.Get(ClausesUtilities.Icon.Play); EditorGUI.BeginDisabledGroup(!EditorApplication.isPlaying); if (GUI.Button(rectPlay, gcPlay, CoreGUIStyles.GetButtonRight())) { Debug.LogFormat("<b>Conditions Evaluation:</b> {0}", this.instance.Check(null)); } EditorGUI.EndDisabledGroup(); if (removConditionIndex >= 0) { ICondition source = (ICondition)this.spConditions.GetArrayElementAtIndex(removConditionIndex).objectReferenceValue; this.spConditions.RemoveFromObjectArrayAt(removConditionIndex); this.RemoveSubEditorsElement(removConditionIndex); DestroyImmediate(source, true); if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene); } } if (duplicateConditionIndex >= 0) { int srcIndex = duplicateConditionIndex; int dstIndex = duplicateConditionIndex + 1; ICondition source = (ICondition)this.subEditors[srcIndex].target; ICondition copy = (ICondition)this.instance.gameObject.AddComponent(source.GetType()); this.spConditions.InsertArrayElementAtIndex(dstIndex); this.spConditions.GetArrayElementAtIndex(dstIndex).objectReferenceValue = copy; EditorUtility.CopySerialized(source, copy); this.AddSubEditorElement(copy, dstIndex, true); if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene); } } if (copyConditionIndex >= 0) { ICondition source = (ICondition)this.subEditors[copyConditionIndex].target; GameObject conditionInstance = new GameObject(); conditionInstance.hideFlags = HideFlags.HideAndDontSave; CLIPBOARD_ICONDITION = (ICondition)conditionInstance.AddComponent(source.GetType()); EditorUtility.CopySerialized(source, CLIPBOARD_ICONDITION); } EditorSortableList.SwapIndexes swapIndexes = this.editorSortableList.GetSortIndexes(); if (swapIndexes != null) { this.spConditions.MoveArrayElement(swapIndexes.src, swapIndexes.dst); this.MoveSubEditorsElement(swapIndexes.src, swapIndexes.dst); if (!Application.isPlaying) { EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene); } } if (EditorApplication.isPlaying) { forceRepaint = true; } if (forceRepaint) { this.Repaint(); } serializedObject.ApplyModifiedProperties(); }
private ItemReturnOperation PaintConditionsHeader(int i) { ItemReturnOperation returnOperation = new ItemReturnOperation(); Rect rectHeader = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn()); this.PaintDragHandle(i, rectHeader); Texture2D conditionIcon = (i < this.subEditors.Length && this.subEditors[i] != null ? this.subEditors[i].GetIcon() : null ); string conditionName = (this.isExpanded[i].target ? " ▾ " : " ▸ "); conditionName += (this.instance.conditions[i] != null ? this.instance.conditions[i].GetNodeTitle() : "<i>Undefined Condition</i>" ); GUIStyle style = (this.isExpanded[i].target ? CoreGUIStyles.GetToggleButtonMidOn() : CoreGUIStyles.GetToggleButtonMidOff() ); Rect rectDelete = new Rect( rectHeader.x + rectHeader.width - 25f, rectHeader.y, 25f, rectHeader.height ); Rect rectDuplicate = new Rect( rectDelete.x - 25f, rectHeader.y, 25f, rectHeader.height ); Rect rectCopy = new Rect( rectDuplicate.x - 25f, rectHeader.y, 25f, rectHeader.height ); Rect rectMain = new Rect( rectHeader.x + 25f, rectHeader.y, rectHeader.width - (25f * 4f), rectHeader.height ); if (GUI.Button(rectMain, new GUIContent(conditionName, conditionIcon), style)) { this.ToggleExpand(i); } GUIContent gcCopy = ClausesUtilities.Get(ClausesUtilities.Icon.Copy); GUIContent gcDuplicate = ClausesUtilities.Get(ClausesUtilities.Icon.Duplicate); GUIContent gcDelete = ClausesUtilities.Get(ClausesUtilities.Icon.Delete); if (this.instance.conditions[i] != null && GUI.Button(rectCopy, gcCopy, CoreGUIStyles.GetButtonMid())) { returnOperation.copyIndex = true; } if (this.instance.conditions[i] != null && GUI.Button(rectDuplicate, gcDuplicate, CoreGUIStyles.GetButtonMid())) { returnOperation.duplicateIndex = true; } if (GUI.Button(rectDelete, gcDelete, CoreGUIStyles.GetButtonRight())) { returnOperation.removeIndex = true; } return(returnOperation); }
private ItemReturnOperation PaintActionHeader(int i) { ItemReturnOperation returnOperation = new ItemReturnOperation(); Color defaultBackgroundColor = GUI.backgroundColor; if (this.spExecutingIndex.intValue == i) { GUI.backgroundColor = COLOR_EXECUTING_ACTION; } Rect rectHeader = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn()); this.PaintDragHandle(i, rectHeader); Texture2D icon = this.subEditors[i].GetIcon(); string name = (this.isExpanded[i].target ? " ▾ " : " ▸ "); name += (this.instance.actions[i] != null ? this.instance.actions[i].GetNodeTitle() : "<i>Undefined Action</i>" ); GUIStyle style = (this.isExpanded[i].target ? CoreGUIStyles.GetToggleButtonMidOn() : CoreGUIStyles.GetToggleButtonMidOff() ); float opacity = 1.0f; if (this.subEditors[i] != null && this.subEditors[i].action != null) { opacity = this.subEditors[i].action.GetOpacity(); } Color tempColor = style.normal.textColor; style.normal.textColor = new Color( style.normal.textColor.r, style.normal.textColor.g, style.normal.textColor.b, opacity ); Rect rectDelete = new Rect( rectHeader.x + rectHeader.width - 25f, rectHeader.y, 25f, rectHeader.height ); Rect rectDuplicate = new Rect( rectDelete.x - 25f, rectHeader.y, 25f, rectHeader.height ); Rect rectCopy = new Rect( rectDuplicate.x - 25f, rectHeader.y, 25f, rectHeader.height ); Rect rectMain = new Rect( rectHeader.x + 25f, rectHeader.y, rectHeader.width - (25f * 4f), rectHeader.height ); if (GUI.Button(rectMain, new GUIContent(name, icon), style)) { this.ToggleExpand(i); } style.normal.textColor = tempColor; GUIContent gcCopy = InteractionUtilities.Get(InteractionUtilities.Icon.Copy); GUIContent gcDuplicate = InteractionUtilities.Get(InteractionUtilities.Icon.Duplicate); GUIContent gcDelete = InteractionUtilities.Get(InteractionUtilities.Icon.Delete); if (this.instance.actions[i] != null && GUI.Button(rectCopy, gcCopy, CoreGUIStyles.GetButtonMid())) { returnOperation.copyIndex = true; } if (this.instance.actions[i] != null && GUI.Button(rectDuplicate, gcDuplicate, CoreGUIStyles.GetButtonMid())) { returnOperation.duplicateIndex = true; } if (GUI.Button(rectDelete, gcDelete, CoreGUIStyles.GetButtonRight())) { returnOperation.removeIndex = true; } GUI.backgroundColor = defaultBackgroundColor; return(returnOperation); }
private ItemReturnOperation PaintHeader(DatabaseInventoryEditor inventoryEditor, int index) { bool removeItem = false; bool duplicateIndex = false; EditorGUILayout.BeginHorizontal(); bool forceSortRepaint = false; if (inventoryEditor.itemsHandleRect.ContainsKey(index)) { EditorGUIUtility.AddCursorRect(inventoryEditor.itemsHandleRect[index], MouseCursor.Pan); forceSortRepaint = inventoryEditor.editorSortableListItems.CaptureSortEvents( inventoryEditor.itemsHandleRect[index], index ); } if (forceSortRepaint) { inventoryEditor.Repaint(); } GUILayout.Label("=", CoreGUIStyles.GetButtonLeft(), GUILayout.Width(25f), GUILayout.Height(BTN_HEIGHT)); if (UnityEngine.Event.current.type == EventType.Repaint) { Rect dragRect = GUILayoutUtility.GetLastRect(); if (inventoryEditor.itemsHandleRect.ContainsKey(index)) { inventoryEditor.itemsHandleRect[index] = dragRect; } else { inventoryEditor.itemsHandleRect.Add(index, dragRect); } } if (inventoryEditor.itemsHandleRectRow.ContainsKey(index)) { inventoryEditor.editorSortableListItems.PaintDropPoints( inventoryEditor.itemsHandleRectRow[index], index, inventoryEditor.spItems.arraySize ); } string name = (this.animUnfold.target ? "▾ " : "▸ "); string spNameString = this.spName.FindPropertyRelative("content").stringValue; name += (string.IsNullOrEmpty(spNameString) ? "No-name" : spNameString); GUIStyle style = (this.animUnfold.target ? CoreGUIStyles.GetToggleButtonMidOn() : CoreGUIStyles.GetToggleButtonMidOff() ); if (GUILayout.Button(name, style, GUILayout.Height(BTN_HEIGHT))) { this.animUnfold.target = !this.animUnfold.value; } GUIContent gcDuplicate = ClausesUtilities.Get(ClausesUtilities.Icon.Duplicate); if (GUILayout.Button(gcDuplicate, CoreGUIStyles.GetButtonMid(), GUILayout.Width(25), GUILayout.Height(BTN_HEIGHT))) { duplicateIndex = true; } GUIContent gcDelete = ClausesUtilities.Get(ClausesUtilities.Icon.Delete); if (GUILayout.Button(gcDelete, CoreGUIStyles.GetButtonRight(), GUILayout.Width(25), GUILayout.Height(BTN_HEIGHT))) { removeItem = true; } EditorGUILayout.EndHorizontal(); if (UnityEngine.Event.current.type == EventType.Repaint) { Rect rect = GUILayoutUtility.GetLastRect(); if (inventoryEditor.itemsHandleRectRow.ContainsKey(index)) { inventoryEditor.itemsHandleRectRow[index] = rect; } else { inventoryEditor.itemsHandleRectRow.Add(index, rect); } } ItemReturnOperation result = new ItemReturnOperation(); if (removeItem) { result.removeIndex = true; } if (duplicateIndex) { result.duplicateIndex = true; } return(result); }
private ItemReturnOperation PaintReferenceHeader(int i, bool usingSearch) { ItemReturnOperation returnOperation = new ItemReturnOperation(); Rect rectHeader = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn()); if (!usingSearch) { this.PaintDragHandle(i, rectHeader); } string variableName = (this.isExpanded[i].target ? " ▾ " : " ▸ "); variableName += this.GetReferenceName(i); Texture2D variableIcon = VariableEditorUtils.GetIcon(this.GetReferenceType(i)); GUIStyle style = (this.isExpanded[i].target ? CoreGUIStyles.GetToggleButtonMidOn() : CoreGUIStyles.GetToggleButtonMidOff() ); Rect rectDelete = new Rect( rectHeader.x + rectHeader.width - 25f, rectHeader.y, 25f, rectHeader.height ); Rect rectMain = new Rect( rectHeader.x + 25f, rectHeader.y, rectHeader.width - (25f * 2f), rectHeader.height ); if (usingSearch) { style = (this.isExpanded[i].target ? CoreGUIStyles.GetToggleButtonLeftOn() : CoreGUIStyles.GetToggleButtonLeftOff() ); rectMain = new Rect( rectHeader.x, rectHeader.y, rectHeader.width - 25f, rectHeader.height ); } if (GUI.Button(rectMain, new GUIContent(variableName, variableIcon), style)) { this.ToggleExpand(i); } GUIContent gcDelete = ClausesUtilities.Get(ClausesUtilities.Icon.Delete); if (GUI.Button(rectDelete, gcDelete, CoreGUIStyles.GetButtonRight())) { returnOperation.removeIndex = true; } this.PaintTags(i); return(returnOperation); }
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(); } }