编译阿拉德(四)-Unity2020升级2022

文章讲述了作者在将Unity项目从2020版升级到2022版过程中遇到的autostreaming错误、宏定义丢失、Android资源路径变化等问题,以及提供的解决方案,如删除manifest.json中的autostreaming、调整宏定义和处理资源打包问题。
摘要由CSDN通过智能技术生成

这次是从 Unity2020.3.48f1c1 升级到 2022.3.8f1c1

下载2022.3.8f1c1版本要到这里找:Unity 2022.x Unity官方下载

要选择“从Hub下载”,利用Hub来安装,这样在安装的时候,就可以把对应的apk工具也装上。否则要自己手工配置apk环境,很容易出现一大堆版本兼容错误。

autostreaming错误

最典型的报错是这个:[com.unity.modules.autostreaming@1.0.0] cannot be found

我用2020随便新建个项目,什么都没做,再用2022打开,就会报这个错

看了这篇文章:

把那三个文件夹都删了,结果出现一大堆莫名其妙的错误,诸如UnityEngine.UI不存在Text或Image这种错误,让我无法继续了,只好又退回了2020。

不过Library文件夹确实可以删,后面遇到一些错乱信息时,可以删除Library再自动重建。

实测有效的解决方案:unity c1转f1报错-CSDN博客

1. 修改 Packages\manifest.json,删除autostreaming那一行即可。

2. 如果你的项目确实用到了autostreaming,那就不能删除。autostreaming应该是在PackageManager目录中的,Unity2020在Unity\2020.3.48f1c1\Editor\Data\Resources\PackageManager\BuiltInPackages里可以找到com.unity.modules.autostreaming这个文件,然后复制到2022对应的目录即可。参看:UnityEngine are you missing an assembly reference - 简书

定义宏

转换到2022后,以前定义的宏都没有了,要重新加一下,否则又是一大堆错误。

先进入安全模式,打开Project Settings->Player->Other Settings->Script Compilation->Scripting Define Symbols,把以前定义的宏都加进去。

这次unity挺给面子,再没出现什么特别的错误,可以直接进入游戏了。

安卓Android/res

接下来是安卓打包,问题又来了。先是这个:

Unity打包报错:OBSOLETE - Providing Android resources in Assets/Plugins/Android/res is deprecated...

意思是说:版本2021以后已经废弃了Android/res,要用aar方式才行。

百度了一下:修改aar方式代价有点大...发现n种方法可以不用aar解决这个问题...某人试了这n种方法还是解决不了,最后还是aar才成功。

只好又google了一下:不用aar,直接把Assets/Plugins/Android目录删了就行。我试了一下,打包apk果然成功了。可是我要用的sdk还在Android目录里呢,所以apk刚打开,就报错缺少文件卡住了。

我的情况是:Android目录中res是空的,要用的文件在libs中。因此,只把assets和res删了,对应的res.meta和assets.meta也删掉,再打包时就成功了。

安卓路径问题

以前用WWW加载的文件,有一部分路径是Assets!/assets/AssetBundles/...,一些表格数据在这里面。现在好像路径变了,导致登录完了游戏但进不去。

根据报错的路径信息,我把原来“Assets!”中的文件,挪到了\Assets\StreamingAssets\AssetBundles中,再进游戏就登录成功了。

最后一坑

本来都已成功了,我决定关闭调试信息再打一个包,也不知道是不是点错了什么东西,这次打包的apk竟然是2.6G,以前的只有1.3G。

这次我真的快要投降了,只好把Library文件夹删除并重建了一下,结果打包出来1.5G,勉强可以接受,终于松了口气。

修改之前遗留的几处bug

数组越界

有时游戏在某个操作后会卡住不动,显示以下错误:

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

TextRenderer.UpdateMesh () (at Assets/Scripts/03Graphic/FX/HitText/TextRenderer.cs:639)

改TextRenderer.cs,在报错的函数那里直接return,不执行后面出错的代码即可。

血条没血

怪物血条只显示一个黑条的问题,要改UI的Slider结构。

CBossHpBar.cs - 有几处的mSliderBloodFg改为imgBloodFg。

调试输出:HPBarManager.cs的Logger.LogProcessFormat改为Debug.LogFormat

血条本质上是进度条,血条存放在Assets>Resources>UIFlatten>Prefabs>BattleUI>DungeonBar中,DungeonMonsterHpBar和DungeonMonsterHpBar_Green是怪物头顶的血条,HPBar_Monster、HPBar_Elite、HPBar_BOSS_NEW是屏幕上方怪物头像的。

以头顶的血条DungeonMonsterHpBar为例,打开时是这样的:

Fg是那个X号图片,应该是这张图片出错了,要先删除它。再新建一张图片,名字也改成Fg,改成红色,调整好位置大小。

在Hierachy面板选中BarRoot,在Inspector面板底下的Add Componet按钮,添加UI->Slider组件。

设置如下:

这时红色的血条的位置变了,要重新调整回刚才的位置大小。这时在Inspector拖动修改Value的值,可以看到红色的血条有长短变化。

在Hierachy面板选中BarRoot,修改这里。此时运行游戏,可以看到怪物头顶的血条已恢复正常了。

BOSS等其它血条也是类似的改法,注意结构改变了,代码也要做一点对应的改变。

背包点击问题

背包点击第一下无内容显示

Assets资源:UIFlatten/Prefabs/Package/PackageNew

打开背包界面代码:ClientSystemTownFrame->_onPackageButtonClick

ClientSystemTownFrame.cs - 主城背包按钮,先打开材料(id=2),便于切换成装备(装备页不能直接切换到装备页)

代码:frameMgr.OpenFrame<PackageNewFrame>(FrameLayer.Middle, 2);

PackageNewFrame.cs - 刚打开窗口,强制切换到装备页面

The complete Visual Behaviour Authoring framework for Unity, empowering you to create advanced AI Behaviours and Logic, including three separate, fully featured, yet seamlessly interchangeable modules for you to choose and easily add in your game: • Behaviour Trees • Hierarchical State Machines • Dialogue Trees NodeCanvas is a production ready framework used by many awesome games including Kim, Pamela, Hurtworld, Shroud of the Avatar, Kingdom and Ghost of a Tale. [Games Showcase] Feature Highlights ------------------------------------- • Choose the right tool for the task at hand. • Design reactive Behaviour Trees and Hierarchical State Machines within an intuitive, designer friendly visual node editor: (Full Undo/Redo, Zoom In/Out, Multi-selection, Duplication, Copy/Pasting, JSON Import/Export, Groups, Comments and more) • Use local & global variables of any type, visually or in code, for creating reusable and actor-oriented, parametric behaviours, optionally saving and loading those variables between gaming sessions. • Data Bind variables with any component property of any type directly. • Sync variables automatically over the network using UNET, for creating multiplayer games. • Visually Debug behaviours with realtime, colorful and informative runtime debugging. • Live Edit everything while in play mode to perfectly understand your design goals and how to achieve them. • Utilize any existing code directly with advanced and extremely fast Reflection Tasks, automatically integrating Unity's and 3rd Party asset APIs. • Work with Lists/Arrays, Enums, Interfaces and pretty much ANY Variable Type you need out-of-the-box. • React to world changes and transfer data using the built-in Event System. • Reuse and Bind made behaviours among any number of different agents. • Organize your designs using Behaviour Sub-Trees and Sub-State Machines. • Extend NodeCanvas Framework to create your own Actions, Conditions, Nodes or even completely new modules with the e
罗马尼亚问题是一个经典的搜索问题,目标是找到两个城市之间的最短路径。其中,城市之间的距离以边的权重表示,从起点到目标点的路径必须经过每个城市一次且仅一次。本题要求使用 Python 代码实现深度优先搜索,并逐个点亮。 深度优先搜索是一种基于栈的搜索方法,在搜索的过程中,先遍历一个分支的全部节点,直到该节点的所有分支都被遍历完为止,然后回溯到前一个节点,重复执行上述步骤,直至找到目标节点或搜索全部节点。在罗马尼亚问题中,栈可以用来维护搜索的节点。 具体的实现步骤如下: 1. 定义一个字典,表示罗马尼亚的地理位置和距离信息。 2. 定义一个列表,表示从起点到目标点的路径。 3. 根据深度优先搜索的特点,使用栈来保存搜索的节点。 4. 设定起点为起始节点,将其加入栈中。 5. 当栈非空时,从栈中弹出最后一个节点,并查找其相邻节点。 6. 对于每个相邻节点,如果它不在路径中,将其加入路径中,并添加到栈中。 7. 如果相邻节点是目标节点,则返回路径。 8. 重复执行步骤5-7,直至栈为空,返回空列表。 实现代码如下: ```python romania_map = { 'Arad': {'Zerind': 75, 'Sibiu': 140, 'Timisoara': 118}, 'Bucharest': {'Urziceni': 85, 'Pitesti': 101, 'Giurgiu': 90, 'Fagaras': 211}, 'Craiova': {'Dobreta': 120, 'Rimnicu Vilcea': 146, 'Pitesti': 138}, 'Dobreta': {'Mehadia': 75, 'Craiova': 120}, 'Eforie': {'Hirsova': 86}, 'Fagaras': {'Sibiu': 99, 'Bucharest': 211}, 'Giurgiu': {'Bucharest': 90}, 'Hirsova': {'Urziceni': 98, 'Eforie': 86}, 'Iasi': {'Neamt': 87, 'Vaslui': 92}, 'Lugoj': {'Timisoara': 111, 'Mehadia': 70}, 'Mehadia': {'Dobreta': 75, 'Lugoj': 70}, 'Neamt': {'Iasi': 87}, 'Oradea': {'Zerind': 71, 'Sibiu': 151}, 'Pitesti': {'Rimnicu Vilcea': 97, 'Bucharest': 101, 'Craiova': 138}, 'Rimnicu Vilcea': {'Sibiu': 80, 'Pitesti': 97, 'Craiova': 146}, 'Sibiu': {'Arad': 140, 'Oradea': 151, 'Fagaras': 99, 'Rimnicu Vilcea': 80}, 'Timisoara': {'Arad': 118, 'Lugoj': 111}, 'Urziceni': {'Bucharest': 85, 'Vaslui': 142, 'Hirsova': 98}, 'Vaslui': {'Urziceni': 142, 'Iasi': 92}, 'Zerind': {'Arad': 75, 'Oradea': 71} } def dfs(start, goal, path=[]): path = path + [start] if start == goal: return path if start not in romania_map: return None for city in romania_map[start]: if city not in path: dfs_path = dfs(city, goal, path) if dfs_path: return dfs_path return None path = dfs('Arad', 'Bucharest') for city in path: print(f'Point {city} is Lightened') ``` 此代码使用深度优先搜索算法在罗马尼亚地图中找到从阿拉德到布加勒斯特的最短路径,并逐个点亮路径中的城市。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值