Method UnloadSceneAsync
UnloadSceneAsync(SceneInstance, UnloadSceneOptions, bool)
Release scene
선언
public static AsyncOperationHandle<SceneInstance> UnloadSceneAsync(SceneInstance scene, UnloadSceneOptions unloadOptions, bool autoReleaseHandle = true)
파라미터
타입 | 이름 | 설명 |
---|---|---|
SceneInstance | scene | The SceneInstance to release. |
UnloadSceneOptions | unloadOptions | Specify behavior for unloading embedded scene objecs |
bool | autoReleaseHandle | If true, the handle will be released automatically when complete. |
반환
타입 | 설명 |
---|---|
AsyncOperationHandle<SceneInstance> | The operation handle for the scene unload. |
참고
UnloadSceneAsync releases a previously loaded scene. The scene must have been activated to be unloaded.
Passing UnloadSceneOptions.UnloadAllEmbeddedSceneObjects will unload assets embedded in the scene. The default is UploadSceneOptions.None which will only unload the scene's GameObjects.
예
// The idea with this sample is to show a simple streaming world. This has 3 events
// that work to load and unload scenes as required. Load would be triggered when
// the player gets close to the entrypoint. Activate would be called by doing
// something like "opening a door". And then unload could be called when the player
// crosses the entrypoint again in the other direction.
public class SceneGatewayManager {
// the Addressables key for the scene to load
[SerializeField]
public string sceneKey;
private AsyncOperationHandle<SceneInstance> sceneHandle;
public void EnterBoundary()
{
if (sceneHandle.IsValid() && sceneHandle.IsDone)
{
// do not reload if they have already passed the load boundary
return;
}
// load, but do not activate
var activateOnLoad = false;
// the scene is additive to keep our base scene and simply add a new area to it
sceneHandle = Addressables.LoadSceneAsync(sceneKey, LoadSceneMode.Additive, activateOnLoad);
}
public IEnumerator<AsyncOperationHandle<SceneInstance>> EnterScene()
{
// at this point we have to finish waiting for the scene to load if it
// hasn't already
yield return sceneHandle;
// this will activate the scene
sceneHandle.Result.ActivateAsync();
}
// exist boundary takes an optional cleanup callback that could be
// used to cleanup Assets after scene unload
public void ExitBoundary(Action cleanupCallback = null)
{
if (!sceneHandle.Result.Scene.isLoaded)
{
// scene has not been activated and cannot be unloaded
return;
}
var unloadHandle = Addressables.UnloadSceneAsync(sceneHandle, UnloadSceneOptions.None);
unloadHandle.Completed += (s) =>
{
if (cleanupCallback != null)
{
cleanupCallback();
}
};
}
}
UnloadSceneAsync(AsyncOperationHandle, UnloadSceneOptions, bool)
Release scene
선언
public static AsyncOperationHandle<SceneInstance> UnloadSceneAsync(AsyncOperationHandle handle, UnloadSceneOptions unloadOptions, bool autoReleaseHandle = true)
파라미터
타입 | 이름 | 설명 |
---|---|---|
AsyncOperationHandle | handle | The handle returned by LoadSceneAsync for the scene to release. |
UnloadSceneOptions | unloadOptions | Specify behavior for unloading embedded scene objecs |
bool | autoReleaseHandle | If true, the handle will be released automatically when complete. |
반환
타입 | 설명 |
---|---|
AsyncOperationHandle<SceneInstance> | The operation handle for the scene unload. |
UnloadSceneAsync(SceneInstance, bool)
Release scene
선언
public static AsyncOperationHandle<SceneInstance> UnloadSceneAsync(SceneInstance scene, bool autoReleaseHandle = true)
파라미터
타입 | 이름 | 설명 |
---|---|---|
SceneInstance | scene | The SceneInstance to release. |
bool | autoReleaseHandle | If true, the handle will be released automatically when complete. |
반환
타입 | 설명 |
---|---|
AsyncOperationHandle<SceneInstance> | The operation handle for the scene unload. |
UnloadSceneAsync(AsyncOperationHandle, bool)
Release scene
선언
public static AsyncOperationHandle<SceneInstance> UnloadSceneAsync(AsyncOperationHandle handle, bool autoReleaseHandle = true)
파라미터
타입 | 이름 | 설명 |
---|---|---|
AsyncOperationHandle | handle | The handle returned by LoadSceneAsync for the scene to release. |
bool | autoReleaseHandle | If true, the handle will be released automatically when complete. |
반환
타입 | 설명 |
---|---|
AsyncOperationHandle<SceneInstance> | The operation handle for the scene unload. |
UnloadSceneAsync(AsyncOperationHandle<SceneInstance>, bool)
Release scene
선언
public static AsyncOperationHandle<SceneInstance> UnloadSceneAsync(AsyncOperationHandle<SceneInstance> handle, bool autoReleaseHandle = true)
파라미터
타입 | 이름 | 설명 |
---|---|---|
AsyncOperationHandle<SceneInstance> | handle | The handle returned by LoadSceneAsync for the scene to release. |
bool | autoReleaseHandle | If true, the handle will be released automatically when complete. |
반환
타입 | 설명 |
---|---|
AsyncOperationHandle<SceneInstance> | The operation handle for the scene unload. |