这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

37 行
1.2 KiB

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;
/// <summary>
/// This class is responsible for starting the game by loading the persistent managers scene
/// and raising the event to load the Main Menu
/// </summary>
public class InitializationLoader : MonoBehaviour
{
[SerializeField] private GameSceneSO _managersScene = default;
[SerializeField] private GameSceneSO _menuToLoad = default;
[Header("Broadcasting on")]
[SerializeField] private AssetReference _menuLoadChannel = default;
private void Start()
{
//Load the persistent managers scene
_managersScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true).Completed += LoadEventChannel;
}
private void LoadEventChannel(AsyncOperationHandle<SceneInstance> obj)
{
_menuLoadChannel.LoadAssetAsync<LoadEventChannelSO>().Completed += LoadMainMenu;
}
private void LoadMainMenu(AsyncOperationHandle<LoadEventChannelSO> obj)
{
obj.Result.RaiseEvent(_menuToLoad);
SceneManager.UnloadSceneAsync(0); //Initialization is the only scene in BuildSettings, thus it has index 0
}
}