ChatPanel.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. }
  36. public void Dialogue()
  37. {
  38. if (CurIndex >= MaxIndex)
  39. {
  40. IsOver = true;
  41. UIManager.Instance.HideUIPanel<ChatPanel>();
  42. UIManager.Instance.LoadAndOpenPanel<InputPanel>(UIManager.UILayer.Middle);
  43. return;
  44. }
  45. if (Text_Dialogue.IsOver)
  46. {
  47. CurIndex++;
  48. DialogueConfig dialogueConfig = ConfigComponent.Instance.Get<DialogueConfig>(CurIndex);
  49. Text_Dialogue.StringContent = dialogueConfig.name;
  50. Text_Dialogue.SetContent();
  51. if (CurIndex % 2 == 0)
  52. {
  53. Image_NPC.gameObject.SetActive(false);
  54. Text_YK.gameObject.SetActive(true);
  55. }
  56. else
  57. {
  58. Image_NPC.gameObject.SetActive(true);
  59. Text_YK.gameObject.SetActive(false);
  60. }
  61. }
  62. }
  63. }
  64. }