123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- 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;
- private float dur = 1.5f;
- // 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 = dur;
- }
- }
- 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 = dur;
- // }
- // 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 = dur;
- tween.Play(true);
- }
- yield return new WaitForSeconds(1.5f);
- Destroy(gameObject);
-
- }
- }
|