加载过程需要自己编写脚本,命名为ProgressBar_Test往里面添加代码:
变量部分:
public UIProgressBar bar;
public UILabel label;
public UIEasing.EasingType easing = UIEasing.EasingType.easeLinear;
public float duration = 2f;
public float startDelay = 0f;
public float holdTime = 1f;
public bool startFromZero = false;
private bool started = false;
private bool ascending = false;
一运行时执行:
void Start()
{
if (this.bar == null)
this.bar = this.GetComponent<UIProgressBar>();
if (this.startFromZero)
{
this.ascending = true;
this.bar.value = 0f;
this.UpdateLabel();
}
}
当Bar存在的时候放在OnEnable中执行:
更新部分代码:
这个脚本挂上后即完成了下载条的加载动画部分,下面需要加载完跳转进入下一个场景:
脚本命名:LoadSceneTest代码部分如下
public string sceneName;//这个直接在Inspector面板中填上需要跳转的场景的名字就行
public UIProgressBar bar;
public float requiredValue = 1f;
public bool ignoreFirst = true;
public void LoadScene()
{
Application.LoadLevel(sceneName);
}
//给脚本UIProgressbar脚本的OnValueChange赋值
public void OnProgress()
{
if (this.ignoreFirst)
{
this.ignoreFirst = false;
return;
}
if (this.bar != null && this.bar.value >= this.requiredValue)
LoadScene();
}
NGUI的比较简单因为出来得早很成熟了,我主要是做个笔记,接下来写下用UGUI实现的方法
相比而言,简单多了,所以还是新生的好吧,只需要一个背景Image再加上一个filled类型的Image
再添加一个Text文本就可以制作了,代码也可以很简洁,贴上:
public UnityEngine.UI.Text text;
public UnityEngine.UI.Image loadbar;
IEnumerator Start()
{
for (int i = 0; i < 120; i++)
{
loadbar.fillAmount += 1 / 120f;
text.text = ((i+1) * 100 / 120).ToString() + "%";
小细节就是从0开始到99就跳转了,从1开始正好百分之百
yield return new WaitForEndOfFrame();
}
SceneManager.LoadScene("HomeScene");
这里的名字也可以像上面那样从面板里填,这样写也行,简单点如果不改场景名的话
}
随着版本的更新,再进行修改,目前还是觉得UGUI顺手,毕竟我一开始学就是用的ugui,NGUI还有适应中,最近
又出了个FairyGUI,国内的一插件挺好用,有空看看。