设为首页 加入收藏

TOP

[3]尝试用Unity3d制作一个王者荣耀(持续更新)->选择英雄-(中)(一)
2019-09-20 11:46:04 】 浏览:83
Tags:试用 Unity3d 制作 一个 王者 荣耀 持续 更新 -> 选择 英雄

如果已经看过本章节:目录传送门:这是目录鸭~

上节内容写了Actor管理器,那么这一节让我们先创建一个角色。(此章节开始加速...)

1.制作角色展示AssetBundle:

提取农药某个展示模型(Show)资源(这步具体去百度),然后再把模型制作成预制体,AssetBundle命名规则按照农药的(ID_游戏拼音_资源类型.assetbundle):

制作UI预制体,还是得提取或者去农药官网 pvp.qq.com 的壁纸中心下载原图截取(一个是图标一个是加载时候用到的):

创建一个空物体,并挂上ActorInfo组件,制作成预制体并输入数据(虽然标签以及打包的文件都是小写的,但按照路径读取文件的时候不会区分大小写,为了好看于是可以大写):

到这步先不要打包,后面还有小部件需要打包的。

2.拼UI(最舒适的部分~):

创建一个滚动视图,并且在Content位置增加自动布局组件,再创建空对象改名Mode,里面存放两个按钮用来切换皮肤和英雄选择,如图:

拉几下几下位置,最终效果:

然后我们制作一个预制体,用于动态生成(结构是一个空物体里面有个按钮(已把里面文字删去)和一个 名字 的 文本显示组件):

把预制体粘贴到Content里面测试有没有问题(是否自动对齐):

测试放上去的内容记得删除,设置预制体标签:

然后我们写一个代码用于管理选择英雄的UI响应的(前SelectionListManager)和 按钮回调的(后HeroItemButton):

 1 /*
 2  * 编辑者:Miku酱
 3  * 版本:1
 4  * 首次编写日期:2019/09/20 00:05
 5  * 修改日期:2019/09/20 00:05
 6  * 强行加一行~~~
 7  */
 8 using System.Collections;
 9 using System.Collections.Generic;
10 using UnityEngine;
11 using LuoHao.Actor;
12 using UnityEngine.UI;
13 using LuoHao.AssetBundleManager;
14 
15 namespace LuoHao.PVP.Selection
16 {
17     public class SelectionListManager : MonoBehaviour
18     {
19         public Transform testPos;
20 
21         /// <summary>
22         /// 接口
23         /// </summary>
24         public static SelectionListManager selectionListManager;
25 
26         /// <summary>
27         /// UI的AB包路径
28         /// </summary>
29         static string uiPath = "UGUI_Selection_0.assetbundle";
30         [Header("父对象")]
31         public Transform UIparent;
32         /// <summary>
33         /// 当前选择的英雄ID
34         /// </summary>
35          private int nowSelectionID = -1;
36 
37         GameObject testGM = null;
38         /// <summary>
39         /// 设置ID
40         /// </summary>
41         /// <param name="id">id</param>
42         public void SetSelectionID(int id)
43         {
44             if (nowSelectionID == id) return;
45            nowSelectionID = id;
46             if (testGM != null) Destroy(testGM);
47             Transform tr = Instantiate(AssetBundleManager.AssetBundleManager.
48                 GetAssetBundle(ActorManager.allActor[id].actorSkins[0].skinShowModelPath+ ".assetbundle")
49                 .GetAssetBundle().LoadAllAssets<GameObject>()[0],testPos).transform;
50             tr.localPosition = Vector3.zero;
51         }
52         
53         public int GetSelectionID()
54         {
55             return nowSelectionID;
56         }
57 
58         private void Awake()
59         {
60             selectionListManager = this;
61             nowSelectionID = -1;//重置ID
62         }
63         // Start is called before the first frame update
64         private void Start()
65         {
66             LoadList();
67         }
68 
69         // Update is called once per frame
70         private void Update()
71         {
72 
73         }
74         
75         private void LoadList()
76         {
77             //取得预制体
78             GameObject btn =AssetBundleManager.AssetBundleManager.
79                 GetAssetBundle(uiPath).GetAssetBundle().LoadAsset<GameObject>("HeroBtn");
80             List<ActorInfoData> infos = new List<ActorInfoData>(ActorManager.allActor.Values);//取得信息...
81             for(int i = 0; i < infos.Count; i++)//创建UI
82             {
83                 PackageForAssetBundle sprite = AssetBundleManager.AssetBundleManager.
84                     GetAssetBundle(infos[i].actorSkins[0].skinIconPath+".assetbundle");
85                    //取得图标资源
86                 Transform tr = Instantiate(btn, UIparent).transform;
87                 tr.GetComponentInChildren<Text>().text = infos[i].actorName;//设置名字
88                 tr.GetComponentInChildren<Image>().sprite= sprite.GetAssetBundle()
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇表达式树的说明与运用 下一篇Winform中设置ZedGraph的字体和间..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目