ChatPanel.cs 2.7 KB

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