CardDeck.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CardDeck : MonoBehaviour
  5. {
  6. public static CardDeck Instance { get; private set; }
  7. public float RightOffset
  8. {
  9. get
  10. {
  11. return this.m_RightOffset;
  12. }
  13. }
  14. public Vector3 FlipupAngle
  15. {
  16. get
  17. {
  18. return this.m_UpAngle;
  19. }
  20. }
  21. public Vector3 FlipdownAngle
  22. {
  23. get
  24. {
  25. return this.m_DownAngle;
  26. }
  27. }
  28. private void Awake()
  29. {
  30. CardDeck.Instance = this;
  31. if (CardDeck.m_CardObjData == null)
  32. {
  33. CardDeck.m_CardObjData = new Dictionary<CardData.Suit, Dictionary<CardData.Rank, GameObject>>
  34. {
  35. {
  36. CardData.Suit.Spades,
  37. new Dictionary<CardData.Rank, GameObject>()
  38. },
  39. {
  40. CardData.Suit.Diamonds,
  41. new Dictionary<CardData.Rank, GameObject>()
  42. },
  43. {
  44. CardData.Suit.Hearts,
  45. new Dictionary<CardData.Rank, GameObject>()
  46. },
  47. {
  48. CardData.Suit.Clubs,
  49. new Dictionary<CardData.Rank, GameObject>()
  50. }
  51. };
  52. CardData.Suit[] array = (CardData.Suit[])Enum.GetValues(typeof(CardData.Suit));
  53. CardData.Rank[] array2 = (CardData.Rank[])Enum.GetValues(typeof(CardData.Rank));
  54. foreach (CardData.Suit key in array)
  55. {
  56. foreach (CardData.Rank key2 in array2)
  57. {
  58. GameObject gameObject = Resources.Load<GameObject>(BlackjackGame.BlackJackResource("Prefab/Cards/" + key.ToString()));
  59. gameObject = gameObject.transform.Find(key2.ToString().ToLower() + key.ToString().ToLower()).gameObject;
  60. CardDeck.m_CardObjData[key].Add(key2, gameObject);
  61. }
  62. }
  63. }
  64. }
  65. public void Shuffle(int deckCount)
  66. {
  67. this.m_CardDeck = new List<CardData>(52 * deckCount);
  68. while (deckCount > 0)
  69. {
  70. this.AddDeck();
  71. deckCount--;
  72. }
  73. this.RandomiseDeck();
  74. }
  75. public CardData GetCard()
  76. {
  77. CardData result = this.m_CardDeck[0];
  78. this.m_CardDeck.RemoveAt(0);
  79. return result;
  80. }
  81. private void AddDeck()
  82. {
  83. CardData.Suit[] array = (CardData.Suit[])Enum.GetValues(typeof(CardData.Suit));
  84. CardData.Rank[] array2 = (CardData.Rank[])Enum.GetValues(typeof(CardData.Rank));
  85. for (int i = 0; i < array2.Length; i++)
  86. {
  87. for (int j = 0; j < array.Length; j++)
  88. {
  89. this.m_CardDeck.Add(new CardData(array[j], array2[i]));
  90. }
  91. }
  92. }
  93. private void RandomiseDeck()
  94. {
  95. this.FisherYatesCardDeckShuffle(this.m_CardDeck);
  96. }
  97. private List<CardData> FisherYatesCardDeckShuffle(List<CardData> aList)
  98. {
  99. System.Random random = new System.Random();
  100. int count = aList.Count;
  101. for (int i = 0; i < count; i++)
  102. {
  103. int index = i + (int)(random.NextDouble() * (double)(count - i));
  104. CardData value = aList[index];
  105. aList[index] = aList[i];
  106. aList[i] = value;
  107. }
  108. return aList;
  109. }
  110. public GameObject GetCardObj(CardData.Suit suit, CardData.Rank rank)
  111. {
  112. return CardDeck.m_CardObjData[suit][rank];
  113. }
  114. [SerializeField]
  115. private bool m_ForceSplit;
  116. [SerializeField]
  117. private bool m_ForceBJ;
  118. [SerializeField]
  119. private bool m_NotShufflue;
  120. [SerializeField]
  121. [Header("右手に持たせたときのオフセット値")]
  122. private float m_RightOffset;
  123. [SerializeField]
  124. [Header("表向きの時のカードのワールド角度")]
  125. private Vector3 m_UpAngle = Vector3.up * 90f;
  126. [SerializeField]
  127. [Header("裏向きの時のカードのワールド角度")]
  128. private Vector3 m_DownAngle = Vector3.up * 90f;
  129. private List<CardData> m_CardDeck = new List<CardData>();
  130. private static Dictionary<CardData.Suit, Dictionary<CardData.Rank, GameObject>> m_CardObjData;
  131. }