123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- 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<Detonator>().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<iTween>();
- 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;
- }
|