DialogueManager.cs 2.0 KB

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