CommandPanel.cs 5.1 KB

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