浏览代码

Removed array of scenes from loading

/main
Ciro Continisio 4 年前
当前提交
a1ce890c
共有 13 个文件被更改,包括 62 次插入106 次删除
  1. 14
      UOP1_Project/Assets/Scenes/Initialization.unity
  2. 9
      UOP1_Project/Assets/Scenes/Locations/Beach.unity
  3. 3
      UOP1_Project/Assets/Scenes/Locations/Forest.unity
  4. 3
      UOP1_Project/Assets/Scenes/Locations/Glade.unity
  5. 7
      UOP1_Project/Assets/Scenes/WIP/TestingGround.unity
  6. 10
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/LoadEventChannelSO.cs
  7. 4
      UOP1_Project/Assets/Scripts/SaveSystem/FileManager.cs
  8. 12
      UOP1_Project/Assets/Scripts/SaveSystem/SaveSystem.cs
  9. 2
      UOP1_Project/Assets/Scripts/SceneManagement/EditorColdStartup.cs
  10. 9
      UOP1_Project/Assets/Scripts/SceneManagement/InitializationLoader.cs
  11. 4
      UOP1_Project/Assets/Scripts/SceneManagement/LocationExit.cs
  12. 85
      UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs
  13. 6
      UOP1_Project/Assets/Scripts/SceneManagement/StartGame.cs

14
UOP1_Project/Assets/Scenes/Initialization.unity


--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2

m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2

manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}

m_Script: {fileID: 11500000, guid: 43bf3a70578af0044a7af79dd1c44ea6, type: 3}
m_Name:
m_EditorClassIdentifier:
_persistentManagersScene: {fileID: 11400000, guid: c2119785ce96367428081d6eee0d932b,
type: 2}
_menuToLoad:
- {fileID: 11400000, guid: 431ff81b74b48fb4d9301fb76ca633dd, type: 2}
_showLoadScreen: 1
_managersScene: {fileID: 11400000, guid: c2119785ce96367428081d6eee0d932b, type: 2}
_menuToLoad: {fileID: 11400000, guid: 431ff81b74b48fb4d9301fb76ca633dd, type: 2}
m_EditorAssetChanged: 0
--- !u!4 &1266309721
Transform:
m_ObjectHideFlags: 0

9
UOP1_Project/Assets/Scenes/Locations/Beach.unity


m_Script: {fileID: 11500000, guid: 02e6b73898a4a52438d630a7ba29da77, type: 3}
m_Name:
m_EditorClassIdentifier:
_locationsToLoad:
- {fileID: 11400000, guid: d102ba8fe3b291249aeb9de4b95c1904, type: 2}
_locationToLoad: {fileID: 11400000, guid: d102ba8fe3b291249aeb9de4b95c1904, type: 2}
_showLoadScreen: 1
_pathTaken: {fileID: 11400000, guid: a9ec09853cba047a8a58f5881053cfc6, type: 2}
_exitPath: {fileID: 11400000, guid: 050fcf2d8a1044670b51fc2358167588, type: 2}

m_Script: {fileID: 11500000, guid: 02e6b73898a4a52438d630a7ba29da77, type: 3}
m_Name:
m_EditorClassIdentifier:
_locationsToLoad:
- {fileID: 11400000, guid: 3902a4362b3a4fb4ab5ce5dcc07d8427, type: 2}
_locationToLoad: {fileID: 11400000, guid: 3902a4362b3a4fb4ab5ce5dcc07d8427, type: 2}
_showLoadScreen: 1
_pathTaken: {fileID: 11400000, guid: a9ec09853cba047a8a58f5881053cfc6, type: 2}
_exitPath: {fileID: 11400000, guid: 447b413e95f8c95489b5385f03982ec5, type: 2}

m_Script: {fileID: 11500000, guid: 02e6b73898a4a52438d630a7ba29da77, type: 3}
m_Name:
m_EditorClassIdentifier:
_locationsToLoad:
- {fileID: 11400000, guid: 1514f833150a79e4c9d242f58bdbcbc0, type: 2}
_locationToLoad: {fileID: 11400000, guid: 1514f833150a79e4c9d242f58bdbcbc0, type: 2}
_showLoadScreen: 0
_pathTaken: {fileID: 11400000, guid: a9ec09853cba047a8a58f5881053cfc6, type: 2}
_exitPath: {fileID: 11400000, guid: 02c13d612a86149a8b354b877b9f261f, type: 2}

3
UOP1_Project/Assets/Scenes/Locations/Forest.unity


m_Script: {fileID: 11500000, guid: 02e6b73898a4a52438d630a7ba29da77, type: 3}
m_Name:
m_EditorClassIdentifier:
_locationsToLoad:
- {fileID: 11400000, guid: 2f386bbc670c05145834a0f9c7d55798, type: 2}
_locationToLoad: {fileID: 11400000, guid: 2f386bbc670c05145834a0f9c7d55798, type: 2}
_showLoadScreen: 0
_pathTaken: {fileID: 11400000, guid: a9ec09853cba047a8a58f5881053cfc6, type: 2}
_exitPath: {fileID: 11400000, guid: 050fcf2d8a1044670b51fc2358167588, type: 2}

3
UOP1_Project/Assets/Scenes/Locations/Glade.unity
文件差异内容过多而无法显示
查看文件

7
UOP1_Project/Assets/Scenes/WIP/TestingGround.unity
文件差异内容过多而无法显示
查看文件

10
UOP1_Project/Assets/Scripts/Events/ScriptableObjects/LoadEventChannelSO.cs


using UnityEngine.Events;
/// <summary>
/// This class is a used for scene loading events.
/// Takes an array of the scenes we want to load and a bool to specify if we want to show a loading screen.
/// This class is used for scene-loading events.
/// Takes a GameSceneSO of the location or menu that needs to be loaded, and a bool to specify if a loading screen needs to display.
public UnityAction<GameSceneSO[], bool> OnLoadingRequested;
public UnityAction<GameSceneSO, bool> OnLoadingRequested;
public void RaiseEvent(GameSceneSO[] locationsToLoad, bool showLoadingScreen = false)
public void RaiseEvent(GameSceneSO locationToLoad, bool showLoadingScreen = false)
OnLoadingRequested.Invoke(locationsToLoad, showLoadingScreen);
OnLoadingRequested.Invoke(locationToLoad, showLoadingScreen);
}
else
{

4
UOP1_Project/Assets/Scripts/SaveSystem/FileManager.cs


}
catch (Exception e)
{
//Debug.LogError($"Failed to write to {fullPath} with exception {e}");
Debug.LogError($"Failed to write to {fullPath} with exception {e}");
return false;
}
}

}
catch (Exception e)
{
//Debug.LogError($"Failed to read from {fullPath} with exception {e}");
Debug.LogError($"Failed to read from {fullPath} with exception {e}");
result = "";
return false;
}

12
UOP1_Project/Assets/Scripts/SaveSystem/SaveSystem.cs


_loadLocation.OnLoadingRequested -= CacheLoadLocations;
}
private void CacheLoadLocations(GameSceneSO[] locationsToLoad, bool showLoadingScreen)
private void CacheLoadLocations(GameSceneSO locationsToLoad, bool showLoadingScreen)
LocationSO locationSo = locationsToLoad[0] as LocationSO;
if (locationSo)
LocationSO locationSO = locationsToLoad as LocationSO;
if (locationSO)
saveData._locationId = locationSo.Guid;
saveData._locationId = locationSO.Guid;
}
SaveDataToDisk();

yield return loadItemOperationHandle;
if (loadItemOperationHandle.Status == AsyncOperationStatus.Succeeded)
{
var itemSo = loadItemOperationHandle.Result;
_playerInventory.Add(itemSo, serializedItemStack.amount);
var itemSO = loadItemOperationHandle.Result;
_playerInventory.Add(itemSO, serializedItemStack.amount);
}
}
}

2
UOP1_Project/Assets/Scripts/SceneManagement/EditorColdStartup.cs


private void ReloadScene(AsyncOperationHandle<LoadEventChannelSO> obj)
{
LoadEventChannelSO loadEventChannelSO = (LoadEventChannelSO)_loadSceneEventChannel.Asset;
loadEventChannelSO.RaiseEvent(new GameSceneSO[] { _thisSceneSO });
loadEventChannelSO.RaiseEvent(_thisSceneSO);
SceneManager.UnloadSceneAsync(_thisSceneSO.sceneReference.editorAsset.name);
}

9
UOP1_Project/Assets/Scripts/SceneManagement/InitializationLoader.cs


public class InitializationLoader : MonoBehaviour
{
[Header("Persistent managers Scene")]
[SerializeField] private GameSceneSO _persistentManagersScene = default;
[Header("Loading settings")]
[SerializeField] private GameSceneSO[] _menuToLoad = default;
[SerializeField] private GameSceneSO _managersScene = default;
[SerializeField] private GameSceneSO _menuToLoad = default;
[Header("Broadcasting on")]
[SerializeField] private AssetReference _menuLoadChannel = default;

//Load the persistent managers scene
_persistentManagersScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true).Completed += LoadEventChannel;
_managersScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true).Completed += LoadEventChannel;
}
private void LoadEventChannel(AsyncOperationHandle<SceneInstance> obj)

4
UOP1_Project/Assets/Scripts/SceneManagement/LocationExit.cs


public class LocationExit : MonoBehaviour
{
[Header("Loading settings")]
[SerializeField] private GameSceneSO[] _locationsToLoad = default;
[SerializeField] private GameSceneSO _locationToLoad = default;
[SerializeField] private bool _showLoadScreen = default;
[SerializeField] private PathAnchor _pathTaken = default;
[SerializeField] private PathSO _exitPath = default;

if (other.CompareTag("Player"))
{
UpdatePathTaken();
_locationExitLoadChannel.RaiseEvent(_locationsToLoad, _showLoadScreen);
_locationExitLoadChannel.RaiseEvent(_locationToLoad, _showLoadScreen);
}
}

85
UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs


[SerializeField] private BoolEventChannelSO _toggleLoadingScreen = default;
[SerializeField] private VoidEventChannelSO _onSceneReady = default;
private List<AsyncOperationHandle<SceneInstance>> _loadingOperationHandles = new List<AsyncOperationHandle<SceneInstance>>();
private AsyncOperationHandle<SceneInstance> _loadingOperationHandle;
private GameSceneSO[] _scenesToLoad;
private GameSceneSO[] _currentlyLoadedScenes = new GameSceneSO[] { };
private GameSceneSO _sceneToLoad;
private GameSceneSO _currentlyLoadedScene;
private bool _showLoadingScreen;
private SceneInstance _gameplayManagerSceneInstance = new SceneInstance();

/// <summary>
/// This function loads the location scenes passed as array parameter
/// </summary>
private void LoadLocation(GameSceneSO[] locationsToLoad, bool showLoadingScreen)
private void LoadLocation(GameSceneSO locationToLoad, bool showLoadingScreen)
_scenesToLoad = locationsToLoad;
_sceneToLoad = locationToLoad;
//In case we are coming from the main menu, we need to load the persistent Gameplay manager scene first
//In case we are coming from the main menu, we need to load the Gameplay manager scene first
StartCoroutine(ProcessGameplaySceneLoading(locationsToLoad, showLoadingScreen));
_gameplayManagerLoadingOpHandle = _gameplayScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true);
_gameplayManagerLoadingOpHandle.Completed += OnGameplayMangersLoaded;
UnloadPreviousScenes();
UnloadPreviousScene();
private IEnumerator ProcessGameplaySceneLoading(GameSceneSO[] locationsToLoad, bool showLoadingScreen)
private void OnGameplayMangersLoaded(AsyncOperationHandle<SceneInstance> obj)
_gameplayManagerLoadingOpHandle = _gameplayScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true);
while (_gameplayManagerLoadingOpHandle.Status != AsyncOperationStatus.Succeeded)
{
yield return null;
}
UnloadPreviousScenes();
UnloadPreviousScene();
private void LoadMenu(GameSceneSO[] menusToLoad, bool showLoadingScreen)
private void LoadMenu(GameSceneSO menuToLoad, bool showLoadingScreen)
_scenesToLoad = menusToLoad;
_sceneToLoad = menuToLoad;
_showLoadingScreen = showLoadingScreen;
//In case we are coming from a Location back to the main menu, we need to get rid of the persistent Gameplay manager scene

UnloadPreviousScenes();
UnloadPreviousScene();
private void UnloadPreviousScenes()
private void UnloadPreviousScene()
for (int i = 0; i < _currentlyLoadedScenes.Length; i++)
{
_currentlyLoadedScenes[i].sceneReference.UnLoadScene();
}
if(_currentlyLoadedScene != null)
_currentlyLoadedScene.sceneReference.UnLoadScene();
LoadNewScenes();
LoadNewScene();
/// Kicks off the asynchronous loading of an array of scenes, either menus or Locations.
/// Kicks off the asynchronous loading of a scene, either menu or Location.
private void LoadNewScenes()
private void LoadNewScene()
{
if (_showLoadingScreen)
{

_loadingOperationHandles.Clear();
//Build the array of handles of the temporary scenes to load
for (int i = 0; i < _scenesToLoad.Length; i++)
{
_loadingOperationHandles.Add(_scenesToLoad[i].sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true, 0));
}
StartCoroutine(LoadingProcess());
_loadingOperationHandle = _sceneToLoad.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true, 0);
_loadingOperationHandle.Completed += OnNewSceneLoaded;
private IEnumerator LoadingProcess()
private void OnNewSceneLoaded(AsyncOperationHandle<SceneInstance> obj)
bool done = _loadingOperationHandles.Count == 0;
//This while will exit when all scenes requested have been unloaded
while (!done)
{
for (int i = 0; i < _loadingOperationHandles.Count; ++i)
{
if (_loadingOperationHandles[i].Status != AsyncOperationStatus.Succeeded)
{
break;
}
else
{
done = true;
}
}
yield return null;
}
_currentlyLoadedScenes = _scenesToLoad;
_currentlyLoadedScene = _sceneToLoad;
SetActiveScene();
if (_showLoadingScreen)

}
/// <summary>

{
//All the scenes have been loaded, so we assume the first in the array is ready to become the active scene
Scene s = ((SceneInstance)_loadingOperationHandles[0].Result).Scene;
Scene s = ((SceneInstance)_loadingOperationHandle.Result).Scene;
SceneManager.SetActiveScene(s);
LightProbes.TetrahedralizeAsync();

6
UOP1_Project/Assets/Scripts/SceneManagement/StartGame.cs


public class StartGame : MonoBehaviour
{
public LoadEventChannelSO onPlayButtonPress;
public GameSceneSO[] locationsToLoad;
public GameSceneSO locationsToLoad;
public bool showLoadScreen;
public SaveSystem saveSystem;

yield return asyncOperationHandle;
if (asyncOperationHandle.Status == AsyncOperationStatus.Succeeded)
{
var locationSo = asyncOperationHandle.Result;
onPlayButtonPress.RaiseEvent(new[] { (GameSceneSO)locationSo }, showLoadScreen);
LocationSO locationSO = asyncOperationHandle.Result;
onPlayButtonPress.RaiseEvent(locationSO, showLoadScreen);
}
}
}
正在加载...
取消
保存