DialogBox.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using Core.Language;
  3. using Excel2Json;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using Mono.Utility;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. namespace Fort23.Mono
  10. {
  11. public class DialogBox
  12. {
  13. /// <summary>
  14. /// 对话内容.
  15. /// </summary>
  16. public Text Content;
  17. public Text Text_Dialogue01;
  18. public Text Text_Dialogue02;
  19. public Text Text_Dialogue03;
  20. public Text Text_Dialogue04;
  21. // public BoxCollider boxCol;
  22. public Transform MessageBG;
  23. public Transform di;
  24. public MyImage NpcIcon;
  25. public MyImage HeroIcon;
  26. private BetterList<string> dialogTextList;
  27. private int curIdx;
  28. public Action onAction;
  29. public UISpiritLoader UISpiritLoader;
  30. public Text NpcNameText;
  31. public void Init()
  32. {
  33. GuidePanel guidePanel = UIManager.Instance.GetComponent<GuidePanel>();
  34. // guidePanel.DialogBoxState.gameObject.SetActive(true);
  35. NpcIcon = guidePanel.Image_Npc;
  36. HeroIcon = guidePanel.HeroIcon;
  37. MessageBG = guidePanel.MessageBG;
  38. UISpiritLoader = NpcIcon.transform.parent.GetComponent<UISpiritLoader>();
  39. NpcNameText = guidePanel.Text_NpcName;
  40. Text_Dialogue01 = guidePanel.Text_Dialogue01;
  41. Text_Dialogue02 = guidePanel.Text_Dialogue02;
  42. Text_Dialogue03 = guidePanel.Text_Dialogue03;
  43. Text_Dialogue04 = guidePanel.Text_Dialogue04;
  44. }
  45. public void Open(BetterList<string> list, Action action)
  46. {
  47. GuidePanel guidePanel = UIManager.Instance.GetComponent<GuidePanel>();
  48. guidePanel.DialogBoxState.gameObject.SetActive(true);
  49. if (list == null || list.size <= 0)
  50. {
  51. Close();
  52. return;
  53. }
  54. if (action == null) Debug.Log("action == null");
  55. onAction = action;
  56. curIdx = 0;
  57. dialogTextList = list;
  58. OnClickScreen();
  59. }
  60. // private AssetHandle assetHandle;
  61. /// <summary>
  62. ///
  63. /// </summary>
  64. /// <param name="playerGuideConfig"></param>
  65. /// <param name="id">1:默认 2:剧情1 3:boss</param>
  66. public async CTask SetDiTex(PlayerGuideConfig playerGuideConfig, int id)
  67. {
  68. EventNPC heroModelConfig = ConfigComponent.Instance.Get<EventNPC>(id);
  69. NpcIcon.gameObject.SetActive(false);
  70. CTask cTask = CTask.Create();
  71. NpcIcon.onSpriteAlter = () =>
  72. {
  73. NpcIcon.SetNativeSize();
  74. NpcIcon.gameObject.SetActive(true);
  75. cTask.SetResult();
  76. };
  77. NpcIcon.icon_name = heroModelConfig.icon;
  78. NpcNameText.text = LanguageManager.Instance.Text(heroModelConfig.name);
  79. // HeroIcon.icon_name = heroModelConfig.HeroUIIconName;
  80. if (playerGuideConfig.reversalBox == 1)
  81. {
  82. NpcIcon.transform.rotation = Quaternion.Euler(0, 180, 0);
  83. }
  84. else
  85. {
  86. NpcIcon.transform.rotation = Quaternion.Euler(0, 0, 0);
  87. }
  88. // NpcNameText.text = LanguageManager.Instance.Text(heroModelConfig.HeroNameID);
  89. NpcIcon.enabled = true;
  90. await cTask;
  91. }
  92. public void OnClickScreen()
  93. {
  94. // for (int i = 0; i < 100; i++)
  95. // {
  96. //
  97. // }
  98. if (dialogTextList == null)
  99. {
  100. return;
  101. }
  102. if (dialogTextList.size > curIdx)
  103. {
  104. Content.text = dialogTextList[curIdx++];
  105. //最后一条
  106. if (dialogTextList.size == curIdx)
  107. {
  108. if (PlayerGuideManager.Instance.guideConfig.forceText == 0)
  109. {
  110. // PlayerGuideManager.Instance.SetFingerVisiable(true);
  111. PlayerGuideManager.Instance.CanDoNextCTask = CTask.Create();
  112. onAction?.Invoke();
  113. onAction = null;
  114. PlayerGuideManager.Instance.CanDoNextCTask.SetResult();
  115. }
  116. }
  117. }
  118. else
  119. {
  120. PlayerGuideManager.Instance.CanDoNextCTask = CTask.Create();
  121. onAction?.Invoke();
  122. onAction = null;
  123. PlayerGuideManager.Instance.CanDoNextCTask.SetResult();
  124. }
  125. }
  126. public void Close()
  127. {
  128. PlayerGuideManager.Instance.CanDoNextCTask = CTask.Create();
  129. onAction?.Invoke();
  130. onAction = null;
  131. PlayerGuideManager.Instance.CanDoNextCTask.SetResult();
  132. }
  133. public void ChangeState(int guideConfigSpeakerStyle)
  134. {
  135. switch (guideConfigSpeakerStyle)
  136. {
  137. case 1:
  138. Content = Text_Dialogue01;
  139. break;
  140. case 2:
  141. Content = Text_Dialogue02;
  142. break;
  143. case 3:
  144. Content = Text_Dialogue03;
  145. break;
  146. case 4:
  147. Content = Text_Dialogue04;
  148. break;
  149. }
  150. }
  151. }
  152. }