FieldPermanentCard.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using UnityEngine.UI;
  6. using DG.Tweening;
  7. using UnityEngine.EventSystems;
  8. using TMPro;
  9. using System;
  10. using System.Diagnostics;
  11. public class FieldPermanentCard : MonoBehaviour
  12. {
  13. [Header("選択状態アウトライン")]
  14. public Image Outline_Select;
  15. [Header("カード画像")]
  16. public Image CardImage;
  17. [Header("ブロッカーエフェクト")]
  18. public GameObject BlockerEffect;
  19. [Header("エナジー個数Text")]
  20. public Text EnergyCountText;
  21. [Header("コライダー")]
  22. public GameObject Collider;
  23. [Header("アニメーター")]
  24. public Animator anim;
  25. [Header("コマンドパネル")]
  26. public CommandPanel fieldUnitCommandPanel;
  27. [Header("スキル名Text")]
  28. public Text SkillNameText;
  29. [Header("DPテキスト")]
  30. public Text DPText;
  31. [Header("DP枠")]
  32. public List<Image> DPBackground_color = new List<Image>();
  33. [Header("進化元枚テキスト")]
  34. public Text EvoRootCountText;
  35. [Header("進化元枚枠")]
  36. public Image EvoRootCountBackground;
  37. [Header("レベルテキスト")]
  38. public TextMeshProUGUI LevelText;
  39. [Header("Link Elements")]
  40. public GameObject LinkedObject;
  41. public Image LinkIcon;
  42. [Header("表示親")]
  43. public GameObject Parent;
  44. [Header("スキル使用エフェクト")]
  45. public GameObject UsingSkillEffect;
  46. [Header("進化元追加エフェクト")]
  47. public ParticleSystem addDigivolutionCardsEffect;
  48. //初期スケール
  49. public Vector3 StartScale { get; set; }
  50. [Header("パーマネント番号テキスト")]
  51. public TextMeshProUGUI permanentIndexText;
  52. [Header("タップオブジェクト")]
  53. public GameObject TapObject;
  54. [Header("ダメージテキスト")]
  55. public Text DirectStrikeText;
  56. [Header("召喚酔い")]
  57. public GameObject SummonSicknessObject;
  58. [Header("進化予定オブジェクト")]
  59. public GameObject WillEvolutionObject;
  60. [Header("消滅予定オブジェクト")]
  61. public GameObject WillBeDeletedObject;
  62. [Header("デッキバウンス予定オブジェクト")]
  63. public GameObject WillBeDeckBounceObject;
  64. [Header("手札バウンス予定オブジェクト")]
  65. public GameObject WillBeHandBounceObject;
  66. [Header("場を離れる予定オブジェクト")]
  67. public GameObject WillRemoveFieldObject;
  68. [Header("アンタップ予定オブジェクト")]
  69. public GameObject WillUntapObject;
  70. public List<TextCardColorMaterial> textCardColorMaterials = new List<TextCardColorMaterial>();
  71. public UnityAction<FieldPermanentCard> OnClickAction;
  72. public Permanent ThisPermanent { get; set; }
  73. public bool IsEffectPlaying { get; set; }
  74. private void Awake()
  75. {
  76. RemoveSelectEffect();
  77. CloseCommandPanel();
  78. Outline_Select.gameObject.SetActive(false);
  79. OffUsingSkillEffect();
  80. OffSkillName();
  81. if (BlockerEffect != null)
  82. {
  83. BlockerEffect.gameObject.SetActive(false);
  84. }
  85. if (EvoRootCountText != null)
  86. {
  87. EvoRootCountText.transform.parent.gameObject.SetActive(false);
  88. }
  89. if (LinkedObject != null)
  90. {
  91. LinkedObject.SetActive(false);
  92. }
  93. if (DirectStrikeText != null)
  94. {
  95. DirectStrikeText.transform.parent.parent.gameObject.SetActive(true);
  96. DirectStrikeText.transform.parent.gameObject.SetActive(false);
  97. }
  98. if (SummonSicknessObject != null)
  99. {
  100. SummonSicknessObject.gameObject.SetActive(false);
  101. }
  102. if (WillEvolutionObject != null)
  103. {
  104. WillEvolutionObject.SetActive(false);
  105. }
  106. if (WillBeDeletedObject != null)
  107. {
  108. WillBeDeletedObject.SetActive(false);
  109. }
  110. if (WillBeDeckBounceObject != null)
  111. {
  112. WillBeDeckBounceObject.SetActive(false);
  113. }
  114. if (WillBeHandBounceObject != null)
  115. {
  116. WillBeHandBounceObject.SetActive(false);
  117. }
  118. if (WillRemoveFieldObject != null)
  119. {
  120. WillRemoveFieldObject.SetActive(false);
  121. }
  122. if (WillUntapObject != null)
  123. {
  124. WillUntapObject.SetActive(false);
  125. }
  126. OffPermanentIndexText();
  127. //Events
  128. GManager.OnReverseOpponentsCardsChanged += SetTransformRotation;
  129. GManager.OnCardFlippedChanged += SetCardIsFlipped;
  130. //GManager.OnCardSuspendedChanged += SetCardSuspended;
  131. }
  132. public IEnumerator ShowAddDigivolutionCardEffect()
  133. {
  134. if (addDigivolutionCardsEffect != null)
  135. {
  136. addDigivolutionCardsEffect.gameObject.SetActive(true);
  137. addDigivolutionCardsEffect.Play();
  138. }
  139. yield return new WaitForSeconds(0.1f);
  140. }
  141. public void OffPermanentIndexText()
  142. {
  143. if (permanentIndexText != null)
  144. {
  145. permanentIndexText.transform.parent.gameObject.SetActive(false);
  146. }
  147. }
  148. public void SetPermanentIndexText(List<Permanent> permanents)
  149. {
  150. if (permanentIndexText != null)
  151. {
  152. if (ThisPermanent != null)
  153. {
  154. if (ThisPermanent.TopCard != null)
  155. {
  156. int index = permanents.IndexOf(ThisPermanent) + 1;
  157. permanentIndexText.transform.parent.parent.gameObject.SetActive(true);
  158. permanentIndexText.transform.parent.gameObject.SetActive(true);
  159. permanentIndexText.text = $"{index}";
  160. }
  161. }
  162. }
  163. }
  164. void RotateSkillNameText()
  165. {
  166. SkillNameText.transform.parent.localRotation = Quaternion.Euler(0, 0, -1 * this.transform.localRotation.eulerAngles.z);
  167. }
  168. public void OnSkillName(ICardEffect cardEffect)
  169. {
  170. if (SkillNameText != null && ThisPermanent != null)
  171. {
  172. RotateSkillNameText();
  173. SkillNameText.transform.parent.gameObject.SetActive(true);
  174. SkillNameText.text = cardEffect.EffectName;
  175. }
  176. }
  177. public void OffSkillName()
  178. {
  179. if (SkillNameText != null)
  180. {
  181. SkillNameText.transform.parent.gameObject.SetActive(false);
  182. }
  183. }
  184. public void OffUsingSkillEffect()
  185. {
  186. if (UsingSkillEffect != null)
  187. {
  188. UsingSkillEffect.SetActive(false);
  189. }
  190. }
  191. public void OnUsingSkillEffect()
  192. {
  193. if (UsingSkillEffect != null)
  194. {
  195. UsingSkillEffect.SetActive(true);
  196. }
  197. }
  198. float _validPressTime = 0.5f;
  199. float _requiredTime = 0.0f;
  200. bool _pressing = false;
  201. #region Processing on click
  202. #region Processing when clicked
  203. public void OnClick()
  204. {
  205. if (ThisPermanent != null)
  206. {
  207. if (ThisPermanent.TopCard != null)
  208. {
  209. if (Input.GetMouseButtonUp(0))
  210. {
  211. OnClickAction?.Invoke(this);
  212. }
  213. else if (Input.GetMouseButtonUp(1))
  214. {
  215. OnRightClicked();
  216. }
  217. }
  218. }
  219. }
  220. void OnRightClicked()
  221. {
  222. if (!ThisPermanent.TopCard.IsFlipped || ThisPermanent.TopCard.Owner.isYou)
  223. {
  224. GManager.instance.pokemonDetail.OpenUnitDetail(ThisPermanent);
  225. }
  226. }
  227. #endregion
  228. #region Added processing when clicked
  229. public void AddClickTarget(UnityAction<FieldPermanentCard> _OnClickAction)
  230. {
  231. OnClickAction = _OnClickAction;
  232. }
  233. #endregion
  234. #region Delete the process when clicked
  235. public void RemoveClickTarget()
  236. {
  237. OnClickAction = null;
  238. }
  239. #endregion
  240. #endregion
  241. #region Set permanent data
  242. public void SetPermanentData(Permanent permanent, bool updateIsTapped)
  243. {
  244. ThisPermanent = permanent;
  245. SetTransformRotation();
  246. SetCardIsFlipped();
  247. ShowPermanentData(updateIsTapped);
  248. }
  249. #endregion
  250. #region Reflect permanent data on UI
  251. bool _oldTurnSuspendedCards = false;
  252. void SetTransformRotation()
  253. {
  254. if (ThisPermanent == null)
  255. return;
  256. if (ThisPermanent.TopCard == null)
  257. return;
  258. if (ThisPermanent.TopCard.Owner.isYou)
  259. return;
  260. if (ContinuousController.instance == null)
  261. return;
  262. if (ContinuousController.instance.reverseOpponentsCards)
  263. Parent.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, 180));
  264. else
  265. Parent.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, 0));
  266. }
  267. async void SetCardIsFlipped()
  268. {
  269. if (ThisPermanent == null)
  270. return;
  271. if (ThisPermanent.TopCard == null)
  272. return;
  273. if (ContinuousController.instance == null)
  274. return;
  275. if (CardImage == null)
  276. return;
  277. // card image
  278. if (ThisPermanent.TopCard.IsFlipped)
  279. {
  280. if (CardImage.sprite != ContinuousController.instance.ReverseCard)
  281. CardImage.sprite = ContinuousController.instance.ReverseCard;
  282. }
  283. else
  284. {
  285. CardImage.sprite = await ThisPermanent.TopCard.GetCardSprite();
  286. }
  287. CardImage.gameObject.SetActive(true);
  288. }
  289. void SetCardSuspended(bool updateIsTapped)
  290. {
  291. if (ThisPermanent == null)
  292. return;
  293. if (ThisPermanent.TopCard == null)
  294. return;
  295. if (ContinuousController.instance == null)
  296. return;
  297. if (ThisPermanent.IsSuspended)
  298. {
  299. if (TapObject != null)
  300. TapObject.SetActive(true);
  301. if (updateIsTapped)
  302. {
  303. bool turnSuspendedCards = ContinuousController.instance != null && ContinuousController.instance.turnSuspendedCards;
  304. if (anim != null)
  305. {
  306. if (ThisPermanent.OldIsSuspended != ThisPermanent.IsSuspended || _oldTurnSuspendedCards != turnSuspendedCards)
  307. {
  308. ThisPermanent.OldIsSuspended = ThisPermanent.IsSuspended;
  309. _oldTurnSuspendedCards = turnSuspendedCards;
  310. if (turnSuspendedCards)
  311. {
  312. if (anim.GetInteger("Tap") != 1)
  313. anim.SetInteger("Tap", 1);
  314. }
  315. else
  316. {
  317. if (anim.GetInteger("Tap") != -1)
  318. anim.SetInteger("Tap", -1);
  319. }
  320. }
  321. }
  322. }
  323. }
  324. else
  325. {
  326. if (TapObject != null)
  327. TapObject.SetActive(false);
  328. if (ContinuousController.instance != null)
  329. {
  330. if (ContinuousController.instance.turnSuspendedCards)
  331. {
  332. if (ThisPermanent.OldIsSuspended != ThisPermanent.IsSuspended)
  333. {
  334. ThisPermanent.OldIsSuspended = ThisPermanent.IsSuspended;
  335. if (anim != null)
  336. {
  337. if (anim.GetInteger("Tap") != -1)
  338. anim.SetInteger("Tap", -1);
  339. }
  340. }
  341. }
  342. }
  343. }
  344. }
  345. public void ShowPermanentData(bool updateIsTapped)
  346. {
  347. if (ThisPermanent == null)
  348. {
  349. return;
  350. }
  351. if (ThisPermanent.TopCard != null)
  352. {
  353. SetCardSuspended(updateIsTapped);
  354. //DP
  355. if (ThisPermanent.IsDigimon && ThisPermanent.DP >= 0)
  356. {
  357. DPText.transform.parent.gameObject.SetActive(true);
  358. if(DPText.text != ThisPermanent.DP.ToString())
  359. DPText.text = ThisPermanent.DP.ToString();
  360. for (int i = 0; i < DPBackground_color.Count; i++)
  361. {
  362. CardColor cardColor = CardColor.None;
  363. if (i < ThisPermanent.TopCard.CardColors.Count)
  364. {
  365. cardColor = ThisPermanent.TopCard.CardColors[i];
  366. float fillAmount = (float)((i + 1) / (float)ThisPermanent.TopCard.CardColors.Count);
  367. if (DPBackground_color[i].color != DataBase.CardColor_ColorLightDictionary[cardColor])
  368. DPBackground_color[i].color = DataBase.CardColor_ColorLightDictionary[cardColor];
  369. DPBackground_color[i].fillAmount = fillAmount;
  370. DPBackground_color[i].gameObject.SetActive(true);
  371. }
  372. else
  373. {
  374. DPBackground_color[i].gameObject.SetActive(false);
  375. }
  376. }
  377. }
  378. else
  379. {
  380. DPText.transform.parent.gameObject.SetActive(false);
  381. }
  382. //Level
  383. if (ThisPermanent.IsDigimon && ThisPermanent.TopCard.HasLevel)
  384. {
  385. LevelText.transform.parent.gameObject.SetActive(true);
  386. if(LevelText.text != ThisPermanent.Level.ToString())
  387. LevelText.text = ThisPermanent.Level.ToString();
  388. foreach (TextCardColorMaterial textCardColorMaterial in textCardColorMaterials)
  389. {
  390. if (textCardColorMaterial.cardColor == ThisPermanent.TopCard.CardColors[0])
  391. {
  392. LevelText.fontSharedMaterial = new Material(textCardColorMaterial.material);
  393. break;
  394. }
  395. }
  396. }
  397. else
  398. {
  399. LevelText.transform.parent.gameObject.SetActive(false);
  400. }
  401. //Digivolution Count
  402. if (EvoRootCountText != null)
  403. {
  404. if (ThisPermanent.DigivolutionCards.Count >= 1)
  405. {
  406. EvoRootCountText.transform.parent.gameObject.SetActive(true);
  407. if(EvoRootCountText.text != $"×{ThisPermanent.DigivolutionCards.Count}")
  408. EvoRootCountText.text = $"×{ThisPermanent.DigivolutionCards.Count}";
  409. if(EvoRootCountBackground.color != DataBase.CardColor_ColorLightDictionary[ThisPermanent.TopCard.CardColors[0]])
  410. EvoRootCountBackground.color = DataBase.CardColor_ColorLightDictionary[ThisPermanent.TopCard.CardColors[0]];
  411. }
  412. else
  413. {
  414. EvoRootCountText.transform.parent.gameObject.SetActive(false);
  415. }
  416. }
  417. //Links
  418. if (LinkedObject != null)
  419. {
  420. if (ThisPermanent.LinkedCards.Count > 0)
  421. {
  422. LinkedObject.SetActive(true);
  423. //if (LinkedDPText.text != $"+{ThisPermanent.LinkedDP}")
  424. // LinkedDPText.text = $"+{ThisPermanent.LinkedDP}";
  425. if (LinkIcon.color != DataBase.CardColor_ColorLightDictionary[ThisPermanent.TopCard.CardColors[0]])
  426. LinkIcon.color = DataBase.CardColor_ColorLightDictionary[ThisPermanent.TopCard.CardColors[0]];
  427. }
  428. else
  429. {
  430. LinkedObject.SetActive(false);
  431. }
  432. }
  433. //Summoning Sickness
  434. if (SummonSicknessObject != null)
  435. {
  436. bool isActive = false;
  437. if (ThisPermanent.EnterFieldTurnCount == GManager.instance.turnStateMachine.TurnCount)
  438. {
  439. if (GManager.instance.turnStateMachine.gameContext.TurnPlayer == ThisPermanent.TopCard.Owner)
  440. {
  441. if (!ThisPermanent.HasRush)
  442. {
  443. if (ThisPermanent.TopCard.Owner.GetBattleAreaPermanents().Contains(ThisPermanent))
  444. {
  445. isActive = true;
  446. }
  447. }
  448. }
  449. }
  450. SummonSicknessObject.SetActive(isActive);
  451. }
  452. //Blocker
  453. if (BlockerEffect != null)
  454. {
  455. bool isActive = false;
  456. if (ThisPermanent.IsDigimon)
  457. {
  458. if (ThisPermanent.HasBlocker)
  459. {
  460. //if (thisPermanent.TopCard.Owner.GetBattleAreaPermanents().Contains(thisPermanent))
  461. {
  462. isActive = true;
  463. }
  464. }
  465. }
  466. BlockerEffect.SetActive(isActive);
  467. }
  468. }
  469. }
  470. #endregion
  471. #region Automatically reflect card data
  472. int _frameCount = 0;
  473. int _updateFrame = 75;
  474. public bool destroyed { get; set; } = false;
  475. public bool skipDestroy { get; set; } = false;
  476. public bool skipUpdate { get; set; } = false;
  477. //TODO: Pretty poor gargage collection, need to optimize - MB
  478. private void LateUpdate()
  479. {
  480. if (skipUpdate)
  481. {
  482. return;
  483. }
  484. #region exception check
  485. if (destroyed)
  486. {
  487. return;
  488. }
  489. if (ThisPermanent == null)
  490. {
  491. return;
  492. }
  493. if (ThisPermanent.TopCard == null)
  494. {
  495. if (!destroyed && !skipDestroy)
  496. {
  497. StartCoroutine(DestroyCoroutine());
  498. return;
  499. }
  500. }
  501. #endregion
  502. //Skill name
  503. if (SkillNameText.transform.parent.gameObject.activeSelf)
  504. {
  505. RotateSkillNameText();
  506. }
  507. if (DirectStrikeText != null)
  508. {
  509. if (ThisPermanent.IsSuspended)
  510. {
  511. DirectStrikeText.transform.parent.parent.transform.localPosition = new Vector2(DirectStrikeText.transform.parent.parent.transform.localPosition.x, 24);
  512. }
  513. else
  514. {
  515. DirectStrikeText.transform.parent.parent.transform.localPosition = new Vector2(DirectStrikeText.transform.parent.parent.transform.localPosition.x, 78);
  516. }
  517. DirectStrikeText.transform.parent.parent.localRotation = Quaternion.Euler(0, 0, -1 * this.transform.localRotation.eulerAngles.z);
  518. }
  519. if (ThisPermanent.TopCard.Owner.GetFieldPermanents().Count >= ThisPermanent.TopCard.Owner.fieldCardFrames.Count * 0.7f)
  520. {
  521. _updateFrame = 115;
  522. }
  523. else
  524. {
  525. _updateFrame = 75;
  526. }
  527. #region Get long press
  528. #if !UNITY_EDITOR && UNITY_ANDROID
  529. if (pressing)
  530. {
  531. if(requiredTime < Time.time)
  532. {
  533. OnRightClicked();
  534. pressing = false;
  535. }
  536. }
  537. #endif
  538. #endregion
  539. #region Reflected only once every few frames
  540. _frameCount++;
  541. if (_frameCount < _updateFrame)
  542. {
  543. return;
  544. }
  545. else
  546. {
  547. _frameCount = 0;
  548. }
  549. #endregion
  550. ShowPermanentData(true);
  551. }
  552. #endregion
  553. public void PointerDown(BaseEventData eventData)
  554. {
  555. if (!_pressing)
  556. {
  557. _pressing = true;
  558. _requiredTime = Time.time + _validPressTime;
  559. }
  560. else
  561. {
  562. _pressing = false;
  563. }
  564. }
  565. public void PointerUp(BaseEventData eventData)
  566. {
  567. if (_pressing)
  568. {
  569. _pressing = false;
  570. }
  571. }
  572. public void PointerExit(BaseEventData eventData)
  573. {
  574. if (_pressing)
  575. {
  576. _pressing = false;
  577. }
  578. }
  579. #region このオブジェクトを削除
  580. IEnumerator DestroyCoroutine()
  581. {
  582. yield return null;
  583. destroyed = true;
  584. Destroy(this.gameObject);
  585. }
  586. #endregion
  587. #region 選択状態
  588. public bool isExpand { get; set; }
  589. #region 選択状態
  590. public void OnSelectEffect(float expand)
  591. {
  592. if (isExpand)
  593. {
  594. return;
  595. }
  596. Outline_Select.gameObject.SetActive(true);
  597. if (this.gameObject.activeSelf)
  598. {
  599. StartCoroutine(ExpandCoroutine(expand));
  600. }
  601. isExpand = true;
  602. SetOrangeOutline();
  603. }
  604. #endregion
  605. #region オレンジアウトライン
  606. public void SetOrangeOutline()
  607. {
  608. Outline_Select.color = DataBase.SelectColor_Orange;
  609. }
  610. #endregion
  611. #region ブルーアウトライン
  612. public void SetBlueOutline()
  613. {
  614. Outline_Select.color = DataBase.SelectColor_Blue;
  615. }
  616. #endregion
  617. #region 大きくする
  618. IEnumerator ExpandCoroutine(float expand)
  619. {
  620. float ExpandTime = 0.06f;
  621. float targetScale = StartScale.x * expand;
  622. float expandSpeed = (targetScale - transform.localScale.x) / ExpandTime;
  623. while (transform.localScale.x < targetScale)
  624. {
  625. transform.localScale += new Vector3(expandSpeed * Time.deltaTime, expandSpeed * Time.deltaTime, 0);
  626. yield return new WaitForSeconds(Time.deltaTime);
  627. if (!isExpand)
  628. {
  629. transform.localScale = StartScale;
  630. yield break;
  631. }
  632. }
  633. transform.localScale = new Vector3(targetScale, targetScale, 1);
  634. if (!isExpand)
  635. {
  636. transform.localScale = StartScale;
  637. yield break;
  638. }
  639. }
  640. #endregion
  641. #region 選択状態リセット
  642. public void RemoveSelectEffect()
  643. {
  644. Outline_Select.gameObject.SetActive(false);
  645. if (!isExpand)
  646. {
  647. return;
  648. }
  649. transform.localScale = StartScale;
  650. isExpand = false;
  651. }
  652. #endregion
  653. #endregion
  654. #region キャンバス座標への変換
  655. public Vector3 GetLocalCanvasPosition()
  656. {
  657. return this.transform.localPosition + this.transform.parent.localPosition;
  658. }
  659. #endregion
  660. #region コマンドパネルを閉じる
  661. public void CloseCommandPanel()
  662. {
  663. if (fieldUnitCommandPanel != null)
  664. {
  665. fieldUnitCommandPanel.CloseCommandPanel();
  666. }
  667. }
  668. #endregion
  669. #region ドラッグ
  670. public UnityAction<FieldPermanentCard> OnBeginDragAction { get; set; }
  671. public UnityAction<FieldPermanentCard, List<DropArea>> OnDragAction { get; set; }
  672. public UnityAction<FieldPermanentCard, List<DropArea>> OnEndDragAction { get; set; }
  673. public void RemoveDragTarget()
  674. {
  675. this.OnBeginDragAction = null;
  676. this.OnDragAction = null;
  677. this.OnEndDragAction = null;
  678. }
  679. public void AddDragTarget(UnityAction<FieldPermanentCard> OnBeginDragAction, UnityAction<FieldPermanentCard, List<DropArea>> OnDragAction, UnityAction<FieldPermanentCard, List<DropArea>> OnEndDragAction)
  680. {
  681. this.OnBeginDragAction = OnBeginDragAction;
  682. this.OnDragAction = OnDragAction;
  683. this.OnEndDragAction = OnEndDragAction;
  684. }
  685. public void OnBeginDrag()
  686. {
  687. OnBeginDragAction?.Invoke(this);
  688. }
  689. public void OnDrag()
  690. {
  691. OnDragAction?.Invoke(this, Draggable.GetRaycastArea());
  692. }
  693. public void OnEndDrag()
  694. {
  695. OnEndDragAction?.Invoke(this, Draggable.GetRaycastArea());
  696. }
  697. #endregion
  698. }
  699. [System.Serializable]
  700. public class TextCardColorMaterial
  701. {
  702. public CardColor cardColor;
  703. public Material material;
  704. }