Skip to content

Instantly share code, notes, and snippets.

@kimsama
Created May 1, 2013 05:28
Show Gist options
  • Save kimsama/5493884 to your computer and use it in GitHub Desktop.
Save kimsama/5493884 to your computer and use it in GitHub Desktop.
MonoBehaviour supports async loading progress status. (original post from http://unitystudy.net/bbs/board.php?bo_table=tip&wr_id=52)
using UnityEngine;
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();
//progress 변수로 0.0f ~ 1.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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment