[Unity] Scene

gest·2025년 6월 3일

unity

목록 보기
1/6
using UnityEngine.SceneManagement;

//0 인덱스 로드
SceneManager.LoadScene(0);

//현재 Scene 로드
SceneManager.LoadScene(SceneManager.GetActiveScene().name);

//다음 Scene 로드
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);

씬 제거 함수

SceneManager.UnloadScene 함수를 쓴다.
SceneManager.UnloadScene();

  • 씬 제거

SceneManager.UnloadSceneAsync(index);

  • 비동기로 제거

비동기 실행

AssetReference를 사용하려면 Addressable 라이브러리가 있어야 한다.


addressable을 설치한다.


이후 groups 설정하면 된다.

using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

//클래스 내부
public AssetReference scenes;
AsyncOperation op = 
	scenes.LoadSceneAsync(LoadSceneMode.Additive, bool activateOnLoad);

매개변수1

  • LoadSceneMode.Additive : 기존의 scene에 scenes를 추가하는 느낌 [기존의 scene는 제거X]
  • LoadSceneMode.Single : 기존의 scene를 제거하고 scenes를 로딩

매개변수2

  • activateOnLoad : true면 완료 되자마자 Scene 실행

이후에 op.isDone으로 아직 끝났는지 안끝났는지 판단 가능
op.allowSceneActivation = true; //scene 장면 활성화

  • scene.IsValid;
    • 씬의 내용이 존재하지 않으면 false
    • 가끔 비동기로 씬이 가끔 없는 경우가 있다.

0개의 댓글