ChatPanel.cs 2.4 KB

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