Last active
November 25, 2016 09:32
-
-
Save gegagome/6dd833082b67aae6ce6cf0a36177717e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.SceneManagement; | |
using System.Collections; | |
using DG.Tweening; | |
using UnityEngine.UI; | |
/* | |
UnityAction<Scene, Scene> activeSceneChanged; | |
UnityAction<Scene, LoadSceneMode> sceneLoaded; | |
UnityAction<Scene> sceneUnloaded; | |
*/ | |
public class LoadingScreen : MonoBehaviour | |
{ | |
public Image _thisImage; | |
public RectTransform _spinRect; | |
public static LoadingScreen _instance; | |
RectTransform _thisRect; | |
float _imageHeight; | |
Sequence _loadingScreen; | |
bool _isHidden = true; | |
void Awake () { | |
if (_instance == null) { | |
_instance = this; | |
DontDestroyOnLoad(gameObject); | |
SceneManager.sceneLoaded += SceneLoaded; | |
// SceneManager.activeSceneChanged += SceneChange; | |
} else { | |
Destroy(gameObject); | |
} | |
_thisRect = _thisImage.GetComponent<RectTransform>(); | |
_imageHeight = GetComponent<Canvas>().rectTransform().sizeDelta.y; | |
} | |
void Start() { | |
Debug.Log(_thisRect.anchoredPosition); | |
_thisRect.anchoredPosition = new Vector2(_thisRect.anchoredPosition.x, 0f); | |
_loadingScreen = DOTween.Sequence().SetAutoKill(false).Pause(); | |
_loadingScreen.Append(_thisRect.DOAnchorPosY(_imageHeight, 0.3f).SetEase(Ease.Linear)); | |
// _thisRect.anchoredPosition = Vector2.zero; | |
_loadingScreen.PlayForward(); | |
// _loadingScreen.Append(_thisRect.DOAnchorPosY(0f, 0.3f).SetEase(Ease.InCubic)).Insert(0f, _rectRotatingImage.DOLocalRotate(new Vector3(0f, 0f, 90f), 1f, RotateMode.Fast).SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental) | |
// ); | |
} | |
void LoadingScreenSwitch () { | |
if (_isHidden) { | |
_loadingScreen.PlayBackwards(); | |
} else { | |
_loadingScreen.PlayForward(); | |
} | |
_isHidden = !_isHidden; | |
Debug.Log("Loading Screen"); | |
} | |
public void LoadScene (string scene) { | |
StartCoroutine("PlayBackwardsSequence", scene); | |
} | |
IEnumerator PlayBackwardsSequence (string scene) { | |
_loadingScreen.PlayBackwards(); | |
yield return new WaitForSeconds(0.3f); | |
SceneManager.LoadSceneAsync(scene); | |
} | |
void SceneChange (Scene previousScene, Scene newScene) { | |
LoadingScreenSwitch(); | |
} | |
void SceneLoaded (Scene newScene, LoadSceneMode sceneMode) { | |
_loadingScreen.PlayForward(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment