如果已經(jīng)看過本章節(jié):目錄傳送門:這是目錄鴨~ <https://www.cnblogs.com/Miku-CEB-Bug/p/11509708.html>
上節(jié)內(nèi)容寫了Actor管理器,那么這一節(jié)讓我們先創(chuàng)建一個(gè)角色。(此章節(jié)開始加速...)
1.制作角色展示AssetBundle:
提取農(nóng)藥某個(gè)展示模型(Show)資源(這步具體去百度),然后再把模型制作成預(yù)制體,AssetBundle命名規(guī)則按照農(nóng)藥的(ID_游戲拼音_資源類型.assetbundle):
制作UI預(yù)制體,還是得提取或者去農(nóng)藥官網(wǎng) pvp.qq.com 的壁紙中心下載原圖截取(一個(gè)是圖標(biāo)一個(gè)是加載時(shí)候用到的):
創(chuàng)建一個(gè)空物體,并掛上ActorInfo組件,制作成預(yù)制體并輸入數(shù)據(jù)(雖然標(biāo)簽以及打包的文件都是小寫的,但按照路徑讀取文件的時(shí)候不會區(qū)分大小寫,為了好看于是可以大寫):
到這步先不要打包,后面還有小部件需要打包的。
2.拼UI(最舒適的部分~):
創(chuàng)建一個(gè)滾動(dòng)視圖,并且在Content位置增加自動(dòng)布局組件,再創(chuàng)建空對象改名Mode,里面存放兩個(gè)按鈕用來切換皮膚和英雄選擇,如圖:
拉幾下幾下位置,最終效果:
然后我們制作一個(gè)預(yù)制體,用于動(dòng)態(tài)生成(結(jié)構(gòu)是一個(gè)空物體里面有個(gè)按鈕(已把里面文字刪去)和一個(gè) 名字 的 文本顯示組件):
把預(yù)制體粘貼到Content里面測試有沒有問題(是否自動(dòng)對齊):
測試放上去的內(nèi)容記得刪除,設(shè)置預(yù)制體標(biāo)簽:
然后我們寫一個(gè)代碼用于管理選擇英雄的UI響應(yīng)的(前SelectionListManager)和 按鈕回調(diào)的(后HeroItemButton):
1 /* 2 * 編輯者:Miku醬 3 * 版本:1 4 * 首次編寫日期:2019/09/20 00:05 5 *
修改日期:2019/09/20 00:05 6 * 強(qiáng)行加一行~~~ 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.Selection16 { 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 /// 當(dāng)前選擇的英雄ID 34 /// </summary> 35 private int
nowSelectionID = -1; 36 37 GameObject testGM = null; 38 /// <summary> 39 ///
設(shè)置ID40 /// </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 //取得預(yù)制體 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++)//創(chuàng)建UI 82 { 83 PackageForAssetBundle sprite =
AssetBundleManager.AssetBundleManager.84 GetAssetBundle(infos[i].actorSkins[0
].skinIconPath+".assetbundle"); 85 //取得圖標(biāo)資源 86 Transform tr = Instantiate(btn,
UIparent).transform;87 tr.GetComponentInChildren<Text>().text =
infos[i].actorName;//設(shè)置名字 88 tr.GetComponentInChildren<Image>().sprite=
sprite.GetAssetBundle().LoadAllAssets<Sprite>()[0]; //設(shè)置圖標(biāo) 89
tr.GetComponentInChildren<HeroItemButton>().heroID = infos[i].actorID;//設(shè)置ID 90
sprite.UnLoadAssetBundle(false);//卸載 91 } 92 } 93 } 94 }
?
?
1 /* 2 * 編輯者:Miku醬 3 * 版本:1 4 * 首次編寫日期:2019/09/20 00:05 5 *
修改日期:2019/09/20 00:05 6 * 強(qiáng)行加一行~~~ 7 */ 8 using System.Collections; 9 using
System.Collections.Generic;10 using UnityEngine; 11 12 namespace
LuoHao.PVP.Selection13 { 14 public class HeroItemButton : MonoBehaviour 15 { 16
/// <summary> 17 /// 這個(gè)由代碼來設(shè)置 18 /// </summary> 19 [HideInInspector] 20 21
public int heroID = 0; 22 public void OnClick() 23 { 24
SelectionListManager.selectionListManager.SetSelectionID(heroID);//調(diào)用更改ID 25 26
}27 } 28 }
然后在回到按鈕,掛上HeroItemButton并設(shè)置按鈕回調(diào)OnClick:
再再選擇英雄的場景中創(chuàng)建一個(gè)空物體(SelectionListManager),拖入展示位置和滾動(dòng)視圖的Content:
?
3.試運(yùn)行:
這時(shí)候我們點(diǎn)擊一下AssetBundle打包,讓程序飛一會~
在一個(gè)用于測試的空對象(沒有就創(chuàng)建)掛上ActorManager:
并輸入剛剛創(chuàng)建的阿離的ActorInfo文件的位置(這里就要帶后綴了,可以通過修改代碼來免除加后綴):
然后運(yùn)行:
我這邊因?yàn)榕R時(shí)寫了個(gè)動(dòng)畫的管理的所以有出場動(dòng)畫展示,這個(gè)后面才講。
出現(xiàn)了動(dòng)圖里面的效果就說明成功啦!
不早了( 2019/09/20 00:30),下一節(jié)再見。
如果已經(jīng)看過本章節(jié):目錄傳送門:這是目錄鴨~ <https://www.cnblogs.com/Miku-CEB-Bug/p/11509708.html>
?
熱門工具 換一換