ChatPanel.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. return;
  49. }
  50. if (Text_Dialogue.IsOver)
  51. {
  52. UIManager.Instance.PlayAudioClip("UI_Bubble");
  53. CurIndex++;
  54. DialogueConfig dialogueConfig = ConfigComponent.Instance.Get<DialogueConfig>(CurIndex);
  55. Text_Dialogue.StringContent = dialogueConfig.name;
  56. Text_Dialogue.SetContent();
  57. if (CurIndex % 2 == 0)
  58. {
  59. Image_NPC.gameObject.SetActive(false);
  60. Text_YK.gameObject.SetActive(true);
  61. }
  62. else
  63. {
  64. Image_NPC.gameObject.SetActive(true);
  65. Text_YK.gameObject.SetActive(false);
  66. }
  67. }
  68. }
  69. }
  70. }