[3] Try to make a King's Glory with Unity3d (Continuous Update) ->Choose Hero-(Middle)

If you have read this chapter: Directory Portal: This is a catalog duck~

Actor Manager was written in the previous section, so let's create a role first.(This chapter starts accelerating...)

1. Make Role Show AssetBundle:

Extract pesticide a display model (Show) resources (go to Baidu specifically in this step), and then make the model into prefabricated, AssetBundle naming rules according to the pesticide (ID_Game Pinyin_Resource Type.assetbundle):

To make UI prefabrications, you have to extract or pesticide-free official website pvp.qq.com wallpaper center download the original image intercept (one is the icon and one is used when loading):

Create an empty object, attach the ActorInfo component, make a prefab and enter data (although labels and packaged files are lowercase, they are not case sensitive when reading files by path, so they can be capitalized for good looks):

Don't pack at this point. There are widgets to pack at the end.

2. Pin UI (most comfortable part~):

Create a scrolling view, add the AutoLayout component in the Content position, and create an empty object rename Mode with two buttons to switch between skin and hero selection, as shown in the following figure:

Pull the position a few times for the final result:

Then we make a prefabricated body for dynamic generation (structure is an empty object with a button inside (deleted text) and a name text display component):

Paste the prefabricated body into Content to test if there is any problem (auto-alignment):

Remember to delete what was put on the test and set the prefab label:

Then we'll write a code to manage the UI responses (former SelectionListManager) and button callbacks (latter HeroItemButton) that select heroes:

 1 /*
 2  * Editor: Miku sauce
 3  * Version: 1
 4  * Date of first writing: 2019/09/2000:05
 5  * Date of modification: 2019/09/2000:05
 6  * Force a row~~
 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         /// Interface
23         /// </summary>
24         public static SelectionListManager selectionListManager;
25 
26         /// <summary>
27         /// UI Of AB package path
28         /// </summary>
29         static string uiPath = "UGUI_Selection_0.assetbundle";
30         [Header("parent object")]
31         public Transform UIparent;
32         /// <summary>
33         /// Currently selected hero ID
34         /// </summary>
35          private int nowSelectionID = -1;
36 
37         GameObject testGM = null;
38         /// <summary>
39         /// Set up 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;//Reset 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             //Get prefabricated
78             GameObject btn =AssetBundleManager.AssetBundleManager.
79                 GetAssetBundle(uiPath).GetAssetBundle().LoadAsset<GameObject>("HeroBtn");
80             List<ActorInfoData> infos = new List<ActorInfoData>(ActorManager.allActor.Values);//Get information...
81             for(int i = 0; i < infos.Count; i++)//Establish UI
82             {
83                 PackageForAssetBundle sprite = AssetBundleManager.AssetBundleManager.
84                     GetAssetBundle(infos[i].actorSkins[0].skinIconPath+".assetbundle");
85                    //Get Icon Resources
86                 Transform tr = Instantiate(btn, UIparent).transform;
87                 tr.GetComponentInChildren<Text>().text = infos[i].actorName;//set name
88                 tr.GetComponentInChildren<Image>().sprite= sprite.GetAssetBundle().LoadAllAssets<Sprite>()[0]; //Set Icon
89                 tr.GetComponentInChildren<HeroItemButton>().heroID = infos[i].actorID;//Set up ID
90                 sprite.UnLoadAssetBundle(false);//uninstall
91             }
92         }
93     }
94 }

 

 

 1 /*
 2  * Editor: Miku sauce
 3  * Version: 1
 4  * Date of first writing: 2019/09/2000:05
 5  * Date of modification: 2019/09/2000:05
 6  * Force a row~~
 7  */
 8 using System.Collections;
 9 using System.Collections.Generic;
10 using UnityEngine;
11 
12 namespace LuoHao.PVP.Selection
13 {
14     public class HeroItemButton : MonoBehaviour
15     {
16         /// <summary>
17         /// This is set by code
18         /// </summary>
19         [HideInInspector]
20         
21         public int heroID = 0;
22         public void OnClick()
23         {
24             SelectionListManager.selectionListManager.SetSelectionID(heroID);//Call Change ID
25             
26         }
27     }
28 }

Then back to the button, hang up HeroItemButton and set the button to call back OnClick:

Select another hero's scene to create an empty object (SelectionListManager) and drag into the Content of the display position and scroll view:

 

3. Trial run:

Now let's click on AssetBundle Packaging and let the program fly for a while~

Hang up ActorManager on an empty object (created without it) for testing:

And enter the location of the Ali ActorInfo file you just created (suffixed here, you can modify the code to avoid suffixing):

Then run:

I wrote a temporary animation management on this side, so there is an animation show, which will be discussed later.

Success is evidenced by the effect inside the motion picture!

It's not too early (2019/09/20 00:30). See you next time.

If you have read this chapter: Directory Portal: This is a catalog duck~

Keywords: C#

Added by nahydy on Thu, 19 Sep 2019 19:41:59 +0300