DialogBox.cs 5.1 KB

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