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

45 行
1.5 KiB

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;
/// <summary>
/// Allows a "cold start" in the editor, when pressing Play and not passing from the Initialisation scene.
/// </summary>
public class EditorColdStartup : MonoBehaviour
{
#if UNITY_EDITOR
[SerializeField] private GameSceneSO _thisSceneSO = default;
[SerializeField] private GameSceneSO _persistentManagersSO = default;
[SerializeField] private AssetReference _notifyColdStartupChannel = default;
[SerializeField] private VoidEventChannelSO _onSceneReadyChannel = default;
private void Start()
{
if (!SceneManager.GetSceneByName(_persistentManagersSO.sceneReference.editorAsset.name).isLoaded)
{
_persistentManagersSO.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true).Completed += LoadEventChannel;
}
}
private void LoadEventChannel(AsyncOperationHandle<SceneInstance> obj)
{
_notifyColdStartupChannel.LoadAssetAsync<LoadEventChannelSO>().Completed += OnNotifyChannelLoaded;
}
private void OnNotifyChannelLoaded(AsyncOperationHandle<LoadEventChannelSO> obj)
{
if(_thisSceneSO != null)
{
obj.Result.RaiseEvent(_thisSceneSO);
}
else
{
//Raise a fake scene ready event, so the player is spawned
_onSceneReadyChannel.RaiseEvent();
//When this happens, the player won't be able to move between scenes because the SceneLoader has no conception of which scene we are in
}
}
#endif
}