您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
46 行
1.3 KiB
46 行
1.3 KiB
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
|
|
public class Loading : MonoBehaviour
|
|
{
|
|
private AsyncOperationHandle m_SceneHandle;
|
|
|
|
[SerializeField]
|
|
private Slider m_LoadingSlider;
|
|
|
|
[SerializeField]
|
|
private GameObject m_PlayButton;
|
|
|
|
void OnEnable()
|
|
{
|
|
m_SceneHandle = Addressables.DownloadDependenciesAsync("Level_0" + GameManager.s_CurrentLevel);
|
|
m_SceneHandle.Completed += OnSceneLoaded;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
m_SceneHandle.Completed -= OnSceneLoaded;
|
|
}
|
|
|
|
private void OnSceneLoaded(AsyncOperationHandle obj)
|
|
{
|
|
// We show the UI button once the scene is successfully downloaded
|
|
if(obj.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
m_PlayButton.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void GoToNextLevel()
|
|
{
|
|
Addressables.LoadSceneAsync("Level_0" + GameManager.s_CurrentLevel, UnityEngine.SceneManagement.LoadSceneMode.Single, true);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
// We don't need to check for this value every single frame, and certainly not after the scene has been loaded
|
|
m_LoadingSlider.value = m_SceneHandle.PercentComplete;
|
|
}
|
|
}
|