Card.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class Card : MonoBehaviour
  5. {
  6. public bool IsMoveend
  7. {
  8. get
  9. {
  10. return this.m_IsMoveend;
  11. }
  12. }
  13. private void Reset()
  14. {
  15. this.m_MyRenderer = base.GetComponent<MeshRenderer>();
  16. }
  17. private void PosYFixed()
  18. {
  19. Vector3 position = base.transform.position;
  20. position.y = this.EndPosition.y;
  21. base.transform.position = position;
  22. }
  23. private IEnumerator CardMove()
  24. {
  25. this.m_MyRenderer.enabled = false;
  26. float timer = this.InitTime;
  27. while (timer <= this.StartTime)
  28. {
  29. timer += Time.deltaTime;
  30. yield return null;
  31. }
  32. this.m_MyRenderer.enabled = true;
  33. BlackjackGame.Instance.CardSe.Play();
  34. bool is_player = base.transform.parent == BjPlayer.Instance.CurrentHand.transform;
  35. Vector3 orijin_pos = base.transform.position;
  36. bool hand_switch = false;
  37. for (;;)
  38. {
  39. timer += Time.deltaTime;
  40. if (!hand_switch)
  41. {
  42. hand_switch = (timer > this.SwitchTime);
  43. base.transform.position = BjMotionControl.Instance.LeftHandPos();
  44. float num = this.StartTime + (this.SwitchTime - this.StartTime) / 2f;
  45. float t = KasaiUtility.SinRate01(timer - num, this.SwitchTime - num, false, false);
  46. this.m_OpenTime = this.SwitchTime - num;
  47. if (this.CurrentState == Card.CardState.FlipUp)
  48. {
  49. base.transform.eulerAngles = Vector3.Lerp(CardDeck.Instance.FlipdownAngle, CardDeck.Instance.FlipupAngle, t);
  50. }
  51. }
  52. else
  53. {
  54. Vector3 position = BjMotionControl.Instance.RightHandPos();
  55. float num2 = KasaiUtility.SinRate01(timer - this.SwitchTime, this.CardSetTime - this.SwitchTime, false, false);
  56. this.m_IsMoveend = (timer > this.CardSetTime);
  57. if (is_player)
  58. {
  59. position.x -= CardDeck.Instance.RightOffset * num2;
  60. }
  61. else if (BjPlayer.Instance.IsturnEnd)
  62. {
  63. this.m_IsMoveend = (Dealer.Instance.LastCardPos.z < position.z);
  64. position.z = Mathf.Min(Dealer.Instance.LastCardPos.z, position.z);
  65. }
  66. base.transform.position = position;
  67. if (this.m_IsMoveend)
  68. {
  69. break;
  70. }
  71. }
  72. this.PosYFixed();
  73. yield return null;
  74. }
  75. this.PosYFixed();
  76. BlackjackGame.Instance.DealQueue.CardTimer = timer;
  77. this.MovingCallback(base.gameObject);
  78. yield break;
  79. yield break;
  80. }
  81. private IEnumerator CardOpen()
  82. {
  83. float timer = this.InitTime;
  84. if (this.CurrentState != Card.CardState.Open)
  85. {
  86. yield break;
  87. }
  88. bool near_hand = false;
  89. for (;;)
  90. {
  91. if (!near_hand)
  92. {
  93. near_hand = (timer > this.StartTime);
  94. if (near_hand)
  95. {
  96. BlackjackGame.Instance.CardSe.Play();
  97. }
  98. }
  99. else
  100. {
  101. base.transform.position = BjMotionControl.Instance.LeftHandPos();
  102. float t = KasaiUtility.SinRate01(timer - this.StartTime, this.m_OpenTime, false, false);
  103. base.transform.eulerAngles = Vector3.Lerp(CardDeck.Instance.FlipdownAngle, CardDeck.Instance.FlipupAngle, t);
  104. if (timer > this.CardSetTime)
  105. {
  106. break;
  107. }
  108. }
  109. this.PosYFixed();
  110. yield return null;
  111. timer += Time.deltaTime;
  112. }
  113. this.PosYFixed();
  114. Dealer.Instance.SetCardOffset();
  115. if (this.OpenCallback != null)
  116. {
  117. this.OpenCallback(base.gameObject);
  118. }
  119. yield break;
  120. yield break;
  121. }
  122. public void MoveToPosition(Card.FinishedMoving callback)
  123. {
  124. if (this.m_IsMoveend)
  125. {
  126. return;
  127. }
  128. base.transform.eulerAngles = CardDeck.Instance.FlipdownAngle;
  129. this.MovingCallback = callback;
  130. base.StartCoroutine(this.CardMove());
  131. }
  132. public void Open(Card.FinishedOpen callback)
  133. {
  134. this.OpenCallback = callback;
  135. this.CurrentState = Card.CardState.Open;
  136. base.StartCoroutine(this.CardOpen());
  137. }
  138. public const float m_CardWidth = 0.035f;
  139. public const float m_CardHeight = 0.05f;
  140. private Card.FinishedOpen OpenCallback;
  141. private Card.FinishedMoving MovingCallback;
  142. private bool m_IsMoveend;
  143. [HideInInspector]
  144. public Card.CardState CurrentState;
  145. [HideInInspector]
  146. public Vector3 EndPosition;
  147. [HideInInspector]
  148. public Transform CardSet;
  149. [HideInInspector]
  150. public CardData CardData;
  151. [SerializeField]
  152. [HideInInspector]
  153. private MeshRenderer m_MyRenderer;
  154. [HideInInspector]
  155. public float InitTime;
  156. [HideInInspector]
  157. public float StartTime;
  158. [HideInInspector]
  159. public float CardSetTime;
  160. [HideInInspector]
  161. public float SwitchTime;
  162. private float m_OpenTime;
  163. public enum CardState
  164. {
  165. FlipUp,
  166. FlipDown,
  167. Open
  168. }
  169. public delegate void FinishedMoving(GameObject card);
  170. public delegate void FinishedOpen(GameObject card);
  171. }