CommandPanel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using TMPro;
  5. using UnityEngine.Events;
  6. [System.Serializable]
  7. public class CommandPanel : MonoBehaviour
  8. {
  9. [Header("コマンドパネルオブジェクト")]
  10. [SerializeField] GameObject CommandPanelObject;
  11. [Header("コマンドパネル背景")]
  12. [SerializeField] RectTransform CommandPanelBackGround;
  13. [Header("ボタン親")]
  14. [SerializeField] Transform buttonParent;
  15. private void Start()
  16. {
  17. if (!false)
  18. {
  19. #if !UNITY_EDITOR && UNITY_ANDROID
  20. CommandPanelObject.transform.localScale *= 1.5f;
  21. #endif
  22. }
  23. }
  24. public bool isActive()
  25. {
  26. return CommandPanelObject.gameObject.activeSelf;
  27. }
  28. public void SetUpCommandPanel(List<CardCommand> CardCommands, FieldPermanentCard fieldPokemonCard, HandCard handCard)
  29. {
  30. if (CardCommands.Count == 0)
  31. {
  32. return;
  33. }
  34. List<CardCommandButton> Buttons = new List<CardCommandButton>();
  35. for (int i = 0; i < buttonParent.childCount; i++)
  36. {
  37. Buttons.Add(new CardCommandButton(buttonParent.GetChild(i).GetComponent<Button>(), buttonParent.GetChild(i).GetChild(0).GetComponent<TextMeshProUGUI>()));
  38. }
  39. for (int i = 0; i < Buttons.Count; i++)
  40. {
  41. Buttons[i].CloseFieldUnitCommandButton();
  42. }
  43. for (int i = 0; i < Buttons.Count; i++)
  44. {
  45. if (i < CardCommands.Count)
  46. {
  47. Buttons[i].SetUpFieldUnitCommandButton(CardCommands[i].ButtonMessage, CardCommands[i].OnClickAction, CardCommands[i].Active, CardCommands[i].color);
  48. }
  49. else
  50. {
  51. break;
  52. }
  53. }
  54. //CommandPanelBackGround.sizeDelta = new Vector2(CommandPanelBackGround.sizeDelta.x, 4.6f * (FieldUnitCommands.Count + 1));
  55. GridLayoutGroup grid = CommandPanelObject.GetComponentInChildren<GridLayoutGroup>();
  56. float defaultWidth = 241.42f;
  57. int constraint = CardCommands.Count + 1;
  58. if (grid != null)
  59. {
  60. constraint = grid.constraintCount;
  61. }
  62. UnityEngine.Debug.Log($"PANEL WIDTH: {defaultWidth}, {CardCommands.Count}, {constraint}, {Mathf.CeilToInt((float)CardCommands.Count / (float)constraint)}");
  63. CommandPanelBackGround.sizeDelta = new Vector2(defaultWidth * Mathf.CeilToInt((float)CardCommands.Count / (float)constraint), 27.07f * (CardCommands.Count - 1) + 104.63f);
  64. if (fieldPokemonCard != null)
  65. {
  66. if (fieldPokemonCard.ThisPermanent != null)
  67. {
  68. if (fieldPokemonCard.ThisPermanent.IsSuspended)
  69. {
  70. CommandPanelObject.transform.localRotation = Quaternion.Euler(0, 0, 90);
  71. }
  72. else
  73. {
  74. CommandPanelObject.transform.localRotation = Quaternion.Euler(0, 0, 180);
  75. }
  76. }
  77. }
  78. else if (handCard != null)
  79. {
  80. CommandPanelObject.transform.localRotation = Quaternion.Euler(0, 0, 180);
  81. }
  82. if (handCard != null)
  83. {
  84. if (handCard.cardSource != null)
  85. {
  86. if(!CardEffectCommons.IsExistOnTrash(handCard.cardSource))
  87. CommandPanelObject.transform.localPosition = new Vector2(0f, 31f);
  88. else
  89. {
  90. CommandPanelObject.transform.localPosition = new Vector2(0f, -125f);
  91. CommandPanelObject.transform.localScale = new Vector3(4f, 4f, 1f);
  92. }
  93. }
  94. }
  95. CommandPanelObject.SetActive(true);
  96. }
  97. public void CloseCommandPanel()
  98. {
  99. if (CommandPanelObject != null)
  100. {
  101. CommandPanelObject.SetActive(false);
  102. }
  103. }
  104. }
  105. #region コマンド
  106. public class CardCommand
  107. {
  108. public CardCommand(string ButtonMessage, UnityAction OnClickAction, bool Active, Color color)
  109. {
  110. this.ButtonMessage = ButtonMessage;
  111. this.OnClickAction = OnClickAction;
  112. this.Active = Active;
  113. this.color = color;
  114. }
  115. public string ButtonMessage { get; set; }
  116. public UnityAction OnClickAction { get; set; }
  117. public bool Active { get; set; }
  118. public Color color { get; set; }
  119. }
  120. #endregion
  121. #region コマンドボタン
  122. public class CardCommandButton
  123. {
  124. public Button button;
  125. public TextMeshProUGUI ButtonText;
  126. public CardCommandButton(Button button, TextMeshProUGUI ButtonText)
  127. {
  128. this.button = button;
  129. this.ButtonText = ButtonText;
  130. }
  131. public void SetUpFieldUnitCommandButton(string ButtonMessage, UnityAction OnClickAtion, bool Active, Color color)
  132. {
  133. ButtonText.text = ButtonMessage;
  134. button.gameObject.SetActive(true);
  135. button.interactable = Active;
  136. button.image.color = color;
  137. button.onClick.RemoveAllListeners();
  138. if (Active)
  139. {
  140. button.onClick.AddListener(() => { OnClickAtion?.Invoke(); });
  141. }
  142. }
  143. public void CloseFieldUnitCommandButton()
  144. {
  145. button.gameObject.SetActive(false);
  146. }
  147. }
  148. #endregion