异步加载的优点就是,加载大量资源的时候是后台加载,而不是像同步加载那样,直接卡住.影响软件体验.
Start()方法直接调用:
void Start ()
{
noteLoading.GetComponent<Text>().text = "加载中,请稍候...";
StartCoroutine(LoadingPicFunc_0());
}
协程的返回值:
IEnumerator LoadingPicFunc_0()
{
for (int i = 0; i < 601; i++)//
{
string path = "pic/c_00" + i.ToString().PadLeft(3, '0');//Resources文件夹下的路径,末尾一般是数据,0补齐.例如:00031;
ResourceRequest request = Resources.LoadAsync(path);
yield return request;
if (request != null)
{
if (request.isDone)
{
print(i.ToString());
Texture tex = request.asset as Texture;
logoList.Add(tex);//加入到申明的数据列表
noteLoading.GetComponent<Text>().text ="正在加载第"+ i.ToString()+"张";
}
}
}
noteLoading.SetActive(false);
isStartPictureAnim = true;
}
网友评论