using System; using System.Collections; using UnityEngine; public class PaperAirplaneTarget : MonoBehaviour { public void PopupPosition(Vector3 pos) { foreach (BoxCollider boxCollider in this.mainColliders) { boxCollider.enabled = true; } base.transform.position = pos; this.popEffect.Stop(); this.popEffect.Clear(); this.popEffect.Play(); this.StopTween(); this.modelTransform.localRotation = Quaternion.identity; this.modelTransform.localScale = Vector3.zero; iTween.ScaleTo(this.modelTransform.gameObject, iTween.Hash(new object[] { "Scale", new Vector3(1f, 0f, 1f), "islocal", true, "time", 0, "delay", 1 })); Hashtable args = iTween.Hash(new object[] { "Scale", Vector3.one, "islocal", true, "time", 1f, "easeType", iTween.EaseType.easeOutQuint, "delay", 1 }); iTween.ScaleTo(this.modelTransform.gameObject, args); } public void Die() { foreach (BoxCollider boxCollider in this.mainColliders) { boxCollider.enabled = false; } this.StopTween(); base.GetComponentInChildren().Explode(); Hashtable args = iTween.Hash(new object[] { "easeType", iTween.EaseType.easeInSine, "from", 0, "to", 1, "time", 0.6, "onUpdate", "OnUpdateDrop", "oncomplete", "OnCompleteDrop" }); iTween.ValueTo(base.gameObject, args); } public void Vanish() { foreach (BoxCollider boxCollider in this.mainColliders) { boxCollider.enabled = false; } this.StopTween(); this.popEffect.Stop(); this.popEffect.Clear(); this.popEffect.Play(); this.StopTween(); Hashtable args = iTween.Hash(new object[] { "easetype", iTween.EaseType.easeOutQuint, "from", 0, "to", 2, "time", 0.7f, "delay", 0.5f, "onUpdate", "OnUpdateVanish", "oncomplete", "OnCompleteVanish" }); iTween.ValueTo(base.gameObject, args); } public void OnThrowObjectCorrectionVelocity(Transform throwTrans, ref Vector3 linearVelocity, ref Vector3 angularVelocity) { if (this.correctionColliders == null || this.correctionColliders.Length <= 0) { return; } float magnitude = linearVelocity.magnitude; int layer = this.correctionColliders[0].gameObject.layer; Ray ray = new Ray(throwTrans.position, linearVelocity); RaycastHit raycastHit; if (Physics.Raycast(ray, out raycastHit, float.PositiveInfinity, 1 << layer)) { for (int i = 0; i < this.correctionColliders.Length; i++) { if (this.correctionColliders[i] == raycastHit.collider) { float num = 0f; foreach (BoxCollider boxCollider in this.mainColliders) { num = Mathf.Max(num, boxCollider.bounds.size.z / 2f); } num = UnityEngine.Random.Range(0f, num); if (raycastHit.collider.transform.position.z < base.transform.position.z) { num *= -1f; } float y = linearVelocity.y; Vector3 position = base.transform.position; position = new Vector3(position.x, position.y, position.z + num); linearVelocity = position - throwTrans.transform.position; Vector3 vector = new Vector3(linearVelocity.x, y, linearVelocity.z); linearVelocity = vector.normalized * magnitude; } } } } private void OnCompleteDrop() { this.Vanish(); } private void OnUpdateDrop(float value) { this.modelTransform.localRotation = Quaternion.Euler(Vector3.Lerp(Vector3.zero, new Vector3(0f, 0f, 90f), value)); } private void OnUpdateVanish(float value) { value = Mathf.Clamp(value, 0f, 1f); float num = 1f - value; this.modelTransform.localScale = new Vector3(num, num, num); } private void OnCompleteVanish() { this.StopTween(); if (this.onEndAnimationVanish != null) { this.onEndAnimationVanish(); } } private void StopTween() { GameObject[] array = new GameObject[] { this.modelTransform.gameObject, base.gameObject }; foreach (GameObject gameObject in array) { iTween.Stop(gameObject); Component[] components = gameObject.GetComponents(); foreach (iTween obj in components) { UnityEngine.Object.Destroy(obj); } } } [SerializeField] private BoxCollider[] mainColliders; [SerializeField] private Collider[] correctionColliders; [SerializeField] private ParticleSystem popEffect; [SerializeField] public Transform modelTransform; public Action onEndAnimationVanish; }