| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System.Linq;
- using UnityEngine.Events;
- using Shapes2D;
- using System;
- using Coffee.UIEffects;
- using UnityEngine.EventSystems;
- using TMPro;
- public class CardPrefab_CreateDeck : MonoBehaviour
- {
- [Header("Card Image")]
- public Image CardImage;
- [Header("Scroll Rect")]
- public List<ScrollRect> scroll = new List<ScrollRect>();
- [Header("Cover")]
- public List<GameObject> Cover = new List<GameObject>();
- [Header("Cover Standard")]
- public GameObject Cover_Standard;
- [Header("Outline")]
- public GameObject Outline;
- [Header("Anim")]
- public Animator anim;
- [Header("Cost Icons")]
- public List<Image> CostIcons = new List<Image>();
- [Header("Cost Text")]
- public TextMeshProUGUI CostText;
- [Header("Level Icons")]
- public List<Image> LevelIcons;
- [Header("Level Text")]
- public TextMeshProUGUI LevelText;
- [Header("Evo Cost Icons")]
- public List<Image> EvoCostIcons;
- [Header("Evo Cost Text Level")]
- public List<TextMeshProUGUI> EvoCostTexts_Level;
- [Header("Evo Cost Text Memory")]
- public List<TextMeshProUGUI> EvoCostTexts_Memory;
- [Header("Quantity Limit")]
- public GameObject LimitObject;
- public Text LimitText;
- [Header("Ban")]
- public GameObject BanObject;
- [Header("White Circle")]
- public Sprite WhiteCircle;
- [Header("Rainbow Circle")]
- public Sprite RainbowCircle;
- public Transform Parent;
- public CEntity_Base cEntity_Base { get; set; }
- public UnityAction OnClickAction;
- public UnityAction<CardPrefab_CreateDeck> OnEnterAction;
- public UnityAction<CardPrefab_CreateDeck> OnExitAction;
- public UnityAction<CardPrefab_CreateDeck> OnBeginDragAction;
- public bool isActive = true;
- public GameObject AddRemoveButtonParent;
- public Button AddButton;
- public Button RemoveButton;
- public UIShiny uIShiny;
- private void Start()
- {
- Outline.SetActive(false);
- if (CardImage.GetComponent<UIShiny>() != null)
- {
- CardImage.GetComponent<UIShiny>().enabled = false;
- }
- OffAddRemoveButton();
- if (CostText != null)
- {
- CostText.transform.parent.gameObject.SetActive(false);
- }
- if (LevelText != null)
- {
- LevelText.transform.parent.gameObject.SetActive(false);
- }
- if (EvoCostIcons != null)
- {
- if (EvoCostIcons.Count >= 1)
- {
- for (int i = 0; i < EvoCostIcons.Count; i++)
- {
- EvoCostIcons[i].transform.parent.gameObject.SetActive(false);
- EvoCostIcons[i].transform.parent.parent.gameObject.SetActive(true);
- }
- }
- }
- if (LimitObject != null)
- {
- LimitObject.SetActive(false);
- }
- if (BanObject != null)
- {
- BanObject.SetActive(false);
- }
- }
- public UnityAction<CardPrefab_CreateDeck> OnClickAddButtonAction;
- public void OnClickAddButton()
- {
- OnClickAddButtonAction?.Invoke(this);
- }
- public UnityAction<CardPrefab_CreateDeck> OnClickRemoveButtonAction;
- public void OnClickRemoveButton()
- {
- OnClickRemoveButtonAction?.Invoke(this);
- }
- public void SetupAddRemoveButton(DeckData deckData)
- {
- #if !UNITY_EDITOR && UNITY_ANDROID
- return;
- #endif
- if (AddRemoveButtonParent != null)
- {
- AddRemoveButtonParent.SetActive(true);
- }
- bool AddButtonInteractable = false;
- if (deckData != null && cEntity_Base != null)
- {
- AddButtonInteractable = !CanNotAddThisCard(deckData);
- }
- if (AddButton != null)
- {
- AddButton.interactable = AddButtonInteractable;
- AddButton.transform.parent.gameObject.SetActive(AddButtonInteractable);
- }
- if (transform.parent != null)
- {
- for (int i = 0; i < transform.parent.childCount; i++)
- {
- CardPrefab_CreateDeck cardPrefab_CreateDeck = transform.parent.GetChild(i).GetComponent<CardPrefab_CreateDeck>();
- if (cardPrefab_CreateDeck != null && cardPrefab_CreateDeck != this)
- {
- cardPrefab_CreateDeck.OffAddRemoveButton();
- }
- }
- }
- }
- public void OffAddRemoveButton()
- {
- if (AddRemoveButtonParent != null)
- {
- AddRemoveButtonParent.SetActive(false);
- }
- }
- public void SetUpCardPrefab_CreateDeck(CEntity_Base _cEntity_Base)
- {
- cEntity_Base = _cEntity_Base;
- //ShowCardImage();
- }
- public async void ShowCardImage()
- {
- if (this.cEntity_Base != null)
- {
- //カード画像
- CardImage.color = new Color(1, 1, 1, 1);
- CardImage.GetComponent<EventTrigger>().enabled = true;
- CardImage.sprite = await cEntity_Base.GetCardSprite();
- if (CostText != null)
- {
- if (cEntity_Base.cardKind != CardKind.DigiEgg)
- {
- for (int i = 0; i < CostIcons.Count; i++)
- {
- int cardColorIndex = i < cEntity_Base.cardColors.Count ? i : 0;
- CardColor cardColor = cEntity_Base.cardColors[cardColorIndex];
- CostIcons[i].sprite = DataBase.instance.ColorIcons_circle[(int)cardColor];
- }
- CostText.color = Color.white;
- CostText.transform.parent.gameObject.SetActive(true);
- CostText.text = $"{cEntity_Base.PlayCost}";
- }
- else
- {
- CostText.transform.parent.gameObject.SetActive(false);
- }
- }
- if (LevelIcons != null)
- {
- if ((cEntity_Base.cardKind == CardKind.Digimon || cEntity_Base.cardKind == CardKind.DigiEgg) && cEntity_Base.Level >= 1)
- {
- if (LevelIcons.Count >= 1)
- {
- for (int i = 0; i < CostIcons.Count; i++)
- {
- int cardColorIndex = i < cEntity_Base.cardColors.Count ? i : 0;
- CardColor cardColor = cEntity_Base.cardColors[cardColorIndex];
- LevelIcons[i].sprite = DataBase.instance.ColorIcons_bar[(int)cardColor];
- }
- LevelText.color = Color.white;
- LevelText.transform.parent.gameObject.SetActive(true);
- LevelText.text = $"Lv.{cEntity_Base.Level}";
- }
- }
- else
- {
- LevelText.transform.parent.gameObject.SetActive(false);
- }
- }
- if (EvoCostIcons != null)
- {
- if (cEntity_Base.cardKind == CardKind.Digimon)
- {
- if (EvoCostIcons.Count >= 1)
- {
- for (int i = 0; i < EvoCostIcons.Count; i++)
- {
- if (i < cEntity_Base.EvoCosts.Count)
- {
- EvoCostIcons[i].sprite = WhiteCircle;
- EvoCostIcons[i].transform.parent.gameObject.SetActive(true);
- CardColor cardColor = CardColor.None;
- cardColor = cEntity_Base.EvoCosts[i].CardColor;
- EvoCostIcons[i].color = DataBase.CardColor_ColorDarkDictionary[cardColor];
- EvoCostTexts_Level[i].text = $"Lv.{cEntity_Base.EvoCosts[i].Level}";
- EvoCostTexts_Memory[i].text = $"{cEntity_Base.EvoCosts[i].MemoryCost}";
- if (cardColor == CardColor.Yellow || cardColor == CardColor.White)
- {
- EvoCostTexts_Level[i].color = Color.black;
- EvoCostTexts_Memory[i].color = Color.black;
- }
- else
- {
- EvoCostTexts_Level[i].color = Color.white;
- EvoCostTexts_Memory[i].color = Color.white;
- }
- }
- else
- {
- EvoCostIcons[i].transform.parent.gameObject.SetActive(false);
- }
- }
- if (cEntity_Base.EvoCosts.Count == 7)
- {
- int cost = cEntity_Base.EvoCosts[0].MemoryCost;
- int level = cEntity_Base.EvoCosts[0].Level;
- bool sameCost = true;
- for (int i = 0; i < cEntity_Base.EvoCosts.Count; i++)
- {
- if (cEntity_Base.EvoCosts[i].MemoryCost != cost || cEntity_Base.EvoCosts[i].Level != level)
- {
- sameCost = false;
- break;
- }
- }
- if (sameCost)
- {
- for (int i = 0; i < EvoCostIcons.Count; i++)
- {
- EvoCostIcons[i].transform.parent.gameObject.SetActive(false);
- if (i == 0)
- {
- EvoCostIcons[i].sprite = RainbowCircle;
- EvoCostIcons[i].transform.parent.gameObject.SetActive(true);
- EvoCostIcons[i].color = Color.white;
- EvoCostTexts_Level[i].text = $"Lv.{cEntity_Base.EvoCosts[i].Level}";
- EvoCostTexts_Memory[i].text = $"{cEntity_Base.EvoCosts[i].MemoryCost}";
- EvoCostTexts_Level[i].color = Color.white;
- EvoCostTexts_Memory[i].color = Color.white;
- }
- }
- }
- }
- }
- }
- else
- {
- for (int i = 0; i < EvoCostIcons.Count; i++)
- {
- EvoCostIcons[i].transform.parent.gameObject.SetActive(false);
- }
- }
- }
- if (LimitObject != null && BanObject != null && LimitText != null)
- {
- LimitObject.SetActive(false);
- BanObject.SetActive(false);
- int maxCount = DeckBuildingRule.MaxCount_BanList(cEntity_Base);
- if (maxCount < cEntity_Base.MaxCountInDeck)
- {
- if (maxCount >= 1)
- {
- LimitObject.SetActive(true);
- LimitText.gameObject.SetActive(true);
- LimitText.text = $"{maxCount}";
- }
- else if (maxCount == 0)
- {
- BanObject.SetActive(true);
- }
- }
- }
- }
- }
- public void HideDeckCardTab()
- {
- CardImage.color = new Color(1, 1, 1, 0);
- CardImage.GetComponent<EventTrigger>().enabled = false;
- Outline.SetActive(false);
- if (CardImage.GetComponent<UIShiny>() != null)
- {
- CardImage.GetComponent<UIShiny>().enabled = false;
- }
- if (CostText != null)
- {
- CostText.transform.parent.gameObject.SetActive(false);
- }
- if (LevelText != null)
- {
- LevelText.transform.parent.gameObject.SetActive(false);
- }
- if (EvoCostIcons != null)
- {
- if (EvoCostIcons.Count >= 1)
- {
- for (int i = 0; i < EvoCostIcons.Count; i++)
- {
- EvoCostIcons[i].transform.parent.gameObject.SetActive(false);
- }
- }
- }
- }
- public void SetCover(bool active)
- {
- foreach (GameObject g in Cover)
- {
- g.SetActive(active);
- }
- }
- public void CheckCover(DeckData deckData)
- {
- SetCover(CanNotAddThisCard(deckData));
- }
- public bool CanNotAddThisCard(DeckData deckData)
- {
- if (deckData.DeckCards().Count >= 70)
- {
- return true;
- }
- if (deckData.DigitamaDeckCards().Count >= 10)
- {
- return true;
- }
- if (cEntity_Base != null)
- {
- if (cEntity_Base.cardKind == CardKind.DigiEgg)
- {
- if (cEntity_Base.SameCardIDCount(deckData.DigitamaDeckCards()) >= cEntity_Base.MaxCountInDeck)
- {
- return true;
- }
- }
- else
- {
- if (cEntity_Base.SameCardIDCount(deckData.DeckCards()) >= cEntity_Base.MaxCountInDeck)
- {
- return true;
- }
- }
- if (!DeckBuildingRule.CanAddCard(cEntity_Base, deckData))
- {
- return true;
- }
- }
- return false;
- }
- public void OnClick()
- {
- OnClickAction?.Invoke();
- }
- public void OnBeginDrag()
- {
- OnBeginDragAction?.Invoke(this);
- }
- float _timer = 0f;
- private void Update()
- {
- if (AddRemoveButtonParent.activeSelf)
- {
- _OnEnter();
- }
- _timer += Time.deltaTime;
- if (_timer > Time.deltaTime * 6)
- {
- _timer = 0f;
- if (isActive && CardImage.gameObject.activeSelf)
- {
- if (cEntity_Base != null && Cover_Standard != null)
- {
- Cover_Standard.SetActive(!cEntity_Base.IsStandardValid);
- }
- }
- }
- }
- public Coroutine _OnEnterCoroutine = null;
- public void OnEnter()
- {
- Outline.SetActive(true);
- anim.SetInteger("Open", 1);
- anim.SetInteger("Close", 0);
- uIShiny.enabled = true;
- _OnEnter();
- }
- IEnumerator OnEnterCoroutine()
- {
- int count = 0;
- while (true)
- {
- yield return new WaitForSeconds(Time.deltaTime);
- bool isRay = false;
- List<RaycastResult> results = new List<RaycastResult>();
- PointerEventData pointer = new PointerEventData(EventSystem.current);
- // マウスポインタの位置にレイ飛ばし、ヒットしたものを保存
- pointer.position = Input.mousePosition;
- EventSystem.current.RaycastAll(pointer, results);
- // ヒットしたUIの名前
- foreach (RaycastResult target in results)
- {
- if (target.gameObject == this.CardImage.gameObject)
- {
- isRay = true;
- }
- }
- if (isRay)
- {
- _OnEnter();
- count++;
- if (count > 10)
- {
- _OnEnterCoroutine = null;
- yield break;
- }
- }
- }
- }
- public void _OnEnter()
- {
- OnEnterAction?.Invoke(this);
- }
- public void OnExit()
- {
- #if !UNITY_EDITOR && UNITY_ANDROID
- _OnExit();
- return;
- #endif
- return;
- bool isRay = false;
- List<RaycastResult> results = new List<RaycastResult>();
- PointerEventData pointer = new PointerEventData(EventSystem.current);
- // マウスポインタの位置にレイ飛ばし、ヒットしたものを保存
- pointer.position = Input.mousePosition;
- EventSystem.current.RaycastAll(pointer, results);
- // ヒットしたUIの名前
- foreach (RaycastResult target in results)
- {
- if (target.gameObject == AddButton.gameObject || target.gameObject == RemoveButton.gameObject)
- {
- return;
- }
- }
- _OnExit();
- //StartCoroutine(OnExitCoroutine());
- }
- IEnumerator OnExitCoroutine()
- {
- while (true)
- {
- yield return new WaitForSeconds(Time.deltaTime);
- bool isRay = false;
- List<RaycastResult> results = new List<RaycastResult>();
- PointerEventData pointer = new PointerEventData(EventSystem.current);
- // マウスポインタの位置にレイ飛ばし、ヒットしたものを保存
- pointer.position = Input.mousePosition;
- EventSystem.current.RaycastAll(pointer, results);
- // ヒットしたUIの名前
- foreach (RaycastResult target in results)
- {
- if (target.gameObject == this.CardImage.gameObject)
- {
- isRay = true;
- }
- }
- if (!isRay)
- {
- _OnExit();
- yield break;
- }
- }
- }
- public void _OnExit()
- {
- Outline.SetActive(false);
- anim.SetInteger("Open", 0);
- anim.SetInteger("Close", 1);
- uIShiny.enabled = false;
- OnExitAction?.Invoke(this);
- OffAddRemoveButton();
- }
- }
|