DeckInfoPrefab.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System.Linq;
  6. using UnityEngine.Events;
  7. public class DeckInfoPrefab : MonoBehaviour
  8. {
  9. [Header("MC image")]
  10. public Image KeyCardImage;
  11. [Header("DefaultKeyCardSprite")]
  12. public Sprite DefaultKeyCardSprite;
  13. [Header("deck name")]
  14. public Text DeckName;
  15. [Header("red")]
  16. public Image RedIcon;
  17. [Header("blue")]
  18. public Image BlueIcon;
  19. [Header("green")]
  20. public Image GreenIcon;
  21. [Header("yellow")]
  22. public Image YellowIcon;
  23. [Header("scrollRect")]
  24. public ScrollRect scrollRect;
  25. [Header("Outline")]
  26. public GameObject Outline;
  27. [Header("no MC image")]
  28. public Image ReverseFace;
  29. public DeckData thisDeckData { get; set; }
  30. public UnityAction<DeckData> OnClickAction;
  31. private void OnEnable()
  32. {
  33. OnExit();
  34. }
  35. public void OnEnter()
  36. {
  37. this.gameObject.transform.localScale = Opening.instance.DeckInfoPrefabExpandScale;
  38. }
  39. public void OnClick()
  40. {
  41. OnClick_DeckInfoPrefab(true);
  42. }
  43. public void OnClick_DeckInfoPrefab(bool playSE)
  44. {
  45. if (playSE)
  46. {
  47. Opening.instance.PlayDecisionSE();
  48. }
  49. OnClickAction?.Invoke(thisDeckData);
  50. Outline.SetActive(true);
  51. for (int j = 0; j < this.transform.parent.childCount; j++)
  52. {
  53. if (this.transform.parent.GetChild(j) != this.transform)
  54. {
  55. if (this.transform.parent.GetChild(j).GetComponent<DeckInfoPrefab>() != null)
  56. {
  57. this.transform.parent.GetChild(j).GetComponent<DeckInfoPrefab>().Outline.SetActive(false);
  58. }
  59. if (this.transform.parent.GetChild(j).GetComponent<CreateNewDeckButton>() != null)
  60. {
  61. this.transform.parent.GetChild(j).GetComponent<CreateNewDeckButton>().Outline.SetActive(false);
  62. }
  63. }
  64. }
  65. }
  66. public void OnExit()
  67. {
  68. if (Opening.instance != null)
  69. this.gameObject.transform.localScale = Opening.instance.DeckInfoPrefabStartScale;
  70. }
  71. public async void SetUpDeckInfoPrefab(DeckData deckData)
  72. {
  73. this.gameObject.SetActive(deckData != null);
  74. if (deckData != null)
  75. {
  76. //MC image
  77. if (deckData.KeyCard != null)
  78. {
  79. KeyCardImage.sprite = await deckData.KeyCard.GetCardSprite();
  80. ReverseFace.gameObject.SetActive(false);
  81. }
  82. else
  83. {
  84. KeyCardImage.sprite = DefaultKeyCardSprite;
  85. ReverseFace.gameObject.SetActive(true);
  86. }
  87. //deck name
  88. DeckName.text = deckData.DeckName;
  89. //color icon
  90. RedIcon.gameObject.SetActive(deckData.DeckCards().Count((card) => card.cardColors[0] == CardColor.Green) > 0);
  91. BlueIcon.gameObject.SetActive(deckData.DeckCards().Count((card) => card.cardColors[0] == CardColor.Red) > 0);
  92. GreenIcon.gameObject.SetActive(deckData.DeckCards().Count((card) => card.cardColors[0] == CardColor.Blue) > 0);
  93. YellowIcon.gameObject.SetActive(deckData.DeckCards().Count((card) => card.cardColors[0] == CardColor.Yellow) > 0);
  94. thisDeckData = deckData;
  95. Outline.SetActive(false);
  96. }
  97. }
  98. }