| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- using DG.Tweening;
- using UnityEngine.EventSystems;
- using TMPro;
- using System;
- public class FieldPermanentCard : MonoBehaviour
- {
- [Header("選択状態アウトライン")]
- public Image Outline_Select;
- [Header("カード画像")]
- public Image CardImage;
- [Header("ブロッカーエフェクト")]
- public GameObject BlockerEffect;
- [Header("エナジー個数Text")]
- public Text EnergyCountText;
- [Header("コライダー")]
- public GameObject Collider;
- [Header("アニメーター")]
- public Animator anim;
- [Header("コマンドパネル")]
- public CommandPanel fieldUnitCommandPanel;
- [Header("スキル名Text")]
- public Text SkillNameText;
- [Header("DPテキスト")]
- public Text DPText;
- [Header("DP枠")]
- public List<Image> DPBackground_color = new List<Image>();
- [Header("進化元枚テキスト")]
- public Text EvoRootCountText;
- [Header("進化元枚枠")]
- public Image EvoRootCountBackground;
- [Header("レベルテキスト")]
- public TextMeshProUGUI LevelText;
- [Header("表示親")]
- public GameObject Parent;
- [Header("スキル使用エフェクト")]
- public GameObject UsingSkillEffect;
- [Header("進化元追加エフェクト")]
- public ParticleSystem addDigivolutionCardsEffect;
- //初期スケール
- public Vector3 StartScale { get; set; }
- [Header("パーマネント番号テキスト")]
- public TextMeshProUGUI permanentIndexText;
- [Header("タップオブジェクト")]
- public GameObject TapObject;
- [Header("ダメージテキスト")]
- public Text DirectStrikeText;
- [Header("召喚酔い")]
- public GameObject SummonSicknessObject;
- [Header("進化予定オブジェクト")]
- public GameObject WillEvolutionObject;
- [Header("消滅予定オブジェクト")]
- public GameObject WillBeDeletedObject;
- [Header("デッキバウンス予定オブジェクト")]
- public GameObject WillBeDeckBounceObject;
- [Header("手札バウンス予定オブジェクト")]
- public GameObject WillBeHandBounceObject;
- [Header("場を離れる予定オブジェクト")]
- public GameObject WillRemoveFieldObject;
- [Header("アンタップ予定オブジェクト")]
- public GameObject WillUntapObject;
- public List<TextCardColorMaterial> textCardColorMaterials = new List<TextCardColorMaterial>();
- public UnityAction<FieldPermanentCard> OnClickAction;
- public Permanent ThisPermanent { get; set; }
- public bool IsEffectPlaying { get; set; }
- private void Awake()
- {
- RemoveSelectEffect();
- CloseCommandPanel();
- Outline_Select.gameObject.SetActive(false);
- OffUsingSkillEffect();
- OffSkillName();
- if (BlockerEffect != null)
- {
- BlockerEffect.gameObject.SetActive(false);
- }
- if (EvoRootCountText != null)
- {
- EvoRootCountText.transform.parent.gameObject.SetActive(false);
- }
- if (DirectStrikeText != null)
- {
- DirectStrikeText.transform.parent.parent.gameObject.SetActive(true);
- DirectStrikeText.transform.parent.gameObject.SetActive(false);
- }
- if (SummonSicknessObject != null)
- {
- SummonSicknessObject.gameObject.SetActive(false);
- }
- if (WillEvolutionObject != null)
- {
- WillEvolutionObject.SetActive(false);
- }
- if (WillBeDeletedObject != null)
- {
- WillBeDeletedObject.SetActive(false);
- }
- if (WillBeDeckBounceObject != null)
- {
- WillBeDeckBounceObject.SetActive(false);
- }
- if (WillBeHandBounceObject != null)
- {
- WillBeHandBounceObject.SetActive(false);
- }
- if (WillRemoveFieldObject != null)
- {
- WillRemoveFieldObject.SetActive(false);
- }
- if (WillUntapObject != null)
- {
- WillUntapObject.SetActive(false);
- }
- OffPermanentIndexText();
- }
- public IEnumerator ShowAddDigivolutionCardEffect()
- {
- if (addDigivolutionCardsEffect != null)
- {
- addDigivolutionCardsEffect.gameObject.SetActive(true);
- addDigivolutionCardsEffect.Play();
- }
- yield return new WaitForSeconds(0.1f);
- }
- public void OffPermanentIndexText()
- {
- if (permanentIndexText != null)
- {
- permanentIndexText.transform.parent.gameObject.SetActive(false);
- }
- }
- public void SetPermanentIndexText(List<Permanent> permanents)
- {
- if (permanentIndexText != null)
- {
- if (ThisPermanent != null)
- {
- if (ThisPermanent.TopCard != null)
- {
- int index = permanents.IndexOf(ThisPermanent) + 1;
- permanentIndexText.transform.parent.parent.gameObject.SetActive(true);
- permanentIndexText.transform.parent.gameObject.SetActive(true);
- permanentIndexText.text = $"{index}";
- }
- }
- }
- }
- void RotateSkillNameText()
- {
- SkillNameText.transform.parent.localRotation = Quaternion.Euler(0, 0, -1 * this.transform.localRotation.eulerAngles.z);
- }
- public void OnSkillName(ICardEffect cardEffect)
- {
- if (SkillNameText != null && ThisPermanent != null)
- {
- RotateSkillNameText();
- SkillNameText.transform.parent.gameObject.SetActive(true);
- SkillNameText.text = cardEffect.EffectName;
- }
- }
- public void OffSkillName()
- {
- if (SkillNameText != null)
- {
- SkillNameText.transform.parent.gameObject.SetActive(false);
- }
- }
- public void OffUsingSkillEffect()
- {
- if (UsingSkillEffect != null)
- {
- UsingSkillEffect.SetActive(false);
- }
- }
- public void OnUsingSkillEffect()
- {
- if (UsingSkillEffect != null)
- {
- UsingSkillEffect.SetActive(true);
- }
- }
- float _validPressTime = 0.5f;
- float _requiredTime = 0.0f;
- bool _pressing = false;
- #region Processing on click
- #region クリックされた時の処理
- public void OnClick()
- {
- if (ThisPermanent != null)
- {
- if (ThisPermanent.TopCard != null)
- {
- if (Input.GetMouseButtonUp(0))
- {
- OnClickAction?.Invoke(this);
- }
- else if (Input.GetMouseButtonUp(1))
- {
- OnRightClicked();
- }
- }
- }
- }
- void OnRightClicked()
- {
- if (!ThisPermanent.TopCard.IsFlipped || ThisPermanent.TopCard.Owner.isYou)
- {
- GManager.instance.pokemonDetail.OpenUnitDetail(ThisPermanent);
- }
- }
- #endregion
- #region クリックされた時の処理を追加
- public void AddClickTarget(UnityAction<FieldPermanentCard> _OnClickAction)
- {
- OnClickAction = _OnClickAction;
- }
- #endregion
- #region クリックされた時の処理を削除
- public void RemoveClickTarget()
- {
- OnClickAction = null;
- }
- #endregion
- #endregion
- #region Set permanent data
- public void SetPermanentData(Permanent permanent, bool updateIsTapped)
- {
- ThisPermanent = permanent;
- ShowPermanentData(updateIsTapped);
- }
- #endregion
- #region Reflect permanent data on UI
- bool _oldTurnSuspendedCards = false;
- public async void ShowPermanentData(bool updateIsTapped)
- {
- if (ThisPermanent == null)
- {
- return;
- }
- if (ThisPermanent.TopCard != null)
- {
- // reverse opponent's card
- if (!ThisPermanent.TopCard.Owner.isYou)
- {
- if (ContinuousController.instance != null)
- {
- if (ContinuousController.instance.reverseOpponentsCards)
- {
- Parent.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, 180));
- }
- else
- {
- Parent.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, 0));
- }
- }
- }
- // card image
- if (ThisPermanent.TopCard.IsFlipped)
- {
- CardImage.sprite = ContinuousController.instance.ReverseCard;
- }
- else
- {
- CardImage.sprite = await ThisPermanent.TopCard.GetCardSprite();
- }
- CardImage.gameObject.SetActive(true);
- //タップ
- if (ThisPermanent.IsSuspended)
- {
- if (TapObject != null)
- {
- TapObject.SetActive(true);
- }
- if (updateIsTapped)
- {
- bool turnSuspendedCards = ContinuousController.instance != null && ContinuousController.instance.turnSuspendedCards;
- if (anim != null)
- {
- if (ThisPermanent.OldIsSuspended != ThisPermanent.IsSuspended || _oldTurnSuspendedCards != turnSuspendedCards)
- {
- ThisPermanent.OldIsSuspended = ThisPermanent.IsSuspended;
- _oldTurnSuspendedCards = turnSuspendedCards;
- if (turnSuspendedCards)
- {
- anim.SetInteger("Tap", 1);
- }
- else
- {
- anim.SetInteger("Tap", -1);
- }
- }
- }
- }
- }
- else
- {
- if (TapObject != null)
- {
- TapObject.SetActive(false);
- }
- if (ContinuousController.instance != null)
- {
- if (ContinuousController.instance.turnSuspendedCards)
- {
- if (ThisPermanent.OldIsSuspended != ThisPermanent.IsSuspended)
- {
- ThisPermanent.OldIsSuspended = ThisPermanent.IsSuspended;
- if (anim != null)
- {
- anim.SetInteger("Tap", -1);
- }
- }
- }
- }
- }
- //DP
- if (ThisPermanent.IsDigimon && ThisPermanent.DP >= 0)
- {
- DPText.transform.parent.gameObject.SetActive(true);
- DPText.text = ThisPermanent.DP.ToString();
- for (int i = 0; i < DPBackground_color.Count; i++)
- {
- CardColor cardColor = CardColor.None;
- if (i < ThisPermanent.TopCard.CardColors.Count)
- {
- cardColor = ThisPermanent.TopCard.CardColors[i];
- }
- else
- {
- cardColor = ThisPermanent.TopCard.CardColors[0];
- }
- DPBackground_color[i].color = DataBase.CardColor_ColorLightDictionary[cardColor];
- }
- }
- else
- {
- DPText.transform.parent.gameObject.SetActive(false);
- }
- //Level
- if (ThisPermanent.IsDigimon && ThisPermanent.TopCard.HasLevel)
- {
- LevelText.transform.parent.gameObject.SetActive(true);
- LevelText.text = ThisPermanent.Level.ToString();
- foreach (TextCardColorMaterial textCardColorMaterial in textCardColorMaterials)
- {
- if (textCardColorMaterial.cardColor == ThisPermanent.TopCard.CardColors[0])
- {
- LevelText.fontSharedMaterial = new Material(textCardColorMaterial.material);
- break;
- }
- }
- }
- else
- {
- LevelText.transform.parent.gameObject.SetActive(false);
- }
- if (EvoRootCountText != null)
- {
- if (ThisPermanent.DigivolutionCards.Count >= 1)
- {
- EvoRootCountText.transform.parent.gameObject.SetActive(true);
- EvoRootCountText.text = $"×{ThisPermanent.DigivolutionCards.Count}";
- EvoRootCountBackground.color = DataBase.CardColor_ColorLightDictionary[ThisPermanent.TopCard.CardColors[0]];
- }
- else
- {
- EvoRootCountText.transform.parent.gameObject.SetActive(false);
- }
- }
- if (SummonSicknessObject != null)
- {
- bool isActive = false;
- if (ThisPermanent.EnterFieldTurnCount == GManager.instance.turnStateMachine.TurnCount)
- {
- if (GManager.instance.turnStateMachine.gameContext.TurnPlayer == ThisPermanent.TopCard.Owner)
- {
- if (!ThisPermanent.HasRush)
- {
- if (ThisPermanent.TopCard.Owner.GetBattleAreaPermanents().Contains(ThisPermanent))
- {
- isActive = true;
- }
- }
- }
- }
- SummonSicknessObject.SetActive(isActive);
- }
- if (BlockerEffect != null)
- {
- bool isActive = false;
- if (ThisPermanent.IsDigimon)
- {
- if (ThisPermanent.HasBlocker)
- {
- //if (thisPermanent.TopCard.Owner.GetBattleAreaPermanents().Contains(thisPermanent))
- {
- isActive = true;
- }
- }
- }
- BlockerEffect.SetActive(isActive);
- }
- }
- }
- #endregion
- #region Automatically reflect card data
- int _frameCount = 0;
- int _updateFrame = 75;
- public bool destroyed { get; set; } = false;
- public bool skipDestroy { get; set; } = false;
- public bool skipUpdate { get; set; } = false;
- //TODO: Pretty poor gargage collection, need to optimize - MB
- private void LateUpdate()
- {
- if (skipUpdate)
- {
- return;
- }
- #region exception check
- if (destroyed)
- {
- return;
- }
- if (ThisPermanent == null)
- {
- return;
- }
- if (ThisPermanent.TopCard == null)
- {
- if (!destroyed && !skipDestroy)
- {
- StartCoroutine(DestroyCoroutine());
- return;
- }
- }
- #endregion
- //Skill name
- if (SkillNameText.transform.parent.gameObject.activeSelf)
- {
- RotateSkillNameText();
- }
- if (DirectStrikeText != null)
- {
- if (ThisPermanent.IsSuspended)
- {
- DirectStrikeText.transform.parent.parent.transform.localPosition = new Vector2(DirectStrikeText.transform.parent.parent.transform.localPosition.x, 24);
- }
- else
- {
- DirectStrikeText.transform.parent.parent.transform.localPosition = new Vector2(DirectStrikeText.transform.parent.parent.transform.localPosition.x, 78);
- }
- DirectStrikeText.transform.parent.parent.localRotation = Quaternion.Euler(0, 0, -1 * this.transform.localRotation.eulerAngles.z);
- }
- if (ThisPermanent.TopCard.Owner.GetFieldPermanents().Count >= ThisPermanent.TopCard.Owner.fieldCardFrames.Count * 0.7f)
- {
- _updateFrame = 115;
- }
- else
- {
- _updateFrame = 75;
- }
- #region Get long press
- #if !UNITY_EDITOR && UNITY_ANDROID
- if (pressing)
- {
- if(requiredTime < Time.time)
- {
- OnRightClicked();
- pressing = false;
- }
- }
- #endif
- #endregion
- #region Reflected only once every few frames
- _frameCount++;
- if (_frameCount < _updateFrame)
- {
- return;
- }
- else
- {
- _frameCount = 0;
- }
- #endregion
- ShowPermanentData(true);
- }
- #endregion
- public void PointerDown(BaseEventData eventData)
- {
- if (!_pressing)
- {
- _pressing = true;
- _requiredTime = Time.time + _validPressTime;
- }
- else
- {
- _pressing = false;
- }
- }
- public void PointerUp(BaseEventData eventData)
- {
- if (_pressing)
- {
- _pressing = false;
- }
- }
- public void PointerExit(BaseEventData eventData)
- {
- if (_pressing)
- {
- _pressing = false;
- }
- }
- #region このオブジェクトを削除
- IEnumerator DestroyCoroutine()
- {
- yield return null;
- destroyed = true;
- Destroy(this.gameObject);
- }
- #endregion
- #region 選択状態
- public bool isExpand { get; set; }
- #region 選択状態
- public void OnSelectEffect(float expand)
- {
- if (isExpand)
- {
- return;
- }
- Outline_Select.gameObject.SetActive(true);
- if (this.gameObject.activeSelf)
- {
- StartCoroutine(ExpandCoroutine(expand));
- }
- isExpand = true;
- SetOrangeOutline();
- }
- #endregion
- #region オレンジアウトライン
- public void SetOrangeOutline()
- {
- Outline_Select.color = DataBase.SelectColor_Orange;
- }
- #endregion
- #region ブルーアウトライン
- public void SetBlueOutline()
- {
- Outline_Select.color = DataBase.SelectColor_Blue;
- }
- #endregion
- #region 大きくする
- IEnumerator ExpandCoroutine(float expand)
- {
- float ExpandTime = 0.06f;
- float targetScale = StartScale.x * expand;
- float expandSpeed = (targetScale - transform.localScale.x) / ExpandTime;
- while (transform.localScale.x < targetScale)
- {
- transform.localScale += new Vector3(expandSpeed * Time.deltaTime, expandSpeed * Time.deltaTime, 0);
- yield return new WaitForSeconds(Time.deltaTime);
- if (!isExpand)
- {
- transform.localScale = StartScale;
- yield break;
- }
- }
- transform.localScale = new Vector3(targetScale, targetScale, 1);
- if (!isExpand)
- {
- transform.localScale = StartScale;
- yield break;
- }
- }
- #endregion
- #region 選択状態リセット
- public void RemoveSelectEffect()
- {
- Outline_Select.gameObject.SetActive(false);
- if (!isExpand)
- {
- return;
- }
- transform.localScale = StartScale;
- isExpand = false;
- }
- #endregion
- #endregion
- #region キャンバス座標への変換
- public Vector3 GetLocalCanvasPosition()
- {
- return this.transform.localPosition + this.transform.parent.localPosition;
- }
- #endregion
- #region コマンドパネルを閉じる
- public void CloseCommandPanel()
- {
- if (fieldUnitCommandPanel != null)
- {
- fieldUnitCommandPanel.CloseCommandPanel();
- }
- }
- #endregion
- #region ドラッグ
- public UnityAction<FieldPermanentCard> OnBeginDragAction { get; set; }
- public UnityAction<FieldPermanentCard, List<DropArea>> OnDragAction { get; set; }
- public UnityAction<FieldPermanentCard, List<DropArea>> OnEndDragAction { get; set; }
- public void RemoveDragTarget()
- {
- this.OnBeginDragAction = null;
- this.OnDragAction = null;
- this.OnEndDragAction = null;
- }
- public void AddDragTarget(UnityAction<FieldPermanentCard> OnBeginDragAction, UnityAction<FieldPermanentCard, List<DropArea>> OnDragAction, UnityAction<FieldPermanentCard, List<DropArea>> OnEndDragAction)
- {
- this.OnBeginDragAction = OnBeginDragAction;
- this.OnDragAction = OnDragAction;
- this.OnEndDragAction = OnEndDragAction;
- }
- public void OnBeginDrag()
- {
- OnBeginDragAction?.Invoke(this);
- }
- public void OnDrag()
- {
- OnDragAction?.Invoke(this, Draggable.GetRaycastArea());
- }
- public void OnEndDrag()
- {
- OnEndDragAction?.Invoke(this, Draggable.GetRaycastArea());
- }
- #endregion
- }
- [System.Serializable]
- public class TextCardColorMaterial
- {
- public CardColor cardColor;
- public Material material;
- }
|