Suggest a change Success!Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close Submission failedFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation. Close Your name Your email Suggestion* Cancel Parameters
ReturnsAsyncOperation Use the AsyncOperation to determine if the operation has completed. DescriptionLoads the Scene asynchronously in the background. You can provide the full Scene path, the path shown in the Build Settings window, or just the Scene name. If you only provide the Scene name, Unity loads the first Scene in the list that matches. If you have multiple Scenes with the same name but different paths, you should use the full Scene path in the Build Settings. Examples of supported formats: Note: Scene name input is not case-sensitive. Note: The name of the Scene to load can be case insensitive. If a single mode scene is loaded, Unity calls Resources.UnloadUnusedAssets automatically. using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; 1. 씬 (Scene)경찰, 범죄 등과 관련된 영화나 드라마를 보게 되면, Crime Scene이라는 노란색 테이프로 현장을 막아놓은 장면들이 나온다. 범죄에 사용된 물건, 사물 등이 존재하는 사건 현장이 씬이다. 씬은 캐릭터, 장애물, 벽, 지면 등의 요소들을 포함한다. 게임 설계에 따라, 게임은 단일 씬으로 구성되거나, 여러 개의 씬으로 구성될 수 있다. 각각의 Level을 하나의 Scene에서 구성할 수 있으며, 각각의 레벨에 대응하는 여러 개의 씬으로 구성할 수 있다. 또한, 씬은 씬을 하위 요소처럼 불러와 사용할 수 있다. 2. 씬 전환 (Scene transition)유니티는 SceneManager 클래스를 사용해 씬 전환을 제어할 수 있다. 씬 전환을 제어하는 방식은 동기화 방식과 비동기화 방식으로 나눌 수 있다. 동기화 방식은 씬을 호출하는 행동 이외에, 다른 작업을 수행하지 않는다. 비동기화 방식은 씬을 호출하는 동시에 현재 진행 중인 작업을 계속 실행하고, 씬의 호출이 완료되면, 씬을 불러온다. 씬을 Single과 Addictive 모드로 불러올 수 있다. LoadSceneMode.Single은 현재 씬을 종료하고, 새로운 씬을 로드하는 방법이다. LoadSceneMode.Addictive는 현재 씬 위에 추가적으로 새로운 씬을 불러온다. 2.1 SceneManagementSceneManager 클래스를 사용하기 위해서는 SceneManagement namespace를 지정해야 한다.
namespace는 클래스가 정의된 공간 또는 영역이다. 클래스가 정의된 공간에 접근하기 위해 "using" 키워드를 사용한다. 2.2 LoadSceneSceneManager 클래스의 LoadScene("SceneName")을 사용하여 씬을 불러온다. 씬은 Name(string) 또는 BuildIndex(integer) 값을 이용해 불러올 수 있다. BuildIndex는 Build Settings의 Index 값이다. File → Build Settings → Scenes in Build
2.3 LoadSceneAsync()LoadSceneAsynce()는 비동기적으로 Scene을 호출한다. 유니티는 씬을 불러올 때, 동기적으로 호출하는 LoadScene() 대신, LoadSceneAsync()를 사용할 것을 권한다. LoadScene()은 중지 또는 약간의 지연 등이 발생할 수 있기 때문이다. LoadSceneAsync()은 AsyncOperation 클래스를 리턴 값으로 전달한다. AsyncOperation 프로퍼티로 현재 씬의 호출 상태를 알수 있다. 아래는 각 프로퍼티에 대한 설명이다.
이해를 돕기위해, Unity documents의 일부분을 발췌하였다. "In most cases, to avoid pauses or performance hiccups while loading, you should use the asynchronous version of this command which is: LoadSceneAsync."
3. 데이터 공유여러 개의 Scene으로 구성된 게임은 Scene들 간의 이동 시 데이터 공유 등이 요구된다. 가령 캐릭터가 A 씬에서 B씬으로 이동할 때, 캐릭터의 HP, MP 등의 데이터를 넘겨주어야 한다. 실제 게임 오브젝트를 넘기는 것이 아닌 데이터를 파일로 저장하고, 새로운 씬이 호출되면, 저장된 값을 불러와 사용하도록 설정한다. 아래의 예제 코드는 PlayerPrefs 컴포넌트를 사용하였다. PlayerPrefs는 각 세션간에 데이터를 저장하고, 접근하도록 구현한 유니티 컴포넌트이다. float, int, string 타입을 지원한다.
참고자료 docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html Unity - Scripting API: SceneManagement.SceneManager.LoadScene Note: In most cases, to avoid pauses or performance hiccups while loading, you should use the asynchronous version of this command which is: LoadSceneAsync. When using SceneManager.LoadScene, the scene loads in the next frame, that is it does not load imme docs.unity3d.com |