unity C#
[Unity] unity loading bar 구현
bamsik
2019. 5. 16. 15:23
반응형
using UnityEngine; using System.Collections; using UnityEngine.UI; using DG.Tweening; using UnityEngine.SceneManagement; public delegate void ProgressDelegate(float progress); public class LoadSceneAsyncProgress : MonoBehaviour { public Image ProgressBar; public CanvasGroup CG_Loading; void Start() { CG_Loading.DOFade (0.5f, 0.5f).SetEase (Ease.Linear).SetLoops (-1, LoopType.Yoyo); StartCoroutine(LoadSceneAsyncByName("FamilyHomeVI_SR", OnLoadLevelProgressUpdate)); } public static IEnumerator LoadSceneAsyncByName(string nextLevel, ProgressDelegate progressDelegate) { AsyncOperation async = SceneManager.LoadSceneAsync(nextLevel); while (!async.isDone) { progressDelegate (async.progress); async.allowSceneActivation = async.progress > 0.8; yield return null; } } private void OnLoadLevelProgressUpdate(float progress) { ProgressBar.fillAmount = progress; Debug.Log ("async.progress: " + progress); } }
참조 : https://gist.github.com/crowjdh/26272392e425063cbd69586cd542a46d
Getting progress while loading scene in Unity using SceneManager.LoadSceneAsync.
Getting progress while loading scene in Unity using SceneManager.LoadSceneAsync. - UnityLoadSceneAsyncProgress.cs
gist.github.com
참조 : https://docs.unity3d.com/ScriptReference/AsyncOperation-progress.html
Unity - Scripting API: AsyncOperation.progress
Return an operation's progress. (Read Only) This returns how close the operation is to finishing. The operation is finished when the progress float reaches 1.0 and isDone is called. If you set allowSceneActivation to false, progress is halted at 0.9 until
docs.unity3d.com
반응형