float GetDialogueNodeElementHeight(int index) { float height = 2 + DialogueTextRefFieldHeight; // Handle delete intermediate elements by code if (index >= dialogueNodeReorderableList.serializedProperty.arraySize) { return(0); } SerializedProperty element = dialogueNodeReorderableList.serializedProperty.GetArrayElementAtIndex(index); SerializedProperty dialogueTextProp = element.FindPropertyRelative("m_dialogueText"); DialogueText dialogueText = (DialogueText)dialogueTextProp.objectReferenceValue; if (dialogueText != null) { height += 2 + DialogueTextAreaFieldHeight; } SerializedProperty assignmentsProp = element.FindPropertyRelative("m_assignments"); VariableAssignmentReorderableList variableAssignmentReorderableList = variableAssignmentListPropertyDrawerManager.GetReorderableList(assignmentsProp, "Change Variables"); height += variableAssignmentReorderableList.GetHeight(); height += EditorGUIUtility.singleLineHeight + 2; SerializedProperty optionsProp = element.FindPropertyRelative("m_options"); for (int i = 0; i < optionsProp.arraySize; i++) { SerializedProperty optionProp = optionsProp.GetArrayElementAtIndex(i); SerializedProperty optionAssignmentsProp = optionProp.FindPropertyRelative("m_assignments"); VariableAssignmentReorderableList optionVariableAssignmentReorderableList = variableAssignmentListPropertyDrawerManager.GetReorderableList(optionAssignmentsProp, "Change Variables"); height += optionVariableAssignmentReorderableList.GetHeight() + 2; } height += (2 + DialogueTextRefFieldHeight) * optionsProp.arraySize + 2 + ButtonRowHeight; SerializedProperty nextsProp = element.FindPropertyRelative("m_nexts"); height += m_dialogueNodeNextListPropertyDrawer.GetHeight(nextsProp) + 2; height += 4; return(height); }
void DrawDialogueNodeElement(Rect rect, int index, bool isActive, bool isFocus) { if (!isRectInViewport(rect)) { return; } // Handle delete intermediate elements by code if (index >= dialogueNodeReorderableList.serializedProperty.arraySize) { return; } float prevLabelWidth = EditorGUIUtility.labelWidth; SerializedProperty finalBeginTextProp = serializedObject.FindProperty("m_finalBeginText"); DialogueText finalBeginText = (DialogueText)finalBeginTextProp.objectReferenceValue; SerializedProperty dialogueNodeProp = dialogueNodeReorderableList.serializedProperty.GetArrayElementAtIndex(index); SerializedProperty dialogueTextProp = dialogueNodeProp.FindPropertyRelative("m_dialogueText"); DialogueText dialogueText = (DialogueText)dialogueTextProp.objectReferenceValue; rect.y += 2; Rect dialogueTextRowColumn1Rect = new Rect(rect.x, rect.y, rect.width - 155, DialogueTextRefFieldHeight); Rect dialogueTextRowColumn2Rect = new Rect(rect.xMax - 60 - 90, rect.y, 90, DialogueTextRefFieldHeight); Rect dialogueTextRowColumn3Rect = new Rect(rect.xMax - 60, rect.y, 60, DialogueTextRefFieldHeight); bool isUnused = m_unusedDialogueTexts.Contains(dialogueText); if (isUnused) { Color originalBackgroundColor = GUI.backgroundColor; GUI.backgroundColor = Color.yellow; EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width - 205, DialogueTextRefFieldHeight), dialogueTextProp, GUIContent.none); GUI.backgroundColor = originalBackgroundColor; EditorGUI.BeginDisabledGroup(true); GUI.Button(new Rect(rect.xMax - 60 - 90 - 50, rect.y, 50, DialogueTextRefFieldHeight), "Unused", EditorStyles.miniButtonLeft); EditorGUI.EndDisabledGroup(); } else { EditorGUI.PropertyField(dialogueTextRowColumn1Rect, dialogueTextProp, GUIContent.none); } if (dialogueText != null) { bool isBeginText = dialogueText == finalBeginText; EditorGUI.BeginDisabledGroup(isBeginText); if (GUI.Button(dialogueTextRowColumn2Rect, isBeginText ? "Begin Text" : "As Begin Text", isUnused ? EditorStyles.miniButtonMid : EditorStyles.miniButtonLeft)) { finalBeginTextProp.objectReferenceValue = dialogueText; } EditorGUI.EndDisabledGroup(); if (GUI.Button(dialogueTextRowColumn3Rect, "De|ete", EditorStyles.miniButtonRight)) { if (EditorUtility.DisplayDialog("Delete Dialogue Node", "Are you sure you want to delete?", "Yes", "No")) { DeleteDialogueNode(index); serializedObject.ApplyModifiedProperties(); return; } } } else { if (GUI.Button(dialogueTextRowColumn2Rect, "New Text", EditorStyles.miniButtonLeft)) { DialogueText newDialogueText = PromptToCreate <DialogueText>("New Dialogue Text", "Dialogue Text"); dialogueTextProp.objectReferenceValue = newDialogueText; } if (GUI.Button(dialogueTextRowColumn3Rect, "De|ete", EditorStyles.miniButtonRight)) { if (EditorUtility.DisplayDialog("Delete Dialogue Node", "Are you sure you want to delete?", "Yes", "No")) { DeleteDialogueNode(index); serializedObject.ApplyModifiedProperties(); return; } } } rect.y += DialogueTextRefFieldHeight; if (dialogueText != null) { GUIStyle textAreaStyle = new GUIStyle(EditorStyles.textArea); textAreaStyle.wordWrap = true; dialogueText.text = EditorGUI.TextArea(new Rect(rect.x, rect.y, rect.width, DialogueTextAreaFieldHeight), dialogueText.text, textAreaStyle); EditorUtility.SetDirty(dialogueText); rect.y += DialogueTextAreaFieldHeight; } rect.y += 2; SerializedProperty assignmentsProp = dialogueNodeProp.FindPropertyRelative("m_assignments"); VariableAssignmentReorderableList dialogueNodeVariableAssignmentReorderableList = variableAssignmentListPropertyDrawerManager.GetReorderableList(assignmentsProp, "Change Variables"); float dialogueNodeVariableAssignmentReorderableListHeight = dialogueNodeVariableAssignmentReorderableList.GetHeight(); Rect dialogueNodeVariableAssignmentReorderableListRect = new Rect(rect.x, rect.y, rect.width, dialogueNodeVariableAssignmentReorderableListHeight); dialogueNodeVariableAssignmentReorderableList.DoList(dialogueNodeVariableAssignmentReorderableListRect); rect.y += dialogueNodeVariableAssignmentReorderableListHeight; rect.y += 2; GUIStyle optionsHeaderStyle = new GUIStyle(); optionsHeaderStyle.normal.background = new Texture2D(1, 1); optionsHeaderStyle.padding = EditorStyles.miniButtonLeft.padding; optionsHeaderStyle.alignment = TextAnchor.MiddleLeft; optionsHeaderStyle.normal.background.SetPixels(new Color[] { new Color(0.3f, 0.3f, 0.3f) }); optionsHeaderStyle.normal.background.Apply(); optionsHeaderStyle.normal.textColor = Color.white; Rect optionsHeaderRect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight); GUI.Label(optionsHeaderRect, "Options", optionsHeaderStyle); rect.y += optionsHeaderRect.height; rect.y += 2; SerializedProperty nextDialogueOptionsProp = dialogueNodeProp.FindPropertyRelative("m_options"); for (int i = 0; i < nextDialogueOptionsProp.arraySize; i++) { SerializedProperty nextDialogueOptionProp = nextDialogueOptionsProp.GetArrayElementAtIndex(i); SerializedProperty optionTextProp = nextDialogueOptionProp.FindPropertyRelative("m_dialogueOptionText"); DialogueOptionText optionText = (DialogueOptionText)optionTextProp.objectReferenceValue; EditorGUIUtility.labelWidth = 20.0f; EditorGUI.DrawRect(new Rect(rect.x, rect.y - 2, DialogueTextRefFieldHeight + 2, DialogueTextRefFieldHeight + 2), new Color(0.3f, 0.3f, 0.3f)); EditorGUI.PropertyField(new Rect(rect.x + 20, rect.y, 100, DialogueTextRefFieldHeight), optionTextProp, new GUIContent("\u2192")); if (optionText) { optionText.text = EditorGUI.TextField(new Rect(rect.x + 120, rect.y, rect.width - 180, DialogueTextRefFieldHeight), optionText.text); EditorUtility.SetDirty(optionText); } else { EditorGUI.BeginDisabledGroup(true); EditorGUI.TextField(new Rect(rect.x + 120, rect.y, rect.width - 280, DialogueTextRefFieldHeight), ""); EditorGUI.EndDisabledGroup(); if (GUI.Button(new Rect(rect.xMax - 60 - 100, rect.y, 100, DialogueTextRefFieldHeight), "New Option Text", EditorStyles.miniButtonMid)) { DialogueOptionText newOptionText = PromptToCreate <DialogueOptionText>("New Dialogue Option Text", "Dialogue Option Text"); if (newOptionText != null) { optionTextProp.objectReferenceValue = newOptionText; } } } if (GUI.Button(new Rect(rect.xMax - 60, rect.y, 60, DialogueTextRefFieldHeight), "De|ete", EditorStyles.miniButtonRight)) { if (EditorUtility.DisplayDialog("Delete Option", "Are you sure you want to delete?", "Yes", "No")) { DeleteOption(nextDialogueOptionsProp, i); return; } } rect.y += DialogueTextRefFieldHeight; rect.y += 2; SerializedProperty optionAssignmentsProp = nextDialogueOptionProp.FindPropertyRelative("m_assignments"); VariableAssignmentReorderableList optionVariableAssignmentReorderableList = variableAssignmentListPropertyDrawerManager.GetReorderableList(optionAssignmentsProp, "Change variables"); float optionVariableAssignmentReorderableListHeight = optionVariableAssignmentReorderableList.GetHeight(); Rect optionVariableAssignmentReorderableListRect = new Rect(rect.x + 20, rect.y, rect.width - 20, optionVariableAssignmentReorderableListHeight); EditorGUI.DrawRect(new Rect(rect.x, rect.y - 2, DialogueTextRefFieldHeight + 2, optionVariableAssignmentReorderableListHeight + 2), new Color(0.3f, 0.3f, 0.3f)); optionVariableAssignmentReorderableList.DoList(optionVariableAssignmentReorderableListRect); rect.y += optionVariableAssignmentReorderableListHeight; rect.y += 2; } EditorGUI.DrawRect(new Rect(rect.x, rect.y - 2, DialogueTextRefFieldHeight + 2, DialogueTextRefFieldHeight + 2), new Color(0.3f, 0.3f, 0.3f)); EditorGUI.LabelField(new Rect(rect.x + 20, rect.y, 20, ButtonRowHeight), "\u2192"); if (GUI.Button(new Rect(rect.x + 40, rect.y, rect.width - 40, ButtonRowHeight), "New Option", EditorStyles.miniButton)) { AddOption(nextDialogueOptionsProp); } rect.y += ButtonRowHeight; rect.y += 2; SerializedProperty nextsProp = dialogueNodeProp.FindPropertyRelative("m_nexts"); SerializedProperty finalNextProp = dialogueNodeProp.FindPropertyRelative("m_finalNext"); float nextsHeight = m_dialogueNodeNextListPropertyDrawer.GetHeight(nextsProp); Rect nextsRect = new Rect(rect.x, rect.y, rect.width, nextsHeight); m_dialogueNodeNextListPropertyDrawer.DrawDialogueNodeNexts( nextsRect, nextsProp, finalNextProp, "Branches"); rect.y += 2; rect.y += 10; EditorGUIUtility.labelWidth = prevLabelWidth; }
void OnEnable() { m_variableAssignmentsProp = serializedObject.FindProperty("m_variableAssignments"); m_reorderableList = new VariableAssignmentReorderableList(serializedObject, m_variableAssignmentsProp, "Static Variable Assignments"); }