Unity3D/Tips
로딩 페이지 및 로딩 프로그래스바 사용하기.
blueasa
2014. 4. 14. 14:00
안녕하세요 유니티스터디에서 도움만 받는 잉여 회원 입니다.
로딩 페이지 구현? 에 고생해서 정식으로 유니티스터디를 통해서 올립니다.
AsyncOperation.progress라는 놈이 pc에서는 제대로된 값을 얻을 수 없어서 삽질을 많이 하셨습니다 ㅠㅠ
using UnityEngine;
using System.Collections;
using System.Collections;
public class EnterLoadPage : MonoBehaviour {
public UISlider Script;
public UISlider ScriptPercent;
public UILabel textScript;
AsyncOperation async;
bool IsLoadGame = false;
public IEnumerator StartLoad( string strSceneName )
{
if (IsLoadGame == false)
{
IsLoadGame = true;
AsyncOperation async = Application.LoadLevelAsync ( strSceneName );
while(async.isDone == false)
{
float p = async.progress *100f;
int pRounded = Mathf.RoundToInt(p);
textScript.text = pRounded.ToString();
public UISlider Script;
public UISlider ScriptPercent;
public UILabel textScript;
AsyncOperation async;
bool IsLoadGame = false;
public IEnumerator StartLoad( string strSceneName )
{
if (IsLoadGame == false)
{
IsLoadGame = true;
AsyncOperation async = Application.LoadLevelAsync ( strSceneName );
while(async.isDone == false)
{
float p = async.progress *100f;
int pRounded = Mathf.RoundToInt(p);
textScript.text = pRounded.ToString();
//progress 변수로 0.0f ~ 1.0f로 넘어 오기에 이용하면 됩니다.
ScriptPercent.sliderValue = async.progress;
yield return true;
}
}
}
void Start()
{
StartCoroutine( "StartLoad", "SceneGame" );
}
float fTime = 0.0f;
ScriptPercent.sliderValue = async.progress;
yield return true;
}
}
}
void Start()
{
StartCoroutine( "StartLoad", "SceneGame" );
}
float fTime = 0.0f;
//로딩 페이지에서 연속으로 애니메이션 만들때 Update 함수 내에서 만들면 됩니다.
void Update () {
fTime += Time.deltaTime;
if( fTime >= 1.0f )
{
fTime = 0.0f;
}
Script.sliderValue = fTime;
}
}
void Update () {
fTime += Time.deltaTime;
if( fTime >= 1.0f )
{
fTime = 0.0f;
}
Script.sliderValue = fTime;
}
}
사용법은
Scene과 로딩 부하가 심한 Scene 사이에 해당 ScenePage를 추가 하여 사용하시면 됩니다.
ex)
SceneMenu -> SceneLoadingPage -> SceneGame
읽어 주셔서 감사합니다.
출처 : http://www.unitystudy.net/bbs/board.php?bo_table=tip&wr_id=52
반응형