123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// This component is used by the loading background sperms. They are fadeout according to the scaling
- /// to give the illusion of depth. The fading out is accomplished by darkening the color actually.
- /// </summary>
- public class FadeOutAccordingToScale : MonoBehaviour
- {
- public float minAlpha = 0.1f;
- public float maxAlpha = 0.5f;
- bool _isSetup;
- float _percentageBlack;
- void OnEnable()
- {
- //have to delay setup on update due to pooling
- _isSetup = false;
- NotificationCenter.AddListener(OnFadeOutUpdate, NotificationType.LoadingFadeOutUpdate);
- }
- void OnDisable()
- {
- NotificationCenter.RemoveListener(OnFadeOutUpdate, NotificationType.LoadingFadeOutUpdate);
- }
- void Update()
- {
- if (!_isSetup)
- {
- _percentageBlack = minAlpha + (maxAlpha - minAlpha) * transform.parent.localScale.y;
- SetBlackness(_percentageBlack);
- _isSetup = true;
- }
- }
- void SetBlackness(float p)
- {
- GetComponent<Renderer>().material.SetColor("_TintColor", new Color(p, p, p, 0.5f));
- }
- void OnFadeOutUpdate(Notification note)
- {
- float fadeOutPercentage = (float)note.data;
- SetBlackness(_percentageBlack * fadeOutPercentage);
- }
- }
|