1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// This component is responsible for moving the Loading Progress Sperm which represents the currently
- /// loaded progress of the game scene. When complete, it will zip out of screen.
- /// </summary>
- public class LoadingProgressSperm : MonoBehaviour
- {
- public float minX = 0;
- public float maxX = 634;
- public float offRightScreenX = 1000;
- public float smoothFactor = 0.8f;
- float _targetX = 0;
- void OnEnable()
- {
- NotificationCenter.AddListener(OnLoadingProgress, NotificationType.LoadingProgress);
- NotificationCenter.AddListener(OnLoadingStartFadeOut, NotificationType.LoadingStartFadeOut);
- }
- void OnDisable()
- {
- NotificationCenter.RemoveListener(OnLoadingProgress, NotificationType.LoadingProgress);
- NotificationCenter.RemoveListener(OnLoadingStartFadeOut, NotificationType.LoadingStartFadeOut);
- }
- void Update()
- {
- Vector3 pos = transform.localPosition;
- pos.x = _targetX * smoothFactor + pos.x * (1 - smoothFactor);
- transform.localPosition = pos;
- }
-
- void OnLoadingProgress(Notification note)
- {
- float progress = (float)note.data;
- _targetX = Mathf.Lerp(minX, maxX, progress);
- }
- void OnLoadingStartFadeOut(Notification note)
- {
- enabled = false;
- SoundManager.Play(SoundEvent.spermout);
- iTween.MoveTo(gameObject, iTween.Hash(
- "islocal", true,
- "x", offRightScreenX,
- "time", 1,
- "easetype", iTween.EaseType.easeInCubic,
- "oncomplete", "OniTweenComplete",
- "oncompletetarget", gameObject));
- }
- void OniTweenComplete()
- {
- Destroy(gameObject);
- }
- }
|