DialogueManager.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Common.Utility.CombatEvent;
  5. using Excel2Json;
  6. using Fort23.Mono;
  7. using Fort23.UTool;
  8. using UnityEngine;
  9. using Utility;
  10. public class DialogueManager : Singleton<DialogueManager>
  11. {
  12. private readonly EventSystemManager eventManager;
  13. private int currentDialogueID;
  14. private int currentNodeID;
  15. private int currentEventID;
  16. private List<DialogueConfig> dialogueConfigs;
  17. private List<DialogueOptionConfig> dialogueOptionConfigs;
  18. public void CustomInit()
  19. {
  20. dialogueConfigs = ConfigComponent.Instance.GetAll<DialogueConfig>().ToList();
  21. dialogueOptionConfigs = ConfigComponent.Instance.GetAll<DialogueOptionConfig>().ToList();
  22. }
  23. /// <summary>
  24. /// 开始对话
  25. /// </summary>
  26. public void StartDialogue(int dialogueID, int eventID)
  27. {
  28. currentDialogueID = dialogueID;
  29. currentNodeID = 1;
  30. currentEventID = eventID;
  31. ShowDialogue();
  32. }
  33. /// <summary>
  34. /// 显示当前对话
  35. /// </summary>
  36. private void ShowDialogue()
  37. {
  38. //找到当前对话组
  39. var dialogueConfig = dialogueConfigs.Find(n =>
  40. n.ID == currentDialogueID && n.GroupId == currentNodeID);
  41. if (dialogueConfig.ID == 0)
  42. {
  43. EndDialogue();
  44. return;
  45. }
  46. //todo 加载对话ui
  47. DialoguePanel.OpenDialoguePanel(dialogueConfig.Content, null, ShowDialogueEventData.MessageShowType.Default, () =>
  48. {
  49. });
  50. currentNodeID++;
  51. }
  52. /// <summary>
  53. /// 处理选项选择,跳转节点或触发逻辑。
  54. /// </summary>
  55. /// <param name="optionID">选项ID</param>
  56. public void SelectOption(int optionID)
  57. {
  58. var option = dialogueOptionConfigs.Find(o => o.ID == optionID);
  59. if (option.ID == 0)
  60. {
  61. EndDialogue();
  62. return;
  63. }
  64. if (option.DialogueConfigID > 0)
  65. {
  66. currentNodeID = option.DialogueConfigID;
  67. ShowDialogue();
  68. }
  69. else
  70. {
  71. EndDialogue();
  72. }
  73. }
  74. /// <summary>
  75. /// 结束对话
  76. /// </summary>
  77. private void EndDialogue()
  78. {
  79. }
  80. }