DialogueManager.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Collections.Generic;
  3. using Common.Utility.CombatEvent;
  4. using Core.Event.Event;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.Mono;
  8. using Fort23.UTool;
  9. using GameLogic.Bag;
  10. using UnityEngine;
  11. using Utility;
  12. public class DialogueManager : Singleton<DialogueManager>
  13. {
  14. private int currentDialogueID;
  15. private Action onDialogueComplete;
  16. private EventConfig eventConfig;
  17. IDialogueMono dialogue;
  18. public void CustomInit(IDialogueMono dialogueMono)
  19. {
  20. dialogue = dialogueMono;
  21. }
  22. /// <summary>
  23. /// 开始对话
  24. /// </summary>
  25. public void StartDialogue(int dialogueID, int eventId, Action onComplete = null)
  26. {
  27. currentDialogueID = dialogueID;
  28. onDialogueComplete = onComplete;
  29. eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventId);
  30. PlayDialogue(dialogueID);
  31. }
  32. private void PlayDialogue(int dialogueID)
  33. {
  34. currentDialogueID = dialogueID;
  35. EventSystemManager.Instance.CurrentEventList.curStep = currentDialogueID;
  36. AccountFileInfo.Instance.SavePlayerData();
  37. // 找到当前对话组
  38. var dialogueConfig = ConfigComponent.Instance.Get<EventConditionConfig>(dialogueID);
  39. if (dialogueConfig.ID == 0)
  40. {
  41. EndDialogue();
  42. return;
  43. }
  44. //挂机事件 弹出简单气泡对话
  45. if (eventConfig.EventTriggerType != 2)
  46. {
  47. dialogue.OpenDialoguePanel(dialogueConfig.ID, null, ShowDialogueEventData.MessageShowType.Verbatim, FishDialogue);
  48. }
  49. else
  50. {
  51. dialogue.OpenDialoguePanel(dialogueConfig.ID, FishDialogue);
  52. }
  53. }
  54. public void FishDialogue(int? selectedOptionID)
  55. {
  56. if (selectedOptionID.HasValue)
  57. {
  58. // 玩家选择了选项,处理结果
  59. SelectOption(selectedOptionID.Value);
  60. }
  61. else
  62. {
  63. // 无选
  64. EndDialogue1();
  65. }
  66. }
  67. /// <summary>
  68. /// 处理选项选择
  69. /// </summary>
  70. public void SelectOption(int optionID)
  71. {
  72. PlayDialogue(optionID);
  73. }
  74. /// <summary>
  75. /// 结束对话
  76. /// </summary>
  77. private async void EndDialogue1()
  78. {
  79. EventConditionConfig dialogueConfig = ConfigComponent.Instance.Get<EventConditionConfig>(currentDialogueID);
  80. switch (dialogueConfig.optionType)
  81. {
  82. //选项在这里不处理 在ui层处理 所有这里不是走到1 直接return
  83. case 1:
  84. EndDialogue();
  85. return;
  86. //进入战斗
  87. case 2:
  88. LogTool.Log("对话结束,进入战斗");
  89. break;
  90. //获得奖励
  91. case 3:
  92. List<ItemInfo> itemInfos = new List<ItemInfo>();
  93. for (var i = 0; i < dialogueConfig.PrizeIDs.Length; i++)
  94. {
  95. ItemInfo itemInfo = new ItemInfo(dialogueConfig.PrizeIDs[i], dialogueConfig.PrizeNums[i]);
  96. itemInfos.Add(itemInfo);
  97. }
  98. await dialogue.OpenRewardsPanel(itemInfos);
  99. LogTool.Log("对话结束,获得奖励");
  100. break;
  101. }
  102. //如果有下一个对话id 走下一个id
  103. if (dialogueConfig.ResultOptions != 0)
  104. {
  105. PlayDialogue(dialogueConfig.ResultOptions);
  106. }
  107. else
  108. {
  109. EndDialogue();
  110. }
  111. }
  112. /// <summary>
  113. /// 结束对话
  114. /// </summary>
  115. private void EndDialogue()
  116. {
  117. onDialogueComplete?.Invoke();
  118. }
  119. }