浏览代码

Revert "Proposed fix for issue #229 with test scenes"

This reverts commit 14a6a3a062c3979cf9fef8d3b156c560f6fcd27b.
/main
jandd661 4 年前
当前提交
b7efdfcb
共有 6 个文件被更改,包括 39 次插入151 次删除
  1. 109
      UOP1_Project/Assets/Scripts/SceneManagement/LocationLoader.cs
  2. 9
      UOP1_Project/ProjectSettings/EditorBuildSettings.asset
  3. 24
      UOP1_Project/Assets/ScriptableObjects/SceneData/Locations/Test01.asset
  4. 24
      UOP1_Project/Assets/ScriptableObjects/SceneData/Locations/Test02.asset
  5. 24
      UOP1_Project/Assets/ScriptableObjects/SceneData/Locations/Test03.asset

109
UOP1_Project/Assets/Scripts/SceneManagement/LocationLoader.cs


using UnityEngine.UI;
/// <summary>
/// This class manages the scene loading and unloading.
/// Heavy on comments right now because it is still being worked on.
/// This class manages the scenes loading and unloading
/// </summary>
public class LocationLoader : MonoBehaviour
{

//List of the scenes to load and track progress
private List<AsyncOperation> _scenesToLoadAsyncOperations = new List<AsyncOperation>();
//List of scenes to unload
private List<Scene> _scenesToUnload = new List<Scene>();
private List<Scene> _ScenesToUnload = new List<Scene>();
private Coroutine runningLoader = null;
private void OnEnable()
{

LoadScenes(_mainMenuScenes, false);
}
/// <summary>
/// This function loads the scenes passed as array parameter
/// </summary>
/// <param name="locationsToLoad"></param>
/// <param name="showLoadingScreen"></param>
/// <summary> This function loads the scenes passed as array parameter </summary>
// Index 0 is the main scene to load and activate by default
//Add all current open scenes to unload list
AddScenesToUnload();
// Add all current open scenes to unload list
AddScenesToUnload();
// Unload the scenes
UnloadScenes();
for (int i = 0; i < locationsToLoad.Length; ++i)
{
String currentSceneName = locationsToLoad[i].sceneName;
if (!CheckLoadState(currentSceneName))
{
//Add the scene to the list of scenes to load asynchronously in the background
_scenesToLoadAsyncOperations.Add(SceneManager.LoadSceneAsync(currentSceneName, LoadSceneMode.Additive));
}
}
_scenesToLoadAsyncOperations[0].completed += SetActiveScene;
// Show the progress bar and track progress if loadScreen is true
//Show the progress bar and track progress if loadScreen is true
StartCoroutine(TrackLoadingProgress());
if(_scenesToLoadAsyncOperations.Count == 0)
else
for (int i = 0; i < locationsToLoad.Length; i++)
{
string currentSceneName = locationsToLoad[i].sceneName;
if (IsSceneLoaded(currentSceneName) == false)
{
//Add the scene to the list of scenes to load asynchronously in the background
if(runningLoader == null)
{
_scenesToLoadAsyncOperations.Add(SceneManager.LoadSceneAsync(currentSceneName, LoadSceneMode.Additive));
_scenesToLoadAsyncOperations[i].completed += SetActiveScene;
// TODO: Run a coroutine for each scene loading that updates a combined value
// for the progress bar. This way, as each scene completes loading, we will
// know what scene it is. Then decide if it activates right away or not.
// runningLoader = StartCoroutine(TrackLoadingProgress(locationsToLoad[i]));
}
}
}
//Clear the scenes to load
_scenesToLoadAsyncOperations.Clear();
}
if (_scenesToLoadAsyncOperations.Count > 0)
{
// TODO: locationsToLoad[0] is a place holder right now.
runningLoader = StartCoroutine(TrackLoadingProgress(locationsToLoad[0]));
}
}
//Unload the scenes
UnloadScenes();
/// <summary>
/// SetActiveScene(AsyncOperation asyncOp) is called by AsyncOperation.complete event.
/// </summary>
/// <param name="asyncOp"></param>
// TODO: As each event completes, decide if it needs to activate right away.
for (int i = 0; i < SceneManager.sceneCount; i++)
for (int i = 0; i < SceneManager.sceneCount; ++i)
if (scene.name != _initializationScene.sceneName && scene.name != _activeScene.name)
if (scene.name != _initializationScene.sceneName)
_scenesToUnload.Add(scene);
_ScenesToUnload.Add(scene);
}
}
}

if (_scenesToUnload != null)
if (_ScenesToUnload != null)
for (int i = 0; i < _scenesToUnload.Count; i++)
for (int i = 0; i < _ScenesToUnload.Count; ++i)
SceneManager.UnloadSceneAsync(_scenesToUnload[i]);
//Unload the scene asynchronously in the background
SceneManager.UnloadSceneAsync(_ScenesToUnload[i]);
_scenesToUnload.Clear();
_ScenesToUnload.Clear();
/// <summary>
/// This function checks if a scene is already loaded
/// </summary>
/// <param name="sceneName"></param>
/// <returns>bool</returns>
private bool IsSceneLoaded(string sceneName)
/// <summary> This function checks if a scene is already loaded </summary>
private bool CheckLoadState(String sceneName)
for (int i = 0; i < SceneManager.sceneCount; i++)
for (int i = 0; i < SceneManager.sceneCount; ++i)
{
Scene scene = SceneManager.GetSceneAt(i);
if (scene.name == sceneName)

return false;
}
/// <summary>
/// This function updates the loading progress once per frame until loading is complete
/// </summary>
/// <param name="sceneReference">This is a place holder for the moment</param>
/// <returns>IEnumerator</returns>
private IEnumerator TrackLoadingProgress(GameSceneSO sceneReference)
/// <summary> This function updates the loading progress once per frame until loading is complete </summary>
private IEnumerator TrackLoadingProgress()
{
float totalProgress = 0;
//When the scene reaches 0.9f, it means that it is loaded

//Iterate through all the scenes to load
for (int i = 0; i < _scenesToLoadAsyncOperations.Count; ++i)
{
Debug.Log("Scene " + i + " :" + _scenesToLoadAsyncOperations[i].isDone + " progress = " + _scenesToLoadAsyncOperations[i].progress);
Debug.Log("Scene" + i + " :" + _scenesToLoadAsyncOperations[i].isDone + "progress = " + _scenesToLoadAsyncOperations[i].progress);
Debug.Log("progress bar " + _loadingProgressBar.fillAmount + " and value = " + totalProgress / _scenesToLoadAsyncOperations.Count);
Debug.Log("progress bar" + _loadingProgressBar.fillAmount + "and value =" + totalProgress / _scenesToLoadAsyncOperations.Count);
yield return null;
}

runningLoader = null;
//Hide progress bar when loading is done
_loadingInterface.SetActive(false);

9
UOP1_Project/ProjectSettings/EditorBuildSettings.asset


- enabled: 1
path: Assets/Scenes/TestingGround.unity
guid: 1e57caa7d7ed5e24a88cb3b5c309cc65
- enabled: 1
path: Assets/Scenes/MultiSceneLoader/TestScene_03.unity
guid: fab260a559ee34842814a2d13b1c1798
- enabled: 1
path: Assets/Scenes/MultiSceneLoader/TestScene_02.unity
guid: 63d182036357bd94fb0fffb5af3736c0
- enabled: 1
path: Assets/Scenes/MultiSceneLoader/TestScene_01.unity
guid: 9bea58aee7d47cd45b9cc32b07287fcb
m_configObjects:
com.unity.addressableassets: {fileID: 11400000, guid: 758daf1c1b96e4978a5b9b3f5815abf1,
type: 2}

24
UOP1_Project/Assets/ScriptableObjects/SceneData/Locations/Test01.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8db63739a6674d74e8e232347422172f, type: 3}
m_Name: Test01
m_EditorClassIdentifier:
sceneName: TestScene_01
shortDescription: Find Y
music: {fileID: 0}
locationName:
m_TableReference:
m_TableCollectionName: GUID:5f392fa78068846188a7ed5595276c8f
m_TableEntryReference:
m_KeyId: 214189465600
m_Key:
enemiesCount: 0

24
UOP1_Project/Assets/ScriptableObjects/SceneData/Locations/Test02.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8db63739a6674d74e8e232347422172f, type: 3}
m_Name: Test02
m_EditorClassIdentifier:
sceneName: TestScene_02
shortDescription: Find Y
music: {fileID: 0}
locationName:
m_TableReference:
m_TableCollectionName: GUID:5f392fa78068846188a7ed5595276c8f
m_TableEntryReference:
m_KeyId: 214189465600
m_Key:
enemiesCount: 0

24
UOP1_Project/Assets/ScriptableObjects/SceneData/Locations/Test03.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8db63739a6674d74e8e232347422172f, type: 3}
m_Name: Test03
m_EditorClassIdentifier:
sceneName: TestScene_03
shortDescription: Find Y
music: {fileID: 0}
locationName:
m_TableReference:
m_TableCollectionName: GUID:5f392fa78068846188a7ed5595276c8f
m_TableEntryReference:
m_KeyId: 214189465600
m_Key:
enemiesCount: 0
正在加载...
取消
保存