/// <summary> /// Performs a dialog action. /// </summary> /// <param name="actionIdx"></param> private void DoAction(int actionIdx) { EventSystem.current.SetSelectedGameObject(null); if (m_conversation != null && m_currentDialog != null && m_currentDialog.dialogActions.Count > actionIdx) { Dialog.DialogAction dialogAction = m_currentDialog.dialogActions[actionIdx]; Dialog nextDialog = m_conversation.FindDialogById(dialogAction.targetDialogId); if (dialogAction.onSubmit != null) { dialogAction.onSubmit.Invoke(); } PlayDialog(nextDialog); } else { DoOnCloseConversation(); } }
public DialogActionReorderableList(SerializedObject serializedObject, SerializedProperty dialogProp, Dialog dialog) : base(serializedObject, dialogProp.FindPropertyRelative("dialogActions"), true, true, true, true) { m_dialog = dialog; drawHeaderCallback += (rect) => { GUI.color = DialogColorUtils.GetColorWithHigherContrast(dialog.color, DialogEditorStyles.c_almostBlack, DialogEditorStyles.c_almostWhite); EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), "Dialog Actions", DialogEditorStyles.dialogHeader); GUI.color = Color.white; //NOTE: This is the only place where the ResetDraggedActionLinkIndex is called properly if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.Ignore) { ResetDraggedActionLinkIndex(); } if (Event.current.type == EventType.MouseDown) { s_focusedDialogRlist = this; } }; elementHeightCallback += (index) => { return(GetElementHeight(index)); }; drawFooterCallback += (rect) => { if (count == 0) { float elementHeight = this.elementHeight + 7f; Rect rList = new Rect(rect.x, rect.y - elementHeight, rect.width, elementHeight); if (Event.current.type == EventType.Repaint) { ReorderableList.defaultBehaviours.boxBackground.Draw(rList, false, false, false, false); } Rect rLabel = new Rect(rList.x + 4f, rList.y, rList.width, rList.height); EditorGUI.LabelField(rLabel, "No Actions / End Conversation"); } if (guiMode == eGUIMode.Scene) { GUI.backgroundColor = new Color(1f, 1f, 1f, .2f); defaultBehaviours.DrawFooter(rect, this); GUI.backgroundColor = Color.white; } else { defaultBehaviours.DrawFooter(rect, this); } }; drawElementCallback += (rect, index, isActive, isFocused) => { // NOTE: this should be done in Layout or it won't be updated in the SceveView until forcing a repaint, // but rect.width is negative in the InspectorView during the Layout event because its using DoLayoutList if (Event.current.type == m_updateRowWidthDuringEvent) { m_rowWidth = rect.width; } Dialog.DialogAction dialogAction = dialog.dialogActions[index]; Rect rectConnectionToggle = new Rect(rect.xMax - 10f, rect.y, 20f, EditorGUIUtility.singleLineHeight); m_connectTogglePositions.Add(rectConnectionToggle.center); GUI.color = DialogColorUtils.GetColorWithHigherContrast(dialog.color, DialogEditorStyles.c_almostBlack, DialogEditorStyles.c_almostWhite); GUI.Label(new Rect(rect.x, rect.y + 1f, 18, EditorGUIUtility.singleLineHeight), index.ToString(), DialogEditorStyles.dialogHeader); GUI.color = Color.white; var dialogActionProperty = serializedProperty.GetArrayElementAtIndex(index); var nameProperty = dialogActionProperty.FindPropertyRelative("name"); float namePropHeight = DialogEditorStyles.textArea.CalcHeight(new GUIContent(nameProperty.stringValue), m_rowWidth - 30f); float actionEventsPropertyHeight = 20;//NOTE: it looks that calculating height here is no necessary GetUnityEventPropertyHeight(onSubmitProperty) + GetUnityEventPropertyHeight(onPreProcessProperty); Rect rName = new Rect(rect.x + 20f, rect.y + 1f, rect.width - 30f, namePropHeight); Rect rActionEvents = new Rect(rect.x, rect.y + namePropHeight + 5f, rect.width, actionEventsPropertyHeight); if (nameProperty != null) { EditorGUIUtility.labelWidth = 40f; nameProperty.stringValue = EditorGUI.TextArea(rName, nameProperty.stringValue, DialogEditorStyles.textArea); if (guiMode == eGUIMode.Scene) { bool checkToggleDrag = Event.current.type == EventType.MouseDown && rectConnectionToggle.Contains(Event.current.mousePosition); GUI.Toggle(rectConnectionToggle, dialogAction.targetDialogId >= 0, "", EditorStyles.radioButton); if (Event.current.type == EventType.Used && checkToggleDrag) { m_draggedActionIdx = index; } } EditorGUIUtility.labelWidth = 0f; if (this.guiMode == eGUIMode.Inspector) { var onSubmitProperty = dialogActionProperty.FindPropertyRelative("onSubmit"); var onSubmit = dialog.dialogActions[index].onSubmit; var onPreProcessProperty = dialogActionProperty.FindPropertyRelative("onPreProcess"); var onPreProcess = dialog.dialogActions[index].onPreProcess; bool onSubmitIsDefined = onSubmit != null && onSubmit.GetPersistentEventCount() > 0; bool onPreProcessIsDefined = onPreProcess != null && onPreProcess.GetPersistentEventCount() > 0; if (onSubmitIsDefined) { EditorGUI.PropertyField(rActionEvents, onSubmitProperty); rActionEvents.position += Vector2.up * GetUnityEventPropertyHeight(onSubmitProperty); } if (onPreProcessIsDefined) { EditorGUI.PropertyField(rActionEvents, onPreProcessProperty); rActionEvents.position += Vector2.up * GetUnityEventPropertyHeight(onPreProcessProperty); } if (!onSubmitIsDefined || !onPreProcessIsDefined) { rActionEvents = new Rect(rActionEvents.center.x - 40f, rActionEvents.y, 80f, 16f); if (GUI.Button(rActionEvents, "Add Event...")) { GenericMenu addEventMenu = new GenericMenu(); if (!onSubmitIsDefined) { addEventMenu.AddItem(new GUIContent("Add onSubmit Event"), false, () => { UnityEventTools.AddPersistentListener(onSubmit); }); } if (!onPreProcessIsDefined) { addEventMenu.AddItem(new GUIContent("Add onPreProcess Event"), false, () => { UnityEventTools.AddPersistentListener(onPreProcess); }); } addEventMenu.ShowAsContext(); } } } } }; onAddCallback += (list) => { if (index < 0) { index = count - 1; } if (serializedProperty.arraySize == 0) { serializedProperty.arraySize++; } else { serializedProperty.InsertArrayElementAtIndex(Mathf.Max(index, 0)); } index = Mathf.Max(index + 1, 0); serializedProperty.GetArrayElementAtIndex(index).FindPropertyRelative("name").stringValue = "new action"; serializedProperty.GetArrayElementAtIndex(index).FindPropertyRelative("targetDialogId").intValue = -1; serializedObject.ApplyModifiedProperties(); }; onReorderCallback += (list) => { GUI.changed = true; }; }