| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- using UnityEngine.Events;
- [System.Serializable]
- public class CommandPanel : MonoBehaviour
- {
- [Header("コマンドパネルオブジェクト")]
- [SerializeField] GameObject CommandPanelObject;
- [Header("コマンドパネル背景")]
- [SerializeField] RectTransform CommandPanelBackGround;
- [Header("ボタン親")]
- [SerializeField] Transform buttonParent;
- bool first = false;
- private void Start()
- {
- if (!false)
- {
- first = true;
- #if !UNITY_EDITOR && UNITY_ANDROID
- CommandPanelObject.transform.localScale *= 1.5f;
- #endif
- }
- }
- public bool isActive()
- {
- return CommandPanelObject.gameObject.activeSelf;
- }
- public void SetUpCommandPanel(List<CardCommand> CardCommands, FieldPermanentCard fieldPokemonCard, HandCard handCard)
- {
- if (CardCommands.Count == 0)
- {
- return;
- }
- List<CardCommandButton> Buttons = new List<CardCommandButton>();
- for (int i = 0; i < buttonParent.childCount; i++)
- {
- Buttons.Add(new CardCommandButton(buttonParent.GetChild(i).GetComponent<Button>(), buttonParent.GetChild(i).GetChild(0).GetComponent<TextMeshProUGUI>()));
- }
- for (int i = 0; i < Buttons.Count; i++)
- {
- Buttons[i].CloseFieldUnitCommandButton();
- }
- for (int i = 0; i < Buttons.Count; i++)
- {
- if (i < CardCommands.Count)
- {
- Buttons[i].SetUpFieldUnitCommandButton(CardCommands[i].ButtonMessage, CardCommands[i].OnClickAction, CardCommands[i].Active, CardCommands[i].color);
- }
- else
- {
- break;
- }
- }
- //CommandPanelBackGround.sizeDelta = new Vector2(CommandPanelBackGround.sizeDelta.x, 4.6f * (FieldUnitCommands.Count + 1));
- GridLayoutGroup grid = CommandPanelObject.transform.GetChild(1).GetComponent<GridLayoutGroup>();
- float defaultWidth = 241.42f;
- int constraint = CardCommands.Count + 1;
- if (grid != null)
- {
- constraint = grid.constraintCount;
- }
- CommandPanelBackGround.sizeDelta = new Vector2(defaultWidth * (((CardCommands.Count - 1) / constraint) + 1), 27.07f * (CardCommands.Count - 1) + 104.63f);
- if (fieldPokemonCard != null)
- {
- if (fieldPokemonCard.ThisPermanent != null)
- {
- if (fieldPokemonCard.ThisPermanent.IsSuspended)
- {
- CommandPanelObject.transform.localRotation = Quaternion.Euler(0, 0, 90);
- }
- else
- {
- CommandPanelObject.transform.localRotation = Quaternion.Euler(0, 0, 180);
- }
- }
- }
- else if (handCard != null)
- {
- CommandPanelObject.transform.localRotation = Quaternion.Euler(0, 0, 180);
- }
- if (handCard != null)
- {
- if (handCard.cardSource != null)
- {
- if(!CardEffectCommons.IsExistOnTrash(handCard.cardSource))
- CommandPanelObject.transform.localPosition = new Vector2(0f, 31f);
- else
- {
- CommandPanelObject.transform.localPosition = new Vector2(0f, -125f);
- CommandPanelObject.transform.localScale = new Vector3(4f, 4f, 1f);
- }
- }
- }
- CommandPanelObject.SetActive(true);
- }
- public void CloseCommandPanel()
- {
- if (CommandPanelObject != null)
- {
- CommandPanelObject.SetActive(false);
- }
- }
- }
- #region コマンド
- public class CardCommand
- {
- public CardCommand(string ButtonMessage, UnityAction OnClickAction, bool Active, Color color)
- {
- this.ButtonMessage = ButtonMessage;
- this.OnClickAction = OnClickAction;
- this.Active = Active;
- this.color = color;
- }
- public string ButtonMessage { get; set; }
- public UnityAction OnClickAction { get; set; }
- public bool Active { get; set; }
- public Color color { get; set; }
- }
- #endregion
- #region コマンドボタン
- public class CardCommandButton
- {
- public Button button;
- public TextMeshProUGUI ButtonText;
- public CardCommandButton(Button button, TextMeshProUGUI ButtonText)
- {
- this.button = button;
- this.ButtonText = ButtonText;
- }
- public void SetUpFieldUnitCommandButton(string ButtonMessage, UnityAction OnClickAtion, bool Active, Color color)
- {
- ButtonText.text = ButtonMessage;
- button.gameObject.SetActive(true);
- button.interactable = Active;
- button.image.color = color;
- button.onClick.RemoveAllListeners();
- if (Active)
- {
- button.onClick.AddListener(() => { OnClickAtion?.Invoke(); });
- }
- }
- public void CloseFieldUnitCommandButton()
- {
- button.gameObject.SetActive(false);
- }
- }
- #endregion
|