代码拉取完成,页面将自动刷新
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Events;
using System.IO;
public class Launch : MonoBehaviour
{
public UnityEvent<string> currentFile;
public UnityEvent<float> currentProgress;
private UnityWebRequestAsyncOperation ao;
private bool gameUPdateComplated = false;
public GameObject gameUPdateUI;
private IEnumerator Start()
{
//编辑器模式:根基你点的运行菜单,确定使用哪种资源加载方式
//发布后:设置为运行时资源加载模式
AssetManager.instance.Init();
if (AssetManager.instance.loadMode == LoadMode.runTime)
{
////////////////////////////////////////更新资源之前执行的逻辑//////////////////////
if (AssetManager.instance.LoadAssetMap())//判断一下是否为第一运行游戏
{
//需要先加载一次资源映射表
yield return new WaitForSeconds(0.5f);
//可以等待用户点击屏幕,或者欢迎视频播放结束
//可以在这里执行一些更新游戏之前的逻辑
}
////////////////////////////////////////////更新资源////////////////////////////////////////////
if (AssetManager.instance.loadMode == LoadMode.runTime)
{
gameUPdateUI.SetActive(true);
//注册资源更新事件
GameUpdate.instance.OnBeginDownLoadOne = OnBeginDownLoadOne;
GameUpdate.instance.onDownAllComplated = onDownAllComplated;
//更新
GameUpdate.instance.UpdateAsset();
yield return new WaitUntil(() => gameUPdateComplated == true);//等待游戏更新完成
Debug.Log("游戏更新完成");
}
//加载资源映射表
AssetManager.instance.LoadAssetMap();
}
LuaManager.instance.Init();
/* //加载初始场景
SceneLoader.LoadScene(firstScenePath);*/
LuaManager.instance.luaEnv.DoString("require 'Main' ");
Destroy(this.gameObject);
}
private void onDownAllComplated()
{
gameUPdateComplated = true;
}
private void OnBeginDownLoadOne(UnityWebRequestAsyncOperation ao)
{
this.ao = ao;
Debug.Log($"正在下载{Path.GetFileName(ao.webRequest.url)}");
currentFile.Invoke(Path.GetFileName(ao.webRequest.url));
currentProgress.Invoke(ao.progress);
}
private void Update()
{
if (gameUPdateComplated == false && ao != null)
{
currentProgress.Invoke(ao.progress);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。