1 Star 0 Fork 0

熊峻玉 / unity-dev-framework2212

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Launch.cs 2.54 KB
一键复制 编辑 原始数据 按行查看 历史
熊峻玉 提交于 2023-03-26 09:36 . .
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);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/xiongks/DevFrameWork.git
git@gitee.com:xiongks/DevFrameWork.git
xiongks
DevFrameWork
unity-dev-framework2212
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891