private void SaveService_OnPreLoad(CoroutineEvent coroutineEvent) { SceneLoadInfo sceneLoadInfo = ServiceLocator.SaveService.GetSaveData <SceneLoadInfo>(Animator.StringToHash("PreviousScene")); sceneLoadInfo.fromSave = true; coroutineEvent.coroutines.Add(LoadScene(sceneLoadInfo)); }
//TODO: This should probably be a coroutine so we can wait for scenes to unload/load. public IEnumerator LoadSavedData(string filePath) { if (currentGameSave == null) { if (!LoadGameSaveFromFile(filePath)) { yield break; } } DevTools.Logger.Log(SaveServiceLog, "Started Loading Save."); // Tell objects we are about to load. (Used to load the correct scene definition as an example). CoroutineEvent preLoadCoroutines = new CoroutineEvent(); OnPreLoad(preLoadCoroutines); yield return(preLoadCoroutines.WaitForCoroutines()); // Reinstantiate the SaveableGameObjects foreach (SavedGameObject savedGameObject in currentGameSave.savedPooledObjects) { //TODO: Need to consider how to handle transform parents. Should it be done here or by the SaveableGameObjectComponent. ServiceLocator.PoolService.SpawnDefinition <SaveableGameObject>(savedGameObject.gameObjectPool.ObjectReference, null, false, (x) => x.GetComponent <SaveableGameObject>().ApplySaveData(savedGameObject)); } // Tell objects we have loaded the data. OnPostLoad(); DevTools.Logger.Log(SaveServiceLog, "Finished Loading Save."); }
async Task Waiter(int n, CoroutineEvent go, CoroutineEvent ready) { while (true) { await go.WaitAsync(); go.Reset(); await Task.Delay(500).ConfigureAwait(false); Console.WriteLine("Waiter #" + n + " + run, thread: " + Thread.CurrentThread.ManagedThreadId); ready.Set(); } }
async Task RunAsync() { var ready1 = new CoroutineEvent(initialState: true); var go1 = new CoroutineEvent(initialState: false); var ready2 = new CoroutineEvent(initialState: true); var go2 = new CoroutineEvent(initialState: false); var ready3 = new CoroutineEvent(initialState: true); var go3 = new CoroutineEvent(initialState: false); var waiter1 = Waiter(1, go1, ready1); var waiter2 = Waiter(2, go2, ready2); var waiter3 = Waiter(3, go3, ready3); while (true) { await ready1.WaitAsync(); ready1.Reset(); await ready2.WaitAsync(); ready2.Reset(); await ready3.WaitAsync(); ready2.Reset(); Console.WriteLine("new round"); go1.Set(); go2.Set(); go3.Set(); } }
internal Awaiter(CoroutineEvent owner) { _owner = owner; }