//=============================================================================// //============ Lifecycle Methods //=============================================================================// #region Lifecycle Methods /// <summary> /// Unity's Awake lifecycle /// Will initialize all member's variables and always add the scene containing SceneLoader as the first scene (this one will not be delete in any case) /// </summary> private void Awake() { _currentProcess = null; _collection = new SceneCollection(); InternalSceneData loaderScene = new InternalSceneData(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name, true, false, true, "MainSceneBundle", true); SceneLoaderEvents.TriggerOnSceneLoadedInternal(loaderScene); }
/// <summary> /// Unity's Update lifecycle /// Will manage the process queue by dequeuing when the scene loader is free and not handling a process. /// When a scene loader is handling a process, it will manage event of Start and Finish of the process. /// It will internally call update on the current process. /// </summary> private void Update() { // If there is a process currently handle call the update on it // If the current process has ended, call the event to specify that the process ended // and set the process currently handed to null (allowing the scene loaded to handle a new one) if (_currentProcess != null) { _currentProcess.UpdateProcess(); if (_currentProcess.ProcessFinish) { SceneLoaderEvents.TriggerOnLoaderProcessFinish(); _currentProcess = null; } } }
//=============================================================================// //============ Public Methods //=============================================================================// #region Public Methods public void UpdateProcess() { // Exit update method if there is not current operation processing and all // requests has been treated if (_requests.Count == 0 && _currentOperation == null) { return; } // We are sure that there is still request to treat, so if no operation is processing // start a new one by dequeuing the next request if (_currentRequest == null) { _currentRequest = _requests.Dequeue(); _currentOperation = _currentRequest.DoOperation(); _currentOperation.allowSceneActivation = false; } // Processing the current operation. // We ensure that allowSceneActivation is only set to true if the request is not the last to be treated, or // if we have exceeded the minimum loading time required. // If the current operation is done, we trigger the event and clean to process a new request. bool isNotLastRequest = IsLastRequest() == false; bool minimumTimerExceeded = _currentProcessTimer >= _minimumProcessTime; bool allowSceneActivation = isNotLastRequest || minimumTimerExceeded; _currentOperation.allowSceneActivation = allowSceneActivation; _currentProcessProgress = _currentOperation.progress; SceneLoaderEvents.TriggerOnLoaderProcessUpdate(_currentRequest.GetDescription(), SmoothProgress); if (_currentOperation.isDone && allowSceneActivation) { _globalProcessProgress += 1f; _currentRequest.DoEvents(); _currentRequest = null; _currentOperation = null; } _currentProcessTimer += Time.deltaTime; }
public override void DoEvents() { SceneLoaderEvents.TriggerOnSceneLoaded(_sceneData.SceneName); SceneLoaderEvents.TriggerOnSceneLoadedInternal(_sceneData); }
//=============================================================================// //============ Internal Methods //=============================================================================// #region Internal Methods internal void SendRequest(Queue <InternalSceneRequest> requests) { _currentProcess = new SceneLoaderProcess(_minimumLoadingTime, requests); SceneLoaderEvents.TriggerOnLoaderProcessStart(); }