LoadingProgressSperm.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using UnityEngine;
  2. using System.Collections;
  3. /// <summary>
  4. /// This component is responsible for moving the Loading Progress Sperm which represents the currently
  5. /// loaded progress of the game scene. When complete, it will zip out of screen.
  6. /// </summary>
  7. public class LoadingProgressSperm : MonoBehaviour
  8. {
  9. public float minX = 0;
  10. public float maxX = 634;
  11. public float offRightScreenX = 1000;
  12. public float smoothFactor = 0.8f;
  13. float _targetX = 0;
  14. void OnEnable()
  15. {
  16. NotificationCenter.AddListener(OnLoadingProgress, NotificationType.LoadingProgress);
  17. NotificationCenter.AddListener(OnLoadingStartFadeOut, NotificationType.LoadingStartFadeOut);
  18. }
  19. void OnDisable()
  20. {
  21. NotificationCenter.RemoveListener(OnLoadingProgress, NotificationType.LoadingProgress);
  22. NotificationCenter.RemoveListener(OnLoadingStartFadeOut, NotificationType.LoadingStartFadeOut);
  23. }
  24. void Update()
  25. {
  26. Vector3 pos = transform.localPosition;
  27. pos.x = _targetX * smoothFactor + pos.x * (1 - smoothFactor);
  28. transform.localPosition = pos;
  29. }
  30. void OnLoadingProgress(Notification note)
  31. {
  32. float progress = (float)note.data;
  33. _targetX = Mathf.Lerp(minX, maxX, progress);
  34. }
  35. void OnLoadingStartFadeOut(Notification note)
  36. {
  37. enabled = false;
  38. SoundManager.Play(SoundEvent.spermout);
  39. iTween.MoveTo(gameObject, iTween.Hash(
  40. "islocal", true,
  41. "x", offRightScreenX,
  42. "time", 1,
  43. "easetype", iTween.EaseType.easeInCubic,
  44. "oncomplete", "OniTweenComplete",
  45. "oncompletetarget", gameObject));
  46. }
  47. void OniTweenComplete()
  48. {
  49. Destroy(gameObject);
  50. }
  51. }