PaperAirplaneTarget.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class PaperAirplaneTarget : MonoBehaviour
  5. {
  6. public void PopupPosition(Vector3 pos)
  7. {
  8. foreach (BoxCollider boxCollider in this.mainColliders)
  9. {
  10. boxCollider.enabled = true;
  11. }
  12. base.transform.position = pos;
  13. this.popEffect.Stop();
  14. this.popEffect.Clear();
  15. this.popEffect.Play();
  16. this.StopTween();
  17. this.modelTransform.localRotation = Quaternion.identity;
  18. this.modelTransform.localScale = Vector3.zero;
  19. iTween.ScaleTo(this.modelTransform.gameObject, iTween.Hash(new object[]
  20. {
  21. "Scale",
  22. new Vector3(1f, 0f, 1f),
  23. "islocal",
  24. true,
  25. "time",
  26. 0,
  27. "delay",
  28. 1
  29. }));
  30. Hashtable args = iTween.Hash(new object[]
  31. {
  32. "Scale",
  33. Vector3.one,
  34. "islocal",
  35. true,
  36. "time",
  37. 1f,
  38. "easeType",
  39. iTween.EaseType.easeOutQuint,
  40. "delay",
  41. 1
  42. });
  43. iTween.ScaleTo(this.modelTransform.gameObject, args);
  44. }
  45. public void Die()
  46. {
  47. foreach (BoxCollider boxCollider in this.mainColliders)
  48. {
  49. boxCollider.enabled = false;
  50. }
  51. this.StopTween();
  52. base.GetComponentInChildren<Detonator>().Explode();
  53. Hashtable args = iTween.Hash(new object[]
  54. {
  55. "easeType",
  56. iTween.EaseType.easeInSine,
  57. "from",
  58. 0,
  59. "to",
  60. 1,
  61. "time",
  62. 0.6,
  63. "onUpdate",
  64. "OnUpdateDrop",
  65. "oncomplete",
  66. "OnCompleteDrop"
  67. });
  68. iTween.ValueTo(base.gameObject, args);
  69. }
  70. public void Vanish()
  71. {
  72. foreach (BoxCollider boxCollider in this.mainColliders)
  73. {
  74. boxCollider.enabled = false;
  75. }
  76. this.StopTween();
  77. this.popEffect.Stop();
  78. this.popEffect.Clear();
  79. this.popEffect.Play();
  80. this.StopTween();
  81. Hashtable args = iTween.Hash(new object[]
  82. {
  83. "easetype",
  84. iTween.EaseType.easeOutQuint,
  85. "from",
  86. 0,
  87. "to",
  88. 2,
  89. "time",
  90. 0.7f,
  91. "delay",
  92. 0.5f,
  93. "onUpdate",
  94. "OnUpdateVanish",
  95. "oncomplete",
  96. "OnCompleteVanish"
  97. });
  98. iTween.ValueTo(base.gameObject, args);
  99. }
  100. public void OnThrowObjectCorrectionVelocity(Transform throwTrans, ref Vector3 linearVelocity, ref Vector3 angularVelocity)
  101. {
  102. if (this.correctionColliders == null || this.correctionColliders.Length <= 0)
  103. {
  104. return;
  105. }
  106. float magnitude = linearVelocity.magnitude;
  107. int layer = this.correctionColliders[0].gameObject.layer;
  108. Ray ray = new Ray(throwTrans.position, linearVelocity);
  109. RaycastHit raycastHit;
  110. if (Physics.Raycast(ray, out raycastHit, float.PositiveInfinity, 1 << layer))
  111. {
  112. for (int i = 0; i < this.correctionColliders.Length; i++)
  113. {
  114. if (this.correctionColliders[i] == raycastHit.collider)
  115. {
  116. float num = 0f;
  117. foreach (BoxCollider boxCollider in this.mainColliders)
  118. {
  119. num = Mathf.Max(num, boxCollider.bounds.size.z / 2f);
  120. }
  121. num = UnityEngine.Random.Range(0f, num);
  122. if (raycastHit.collider.transform.position.z < base.transform.position.z)
  123. {
  124. num *= -1f;
  125. }
  126. float y = linearVelocity.y;
  127. Vector3 position = base.transform.position;
  128. position = new Vector3(position.x, position.y, position.z + num);
  129. linearVelocity = position - throwTrans.transform.position;
  130. Vector3 vector = new Vector3(linearVelocity.x, y, linearVelocity.z);
  131. linearVelocity = vector.normalized * magnitude;
  132. }
  133. }
  134. }
  135. }
  136. private void OnCompleteDrop()
  137. {
  138. this.Vanish();
  139. }
  140. private void OnUpdateDrop(float value)
  141. {
  142. this.modelTransform.localRotation = Quaternion.Euler(Vector3.Lerp(Vector3.zero, new Vector3(0f, 0f, 90f), value));
  143. }
  144. private void OnUpdateVanish(float value)
  145. {
  146. value = Mathf.Clamp(value, 0f, 1f);
  147. float num = 1f - value;
  148. this.modelTransform.localScale = new Vector3(num, num, num);
  149. }
  150. private void OnCompleteVanish()
  151. {
  152. this.StopTween();
  153. if (this.onEndAnimationVanish != null)
  154. {
  155. this.onEndAnimationVanish();
  156. }
  157. }
  158. private void StopTween()
  159. {
  160. GameObject[] array = new GameObject[]
  161. {
  162. this.modelTransform.gameObject,
  163. base.gameObject
  164. };
  165. foreach (GameObject gameObject in array)
  166. {
  167. iTween.Stop(gameObject);
  168. Component[] components = gameObject.GetComponents<iTween>();
  169. foreach (iTween obj in components)
  170. {
  171. UnityEngine.Object.Destroy(obj);
  172. }
  173. }
  174. }
  175. [SerializeField]
  176. private BoxCollider[] mainColliders;
  177. [SerializeField]
  178. private Collider[] correctionColliders;
  179. [SerializeField]
  180. private ParticleSystem popEffect;
  181. [SerializeField]
  182. public Transform modelTransform;
  183. public Action onEndAnimationVanish;
  184. }