DialogueManager.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. }
  46. /// <summary>
  47. /// 处理选项选择,跳转节点或触发逻辑。
  48. /// </summary>
  49. /// <param name="optionID">选项ID</param>
  50. public void SelectOption(int optionID)
  51. {
  52. var option = dialogueOptionConfigs.Find(o => o.ID == optionID);
  53. if (option.ID == 0)
  54. {
  55. EndDialogue();
  56. return;
  57. }
  58. if (option.DialogueConfigID > 0)
  59. {
  60. currentNodeID = option.DialogueConfigID;
  61. ShowDialogue();
  62. }
  63. else
  64. {
  65. EndDialogue();
  66. }
  67. }
  68. /// <summary>
  69. /// 结束对话
  70. /// </summary>
  71. private void EndDialogue()
  72. {
  73. }
  74. }