Skip to content

sceen 사이에 로딩창 구현 비동기 적으로 로드 해야함 #9

@ohjichal

Description

@ohjichal

신 사이에 로딩창 구현 비동기적으로 신을 호출 하면 된다.

https://freeedeveloper.tistory.com/entry/Unity-%EC%94%AC%EC%9D%84-%EC%A0%84%ED%99%98%ED%95%A0-%EB%95%8C-%EB%A1%9C%EB%94%A9%EC%9D%84-%EA%B1%B8%EC%96%B4%EB%B3%B4%EC%9E%90-%EC%94%AC-%EB%B9%84%EB%8F%99%EA%B8%B0-%EB%A1%9C%EB%94%A9-%EB%A1%9C%EB%94%A9%EC%B0%BD-%EA%B5%AC%ED%98%84

기본 구현

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LoadSceneManager : MonoBehaviour
{
    float time = 0;
    public void LoadScene(string name){
        StartCoroutine(LoadingAsync(name));
    }

    IEnumerator LoadingAsync(string name){
        AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(name);
        asyncOperation.allowSceneActivation = false; //로딩이 완료되는대로 씬을 활성화할것인지
        
        while(!asyncOperation.isDone){ //isDone는 로딩이 완료되었는지 확인하는 변수
            time += Time.deltaTime; //시간을 더해줌
            print(asyncOperation.progress); //로딩이 얼마나 완료되었는지 0~1의 값으로 보여줌
            
            //이건 로딩이 너무 빨라서 작성한거라, 무거운 씬 로딩할땐 시간 체크하는 부분은
            //생략해도 무방하다!
            if(time > 3){ //3초 기다림(변동가능)
                asyncOperation.allowSceneActivation = true; //씬 활성화
            }
            yield return null;
        }
    }
}

구현 시 생각 해야할 점

드레그엔 드롭으로 3개에 신을 다뤄야 한다.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions