CommandPanel.cs 5.0 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.transform.GetChild(1).GetComponent<GridLayoutGroup>();
  59. float defaultWidth = 241.42f;
  60. int constraint = CardCommands.Count + 1;
  61. if (grid != null)
  62. {
  63. constraint = grid.constraintCount;
  64. }
  65. CommandPanelBackGround.sizeDelta = new Vector2(defaultWidth * (((CardCommands.Count - 1) / constraint) + 1), 27.07f * (CardCommands.Count - 1) + 104.63f);
  66. if (fieldPokemonCard != null)
  67. {
  68. if (fieldPokemonCard.ThisPermanent != null)
  69. {
  70. if (fieldPokemonCard.ThisPermanent.IsSuspended)
  71. {
  72. CommandPanelObject.transform.localRotation = Quaternion.Euler(0, 0, 90);
  73. }
  74. else
  75. {
  76. CommandPanelObject.transform.localRotation = Quaternion.Euler(0, 0, 180);
  77. }
  78. }
  79. }
  80. else if (handCard != null)
  81. {
  82. CommandPanelObject.transform.localRotation = Quaternion.Euler(0, 0, 180);
  83. }
  84. if (handCard != null)
  85. {
  86. if (handCard.cardSource != null)
  87. {
  88. if(!CardEffectCommons.IsExistOnTrash(handCard.cardSource))
  89. CommandPanelObject.transform.localPosition = new Vector2(0f, 31f);
  90. else
  91. {
  92. CommandPanelObject.transform.localPosition = new Vector2(0f, -125f);
  93. CommandPanelObject.transform.localScale = new Vector3(4f, 4f, 1f);
  94. }
  95. }
  96. }
  97. CommandPanelObject.SetActive(true);
  98. }
  99. public void CloseCommandPanel()
  100. {
  101. if (CommandPanelObject != null)
  102. {
  103. CommandPanelObject.SetActive(false);
  104. }
  105. }
  106. }
  107. #region コマンド
  108. public class CardCommand
  109. {
  110. public CardCommand(string ButtonMessage, UnityAction OnClickAction, bool Active, Color color)
  111. {
  112. this.ButtonMessage = ButtonMessage;
  113. this.OnClickAction = OnClickAction;
  114. this.Active = Active;
  115. this.color = color;
  116. }
  117. public string ButtonMessage { get; set; }
  118. public UnityAction OnClickAction { get; set; }
  119. public bool Active { get; set; }
  120. public Color color { get; set; }
  121. }
  122. #endregion
  123. #region コマンドボタン
  124. public class CardCommandButton
  125. {
  126. public Button button;
  127. public TextMeshProUGUI ButtonText;
  128. public CardCommandButton(Button button, TextMeshProUGUI ButtonText)
  129. {
  130. this.button = button;
  131. this.ButtonText = ButtonText;
  132. }
  133. public void SetUpFieldUnitCommandButton(string ButtonMessage, UnityAction OnClickAtion, bool Active, Color color)
  134. {
  135. ButtonText.text = ButtonMessage;
  136. button.gameObject.SetActive(true);
  137. button.interactable = Active;
  138. button.image.color = color;
  139. button.onClick.RemoveAllListeners();
  140. if (Active)
  141. {
  142. button.onClick.AddListener(() => { OnClickAtion?.Invoke(); });
  143. }
  144. }
  145. public void CloseFieldUnitCommandButton()
  146. {
  147. button.gameObject.SetActive(false);
  148. }
  149. }
  150. #endregion