123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using UnityEngine;
- using System.Collections;
- public class ScreenSnowController : MonoBehaviour
- {
- public static ScreenSnowController Instance { get; private set; }
- [SerializeField] private TweenAlpha [] _tweens;
- private int _index;
- private bool forward = true;
- // Use this for initialization
- private void Start()
- {
- if (!Instance)
- {
- Instance = this;
- return;
- }
- //foreach (var tween in _tweens)
- //{
- // tween.onFinished.Add(new EventDelegate(OnTweenFinished));
- //}
- //foreach (var tween in _tweens)
- //{
- // tween.duration = 0.3f;
- //}
- }
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.F3))
- {
- Duplicate();
- }
- }
- //private void OnTweenFinished()
- //{
- // if (forward)
- // {
- // _index++;
- // if (_index == _tweens.Length)
- // {
- // forward = false;
- // foreach (var tween in _tweens)
- // {
- // tween.duration = 1f;
- // }
- // foreach (var tween in _tweens)
- // {
- // tween.onFinished.Clear();
- // }
- // foreach (var tween in _tweens)
- // {
- // tween.onFinished.Add(new EventDelegate(OnTweenFinished));
- // }
- // _tweens[_tweens.Length - 1].Play(false);
- // }
- // else
- // {
- // _tweens[_index].Play(true);
- // }
- // }
- // else
- // {
- // _index--;
- // if (_index < 0)
- // {
- // Destroy(gameObject);
- // }
- // else
- // {
- // _tweens[_tweens.Length - 1].Play(false);
- // }
- // }
- //}
- public void Duplicate()
- {
- var go = Instantiate(gameObject);
- go.transform.parent = transform.parent;
- go.transform.position = transform.position;
- go.transform.localScale = transform.localScale;
- go.SendMessage("Snow");
- }
- private void Snow()
- {
- StartCoroutine(Fade());
- }
- private IEnumerator Fade()
- {
- foreach (var tween in _tweens)
- {
- tween.duration = 0.3f;
- tween.Play(true);
- }
- yield return new WaitForSeconds(0.4f);
- for (int i = _tweens.Length - 1; i >= 0; i--)
- {
- _tweens[i].duration = 0.5f;
- _tweens[i].Play(false);
- yield return new WaitForSeconds(0.3f);
- }
- Destroy(gameObject);
- }
- }
|