using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.InputSystem;
public class SceneChanger : MonoBehaviour
{
private void OnGUI()
{
if(GUI.Button(new Rect(20, 40, 400, 400), "씬 로딩 버튼"))
{
StartCoroutine(Loading());
//SceneManager.LoadScene("SampleScene"); // 동기식으로 씬 불러오기
//var oper = SceneManager.LoadSceneAsync("SampleScene"); // 비동기식으로 씬 불러오기
//oper.progress; // 로딩 진척률 반환
//oper.isDone; // 다 로딩 했으면 참 반환
//oper.completed+=; // 다 로딩 했으면 할 메서드 등록
}
}
IEnumerator Loading()
{
AsyncOperation oper = SceneManager.LoadSceneAsync("SampleScene"); // 비동기식으로 씬 불러오기
oper.allowSceneActivation = false; // 작업 완료 후 , 씬 전환을 즉시 시행할 지 여부
while(oper.isDone == false) // 로딩이 끝나지 않았다면
{
//Debug.Log(oper.progress); // 진행상황 출력
if(oper.progress < 0.9f)
{
// 로딩 중일때 해야 할 그런 코드들. 로딩 이미지 출력이라던지..
// 로딩바.value = oper.progress;
Debug.Log(oper.progress);
}
else // 로딩이 끝남
{
if(Keyboard.current.qKey.isPressed) // q 키가 눌렸다면
{
oper.allowSceneActivation = true;
}
}
yield return null;
}
}
}