ChatPanel.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using Excel2Json;
  2. using Mono.UI.Core;
  3. using Unity.VisualScripting;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7. namespace Mono
  8. {
  9. [UIBinding(prefab = "ChatPanel")]
  10. public class ChatPanel : UIPanel
  11. {
  12. public Button Btn_OnClick;
  13. public Typewriter Text_Dialogue;
  14. public int MaxIndex;
  15. public Transform Text_YK;
  16. public Transform Image_NPC;
  17. public override void GetUIData()
  18. {
  19. Btn_OnClick = UIData.Get<Button>("Btn_OnClick");
  20. Text_Dialogue = UIData.Get<Typewriter>("Text_Dialogue");
  21. Text_Dialogue.IsOver = true;
  22. MaxIndex = ConfigComponent.Instance.GetAll<DialogueConfig>().Length;
  23. Text_YK = UIData.Get<RectTransform>("Text_YK");
  24. Image_NPC = UIData.Get<RectTransform>("Image_NPC");
  25. }
  26. public override void AddButtonEvent()
  27. {
  28. Btn_OnClick.onClick.AddListener(() => { Dialogue(); });
  29. }
  30. public int CurIndex;
  31. public bool IsOver;
  32. public override void Show()
  33. {
  34. base.Show();
  35. Image_NPC.gameObject.SetActive(true);
  36. Text_YK.gameObject.SetActive(false);
  37. UIManager.Instance.PlayBGM("scene02");
  38. CurIndex = 0;
  39. Text_Dialogue.Showtext.text = "";
  40. Dialogue();
  41. }
  42. public void Dialogue()
  43. {
  44. if (CurIndex >= MaxIndex)
  45. {
  46. IsOver = true;
  47. UIManager.Instance.HideUIPanel<ChatPanel>();
  48. UIManager.Instance.LoadAndOpenPanel<InputPanel>(UIManager.UILayer.Middle);
  49. ShowTextPanel showTextPanel = UIManager.Instance.LoadAndOpenPanel<ShowTextPanel>(UIManager.UILayer.Middle);
  50. showTextPanel.ShowText(2);
  51. // TimeComponent.Instance.AddTimer(0.3f, () =>
  52. // {
  53. //
  54. // });
  55. return;
  56. }
  57. if (Text_Dialogue.IsOver)
  58. {
  59. UIManager.Instance.PlayAudioClip("UI_Bubble");
  60. CurIndex++;
  61. DialogueConfig dialogueConfig = ConfigComponent.Instance.Get<DialogueConfig>(CurIndex);
  62. Text_Dialogue.StringContent = dialogueConfig.name;
  63. Text_Dialogue.SetContent();
  64. if (CurIndex % 2 == 0)
  65. {
  66. Image_NPC.gameObject.SetActive(false);
  67. Text_YK.gameObject.SetActive(true);
  68. }
  69. else
  70. {
  71. Image_NPC.gameObject.SetActive(true);
  72. Text_YK.gameObject.SetActive(false);
  73. }
  74. }
  75. }
  76. }
  77. }