You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.1 KiB
119 lines
3.1 KiB
using UnityEngine; |
|
using System.Collections; |
|
using UnityEngine.UI; |
|
using AX.MessageSystem; |
|
public class SceneProgressBar : MonoBehaviour { |
|
|
|
|
|
|
|
//异步对象 |
|
private AsyncOperation _asyncOperation; |
|
//显示tips的文本 |
|
public Text _tip; |
|
//tips的集合 |
|
private string[] _tips = new string[] |
|
{ |
|
".", |
|
"..", |
|
"...", |
|
"...." |
|
}; |
|
//更新tips的时间间隔 |
|
private const float _updateTime = 0.3f; |
|
//上次更新的时间 |
|
private float _lastUpdateTime = 0; |
|
//滑动条 |
|
//public Slider _slider; |
|
//显示进度的文本 |
|
//public Text _progress; |
|
// Use this for initialization |
|
|
|
public static string SceneName; |
|
void Start() |
|
{ |
|
EquipSubmit.costSelectedEquips.Clear(); |
|
EquipSubmit.unCostSelectedEquips.Clear(); |
|
SceneProGress(); |
|
//this.gameObject.SetActive(false); |
|
} |
|
void SceneProGress() |
|
{ |
|
StartCoroutine(LoadAsync(SceneName)); |
|
} |
|
void OnDestroy() |
|
{ |
|
//MessageDispatcher.RemoveListener("SceneProGress", SceneProGress); |
|
} |
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
//首先判断是否为空,其次判断是否加载完毕 |
|
|
|
//开始更新tips |
|
if (Time.time - _lastUpdateTime >= _updateTime) |
|
{ |
|
_lastUpdateTime = Time.time; |
|
SetTip(); |
|
} |
|
if (kong) |
|
{ |
|
i += Time.deltaTime; |
|
if (i > 4) |
|
{ |
|
_asyncOperation.allowSceneActivation = true; |
|
kong = false; |
|
} |
|
} |
|
} |
|
/// <summary> |
|
/// 设置加载标签 |
|
/// </summary> |
|
int temp=0; |
|
float i = 0; |
|
private void SetTip() |
|
{ |
|
if (temp > 3) |
|
{ |
|
temp = 0; |
|
} |
|
_tip.text = _tips[temp]; |
|
temp++; |
|
|
|
} |
|
bool kong = false; |
|
/// <summary> |
|
/// 携程进行异步加载场景 |
|
/// </summary> |
|
/// <param name="sceneName">需要加载的场景名</param> |
|
/// <returns></returns> |
|
IEnumerator LoadAsync(string sceneName) |
|
{ |
|
//当前进度 |
|
int currentProgress = 0; |
|
//目标进度 |
|
int targetProgress = 0; |
|
//_asyncOperation = MySceneManager.LoadSceneAsync(sceneName); |
|
_asyncOperation = MySceneManager.LoadSceneAsync(1); |
|
//unity 加载90% |
|
_asyncOperation.allowSceneActivation = false; |
|
while (_asyncOperation.progress < 0.9f) |
|
{ |
|
targetProgress = (int)_asyncOperation.progress * 100; |
|
//平滑过渡 |
|
while (currentProgress < targetProgress) |
|
{ |
|
++currentProgress; |
|
|
|
yield return new WaitForEndOfFrame(); |
|
} |
|
} |
|
//自行加载剩余的10% |
|
targetProgress = 100; |
|
while (currentProgress < targetProgress) |
|
{ |
|
++currentProgress; |
|
yield return new WaitForEndOfFrame(); |
|
} |
|
kong = true; |
|
} |
|
}
|
|
|