龙哥的秘密花园 发表于 2023-4-21 21:54:15

基于B站教程宝可梦日月导入unity插件的二次拓展教程(本教程只用于学习Unity拓展,)

本帖最后由 龙哥的秘密花园 于 2023-4-23 15:38 编辑

>本帖最后由 龙哥的密码花园 于 2023-4-21 21:54 编辑


本教程只用于学习Unity基于Ui Toolkit,主要是对在其他地方获取到的插件某些功能并没有,但是本身需要这些功能,二次拓展。

本次教程希望可以给大家带来一些启发。

在这里我使用B站关于Unity导入宝可梦日月模型插件进行二次的拓展。

关于宝可梦日月模型导入Unity这的宝可梦日月源文件和github插件地址: https://github.com/opeious/Pokemon3DStoUnity

链接:https://pan.baidu.com/s/11OsBlcHR-xxLA1D1si9vgA?pwd=Long
提取码:Long

B站搜索unity宝可梦日月模型导入应该是可以找到的,我也是在B站上找到的。

关于插件和怎么导入简单的示例一下:

先将插件和源文件解压,等待解压完成。源文件解压完成后不要直接放入unity的项目中,将它放在你自己知道的文件目录下

!(data/attachment/forum/202304/21/174250w2xhhy6mhlw603ww.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

将解压完的第二个插件直接拖入unity项目的""Assets""下,等待编译完成

在Unity菜单中出现如图所示表示插件编译成功

!(data/attachment/forum/202304/21/174732anuulzvvtunwu3zr.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

然后就是关于源文件的操作了,解压完成的源文件如下

!(data/attachment/forum/202304/21/175100y2ueqeeoxr4104l4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

打开网站:->https://gbatemp.net/threads/wip-ultra-sun-and-ultra-moon-pokemon-models-textures-and-animations.490365/

应该是和下面界面一致,向下翻

!(data/attachment/forum/202304/21/175310e6dmwyzo57kh8d5h.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

找到如下示图

!(data/attachment/forum/202304/21/175441u9ao9ojitihkhhli.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

源文件对应的宝可梦路径就知道了

!(data/attachment/forum/202304/21/175602m979onrr0rxoyrz0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

打开Unity项目中菜单的插件

!(data/attachment/forum/202304/21/180338kqamvnqqnkm3zala.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

点击第一个选项,初始界面应该是如下图所示

!(data/attachment/forum/202304/21/180544q1lz1e7k7jkqod12.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

接下来在Unity项目的""Assets\宝可梦模型""下创建文件夹,我这里创建的文件夹叫""第一只宝可梦""。没有宝可梦这个文件夹就先创建""宝可梦模型""文件夹

将""第一只宝可梦""放到""宝可梦模型""文件夹下

然后我这里放入第一只宝可梦的对应文件放入

!(data/attachment/forum/202304/21/181740msr2pfloosxazjxi.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/181727krvkibrv2orrxi3s.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

将插件设置路径设置到""宝可梦模型""文件夹,如图所示

!(data/attachment/forum/202304/21/181914zzbzy4gyke9k3jkn.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

点击如图所示按钮

!(data/attachment/forum/202304/21/181953hlvlgyrngquvgrvg.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

再点击如图所示按钮

!(data/attachment/forum/202304/21/182018zjt5x8a3zj335ne8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

等待解压完成

!(data/attachment/forum/202304/21/182153jgzjpo5jpc7cjbzu.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

使用插件完成一只宝可梦模型导入,当然还有相关动画

还没有完成!!!

打开之前解压的源文件将对应的文件放到同一个文件夹下,注意同一个文件夹放入两个或者更多都是不会解压多个的而是第一个。

想想看,1000多只宝可梦先创建1000多个文件夹,然后将每个对应的文件放入,这该多么麻烦啊!!!!

现在就开始本教程的核心:

1.要创建1000个文件夹

2.将对应的宝可梦源文件分组到到上面的文件夹

自动化完成上面的事然后使用插件完成导入宝可梦模型就非常的简单了,不是吗

现在开始创建Ui Toolkit 完成二次拓展开发

先创建编辑器窗口这里非常简单,在""Project""的""Assets""窗口下右键找到 ->""Create""->""Ui Toolkit""

->"" Editor Window""点击,出现如下所示

!(data/attachment/forum/202304/21/183756veezkppq7m4gl66g.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

创建该拓展名称""宝可梦资源分组拓展""点击""Confirm""创建完成

!(data/attachment/forum/202304/21/184048ov0mdn2kdnni92cm.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

现在我要将这默认文字去掉

!(data/attachment/forum/202304/21/184151dtlnhtg89pn4ggpl.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

在""Assets""->""Editor""在这个文件夹下会有创建拓展名称一样的三个文件

!(data/attachment/forum/202304/21/184412c2mv2aaxafwahexi.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

先双击它,会弹出自定义窗口样式

!(data/attachment/forum/202304/21/184531fbb23st3kbteztve.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")!(data/attachment/forum/202304/21/184555lo12m8sretenu1og.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

在面板上找到""Hierarchy""将""Lable""删除如下

!(data/attachment/forum/202304/21/184720wufibosiffcfkkiz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/184744ucrk09wr5rrkcwrh.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

""CTRL""+""S""保存关闭窗口,发现有行文字被删除了

!(data/attachment/forum/202304/21/184922k99yh6zhr9ru9ur6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

接下来双击打开它

!(data/attachment/forum/202304/21/185002wo350csra292tssj.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/185027d7sh02773wxftsth.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

现在将不需要要的东西删除,并添加如下代码

!(data/attachment/forum/202304/21/185647hahpsszf6mngfupz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

""CTRL""+""S""保存回到Unity发现文字被剔除了

!(data/attachment/forum/202304/21/185755o3g5a35p7ae3c87o.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

接下来我们开始对样式进行搭建,双击打开它

!(data/attachment/forum/202304/21/190019fovf6m7b83zyzvmp.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

在自定义样式中默认是没有添加编辑器容器的我们选择""Editor Extension Autnoring""

!(data/attachment/forum/202304/21/190213eatw3dwap3hetffy.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/190459x27lvrlpghbubuh2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

不用管警告,我们来搭建自己拓展编辑器样式,因为我英文不太好,而且也不太熟练UI Toolkit,然后后面的样式可能会有一点点难看,不过功能没问题就可以了。这里就按自己的理解说一下要用到的容器(名字翻译的)

这些使用的容器中,插页和基类字段并不会在自定义样式中创建,它们会随着宝可梦源文件的变化而需要改变,

它们将在C#代码中创建并使用(关于容器的创建有三种方式:1.自定义样式中创建 2.C#中创建即new

3.在uss中创建)

所有容器的基类   列表             按钮            插页          文本字段         基类字段

!(data/attachment/forum/202304/21/191025isnwxpp8tp9t0q0z.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")!(data/attachment/forum/202304/21/191056dwgqgv630kapkskc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")!(data/attachment/forum/202304/21/191202o29yr6d7x872l233.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")!(data/attachment/forum/202304/21/191224x97487zlqqp9spdp.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")!(data/attachment/forum/202304/21/191454ddr7rgpwo8lzgrsr.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")!(data/attachment/forum/202304/21/191544vsqddl9jlgjgewxt.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

将""Library""中的""VisualElement""拖到""Hierarchy""中

!(data/attachment/forum/202304/21/192354ics3mxm76jsgsncc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

现在开始介绍""Inspector""中我常用的功能以及自己解释的功能

(可能对于你来说我解释的不够正确,请观看UnityAPI进一步了解)

每个容器的""Inspector""基本基于这个基类大抵相同,就快速的搭建一下了

!(data/attachment/forum/202304/21/193246ziwde0uiiisdyrds.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/193449ko8fdq62ofg8gyso.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

搭建完成

!(data/attachment/forum/202304/21/194122p2gb6bc416azfm24.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

先简单的说一下样式的布局和调过的参数

鼠标悬停到这,可以知道该基类容器内包含一个""TextField""和两个""Button""

!(data/attachment/forum/202304/21/194306pyfkykfryfbczyry.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

先看基类容器,并没有任何设置

!(data/attachment/forum/202304/21/194709jrbpsaraffrykeyu.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

在""TextField""中设置名称可以在脚本中找到,设置Labal为""路径"",将Direciton设置为从左到右更加的美观

!(data/attachment/forum/202304/21/195047n72cgf477s7wc2f0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

在""Button2""设置名字和文本,添加一些边距和边框和圆角,

!(data/attachment/forum/202304/21/195351k61asii16lza55dz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/195534cz5vv6xwgd3x7x6d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

在""Button1""和上面一样的设置,文本和名字改变

!(data/attachment/forum/202304/21/195628p4gesa8opchw8soh.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

该基类设置Direciton设置为从左到右 Shrink为1,Grow为1

!(data/attachment/forum/202304/21/195843fhhs7cs5hq27z17y.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

这个基类包含""ListView""和""VisualElemen""

!(data/attachment/forum/202304/21/200050g2jnpw9hozj3ln99.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

""ListView1""如下设置

!(data/attachment/forum/202304/21/200405lun8biqz03isl8bp.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/200453kfbclqbfb4pq47q4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

选择另一个基类如下设置

!(data/attachment/forum/202304/21/200541rt4odzivi2i1ikbb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/200613bmlvzqaffat4z0f0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

选择这个基类,展开它,可以知道该基类容器内包含一个""TextField""和两个""Button""

!(data/attachment/forum/202304/21/200720abn78c0ktmrtnszt.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

关于""TextField""的设置

!(data/attachment/forum/202304/21/200913qe777qvn77wrtkn7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

第一个""Button""设置

!(data/attachment/forum/202304/21/201007m7kq947kkya3lpk7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/201026wrv44jdvr4ka5ppp.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

第二个""Button""设置

!(data/attachment/forum/202304/21/201136fzg7gcohx7u93kth.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/201157h63efq0p389poge3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

最后一个""Button""刷新设置

!(data/attachment/forum/202304/21/201258fwsuzculssnsuzjv.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/201319qip9z14xdvb7vtf1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

如上关于拓展的样式基本完成开始编写脚本

将局部变量改为全局

!(data/attachment/forum/202304/21/201508qujq9un3wja8y4ju.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/201604ebkv8mnv4vzmt8yl.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

声明变量存储并找到,刚刚创建的样式中个个容器。

!(data/attachment/forum/202304/21/202036ykpmaeqagllzvrxm.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

这边先实现导入和导出的回调事件,在`CreateGUI()绑定事件

!(data/attachment/forum/202304/21/203304b1jc0j19cscvcswm.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/202953q0g8bz6ksbvs1myi.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

实现刷新事件

!(data/attachment/forum/202304/21/203613twpe9n32pru949re.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/204923z0e2x02wovz9z3g7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/205411frlpgv3r23u9llpl.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

绑定分组事件

!(data/attachment/forum/202304/21/205832nfm7qf1ifan3ckm7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/211140gj6wopabbplaj2tb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/211553e0gn4rr0hggrb0r3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/211612g8401n7o4pc74oi8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

绑定重置事件

!(data/attachment/forum/202304/21/211749wm49gg2s8sloj41l.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

最后将这里修改一下,放到自己喜欢的地方

!(data/attachment/forum/202304/21/211844amc5shmbhaajwkmz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/211924egrmr8lqlczl33iy.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

保存,等编译完成在菜单栏中找到""龙哥的秘密花园""->""宝可梦资源分组拓展""打开它

!(data/attachment/forum/202304/21/212111qvs711sv1ss7sh8v.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

测试一下

!(data/attachment/forum/202304/21/212302pg966fluls66svlx.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/212408n9t9gy99ppuypmm9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

2.好吧,关于列表这边还是有点点问题,不过正常的添加进去了,将折页折起来,观察第一个元素和最后的元素是否和网站上的宝可梦源文件存储位置是否一致。还有就是网站上的宝可梦源文件存储位置有千分之一会跳源文件的排序请仔细观察

!(data/attachment/forum/202304/21/212429vr7xob1cxxb79xm7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/212439vepmekdvgtzgg2r2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

3.文件路径一定是在""Assets""下是没有重名的

!(data/attachment/forum/202304/21/212929h5ba78a15sq1dzqy.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202304/21/213050qf5y5o822m2t5mnz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

4.

!(data/attachment/forum/202304/21/213112s2x8wyd8xjqqzdxj.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

点击后,还是关于表单的问题,不用管他

!(data/attachment/forum/202304/21/213150ygfmtk7f0t76bpiz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

分组完成

!(data/attachment/forum/202304/21/213240phxrrz7n5ujujnu7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

6.打开插件设置它

!(data/attachment/forum/202304/21/213334g339y9d38dnggn7f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

7.按照顺序点击从左到右

!(data/attachment/forum/202304/21/213359x69g24f6oioov0gm.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")!(data/attachment/forum/202304/21/213405xkd88iz2kiglsc8d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

8.

等待生成

9.生成完成后,宝可梦模型预制体和相关依赖都在!(data/attachment/forum/202304/21/213718y2b8zubvv7qx4aeb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")将文件夹名填入

!(data/attachment/forum/202304/21/213539u3x9xnehtl11yc6c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

10.将预制体导出,等待完成

!(data/attachment/forum/202304/21/213849tf5rhx8mtam8x8xm.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

11.

打开!(data/attachment/forum/202304/21/213947p4jnhnj0hj0myg9q.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")找到自己的unity项目,导出的包在""Assets""同级下,这里没有是因为我将它们移动到其他地方了!(data/attachment/forum/202304/21/214059qodb5eoiosqzsyi0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

本教程基于untiy导入宝可梦插件而进行的二次拓展,除了那列表的文字上下覆盖就没啥问题了,基本上剩下的都是时间的活了。

还有就是关于插件,它最多只能导出45个宝可梦预制体,如果你在""保存文件""下放的超过这个分组数量,

我这个拓展是可以分出来的,但是使用插件导出预制体会跳顺序和大部分分组的文件夹下的文件无法进行下一次

导出宝可梦预制体。所以要在""保存文件""下不要超过45只宝可梦,当然45只在我电脑上导出时间大概为30分钟。这个拓展也是足够方便了,起码比自己手动创建方便。(经过大概4个多小时的测试,可以一次性导出137只,但是第0个文件夹不会解出宝可梦模型)
页: [1]
查看完整版本: 基于B站教程宝可梦日月导入unity插件的二次拓展教程(本教程只用于学习Unity拓展,)