首页 > 编程知识 正文

unity导入asset文件,unity3d 开发框架

时间:2023-05-05 22:44:07 阅读:195515 作者:3413

客户端 运行

安装.net core
安装unity勾选ill2cpp否则打包界面报错:  currently selected scripting backend(il2cpp) is not installed 下载方法:https://unity.cn/releases 然后选择Release notes 然后选择Windows (IL2CPP) Target Support
先下载框架:https://github.com/egametang/ET Checkout时Choose items选择合适版本的
ET框架然后根据指南运行

框架

包含了
ILRuntime框架
MVC的思想

1.Model/Init.cs是程序的入口,然后GotoHotfix()运行热更的Hotfix/Init.cs
2.init首先会将有特性的component添加到system去使用,然后add需要用到的管理component到Game.Scene
3.热更代码写在Hotfix,4.0版本后的ET会自动生成DLL
ReferenceCollector类
Component基类和几个派生类,管理类


为什么会需要两份一样的代码呢

Model
我该其中一份比如Hotfix,我另外的Model也需要跟着改?
不会改
两份是因为要减少ILRuntime的跨域继承

 

写一个自定义UI

使用UI类<UIComponent>().Open→会根据是否创建来Create/Open→最后调到每个具体类的Create实行加载

1.在场景Global/UI下创建Canvas,然后添加需要增加的界面(如UI***)并编辑
2.添加ReferenceCollector组件-用于Get<>UI组件使用,添加CanvasConfig-用于设置CanvasName让ui预设寻找到自己的canvas
3.在UIType中添加新建的UI枚举-用于创建关闭和设定属性
4.模仿UILoginFactory类新建一个UI**Factory类-用于Game.Scene.GetComponent<UIComponent>().Creat(UIType.**)创建UI
5.UIComponent用于管理所有UI,Creat方法里执行了刚才的设置.
6.模仿UILoginComponent类新建一个UI***Component类,类里写UI的逻辑,可wzddc使用ReferenceCollector.Get<>方法获取组件

导配置表

1.在菜单栏Tools→导出配置→导出客户端表;
2.ET使用路径Client/Excel下的XML导到客户端Assets/Res/Config下的txt(json)
3.参考Client/Excel可以编辑自己的表,详细规则见ExcelExporterEditor.cs的ExportSheet()

 

打包 生成bingding code

1.生成固定类型的bingding code
2.分析DLL内类型生成bingding code

有服务器

1.资源预制体位于Bundles内,创建后添加ab名
2.Tools→打包工具 可选择打包平台 勾选打包exe:直接出包 点击打包

无服务器

1.注释网络下载ab包代码; 将Init里面下载ab包流程DownloadBundle内的下载代码注释掉
2.加载ab包地址改变;把LoadOneBundle内的下载load地址改为本地PathHelper.AppHotfixResPath→AppResPath
3.生成CLR binding code;点击Tools→ILRuntime→Generate CLR binding code by Analysis
4.打包ab资源;在打包工具勾选是否将资源打入exe 打包在本地(streamingAssets)

热更

1.代码生成DLL达到热更目的
热更       1.客户端逻辑全放在Hotfix热更  2.热更使用mono类型要先注册泛型
宏定义   IsAsync   IsEditorMode   IsDevelopmentBuild   IsILRuntime  

 

资源加载 ResourcesComponent

resourceCahce 是一个结构为<AbName,<assetName,Object>>的Res存储器
bundles 是一个用于ab技术的存储器
StringToAB() 每次调用都会加上".unity3d" 下次不用进行相加
BundleNameToLower()每次调用都会存起来 而不用每次都调用string的ToLower

使用AB

1.init ----- Init.cs调用Game.Scene.AddComponent<ResourcesComponent>();
2.获取 ---- Game.Scene.GetComponent<ResourcesComponent>()
3.加载ab ----- ResourcesComponent.LoadBundle($"{type}.unity3d")
4.计数  -----   ABInfo ref+1
5.Cache -----  ResourcesComponent的Dictionary<s,ab>bundles给Cache
6.LoadAsset ---- 会加载所有Asset(如果一个包很多资源会不必要加载 要视乎项目打包策略)
6.GetAsset ----- 从resourceCache用abname获取dict 用prefabName获取资源
                         调用:ResourcesComponent.GetAsset($"{type}.unity3d",$"{type}")
7.Unload   -----  ResourcesComponent.UnloadBundle 当引用为0释放

Editor使用AssetDatabase

1.获取路径 AssetDatabase.GetAssetPathsFromAssetBundle
2.获取名字 Path.GetFileNameWithoutExtension(s);
3.加载  AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(s);
4.Cache 
①如果没cache就创建一个 结构为Dic<ABName,Dic<assetName,Res>> 的结构存起来
resourceCache[bundleName] = dict[assetName] = resource;;
②有就直接存dict[assetName] = resource;

加载路径

使用PathHelper.AppHotfixResPath
Editor:Application.streamingAssetsPath(如果项目很大很多资源切到unity会卡一下 也不知道猫大和缥缈的仙人掌怎么解决)
isMobilePlatform:
①如果有Application.persistentDataPath}/{game}/
②否则使用Application.streamingAssetsPath + assetBundleName

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。