LoadEffectComponent.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. namespace WS
  3. {
  4. [ObjectSystem]
  5. public class LoadEffectComponentAwakeSystem : AwakeSystem<LoadEffectComponent>
  6. {
  7. public override void Awake(LoadEffectComponent self)
  8. {
  9. var go = Resources.Load<GameObject>("Material/LoadingEffect/LoadingEffect");
  10. self.loadEffect = GameObject.Instantiate(go, Game.Init);
  11. self.loadEffectMat = Resources.Load<Material>("Material/LoadingEffect/FullScreen_FullScreenCustomPass");
  12. }
  13. }
  14. [ObjectSystem]
  15. public class LoadEffectComponentUpdateSystem : UpdateSystem<LoadEffectComponent>
  16. {
  17. public override void Update(LoadEffectComponent self)
  18. {
  19. if (self.isPlay)
  20. {
  21. if (self.timer <= self.durtaion)
  22. {
  23. self.timer += Time.deltaTime;
  24. if (self.isShow)
  25. {
  26. self.loadEffectMat.SetFloat("_EffectTimer", 1);
  27. }
  28. else
  29. {
  30. self.loadEffectMat.SetFloat("_EffectTimer", Mathf.Lerp(1, 0, self.timer / self.durtaion));
  31. }
  32. }
  33. else
  34. {
  35. self.isPlay=false;
  36. self.timer=0;
  37. }
  38. }
  39. }
  40. }
  41. public class LoadEffectComponent : WSComponent
  42. {
  43. public GameObject loadEffect;
  44. public Material loadEffectMat;
  45. public bool isPlay;
  46. public bool isShow;
  47. public float timer=0;
  48. public float durtaion=2f;
  49. public void PlayLoadEffect(bool show)
  50. {
  51. isPlay = true;
  52. isShow = show;
  53. }
  54. }
  55. }