In the development of a mobile game, the UI has dozens of to hundreds of different, if one to do these UI, it will undoubtedly take a lot of time. Recently our game UI has been the nth revision, I changed this n multiple UI, summed up the UI has a lot of commonality (is the same).
Here are some ideas that I think are commonly used in UI extraction
1. Shared buttons
Common: button, title, [icon],[message number reminder]
Ideas:
button click event and title is certain, other depending on the situation. So we can create a class btnitemclass that handles the logic of the UI, and the outside simply passes in the appropriate parameters to
usingSystem;usingUnityengine;usingSystem.Collections;/// <summary>///Shared Text button, extracting class///includes: Shop, challenge, friend, hero/// </summary> Public classbtnitemclass{ Public stringTitlesprite; Public stringIconsprite; Public stringBtnname; Public stringNextuititle; //button click on the event Publicuieventlistener.voiddelegate Callback; //number of message reminders Public stringtipmsg; Public intTipnum; Private BOOLisenabled; /// <summary> ///constructor Function/// </summary> /// <param name= "Btnname" >button Name</param> /// <param name= "Iconsprite" >Item icon</param> /// <param name= "Titlesprite" >title text picture, no fill null</param> /// <param name= "Nextuititle" >title of next-level UI</param> /// <param name= "callback" >Click on the event</param> /// <param name= "enabled" ></param> PublicBtnitemclass (stringBtnname,stringIconsprite,stringTitlesprite,stringNextuititle, Uieventlistener.voiddelegate Callback,BOOLEnabled =true) { This. Btnname =Btnname; This. Iconsprite = Iconsprite??"NULL"; This. Titlesprite = Titlesprite??"NULL"; This. Nextuititle =Nextuititle; This. Callback =callback; IsEnabled=enabled; } Public btnitemclass ()
{
}
//Setting Properties Public Static voidBind (Btnitemclass itemclass, Transform trans) {if(!string. IsNullOrEmpty (itemclass.btnname)) Trans.name=Itemclass.btnname; //title text PictureUisprite Titlesprite = ctool.getchildcomponent<uisprite> ("Titlesprite", trans); Titlesprite.spritename=Itemclass.titlesprite; Titlesprite.makepixelperfect (); //iconsUisprite Iconsprite = ctool.getchildcomponent<uisprite> ("Iconsprite", trans); Iconsprite.spritename=Itemclass.iconsprite; Iconsprite.makepixelperfect (); //display text when the title picture is not found varTitlelabel = ctool.getchildcomponent<uilabel> ("Titlelabel", trans); if(string. IsNullOrEmpty (itemclass.titlesprite) | | Itemclass.titlesprite = ="NULL") {Titlelabel.text=Itemclass.nextuititle; TitleLabel.gameObject.SetActive (true); } Else{titleLabel.gameObject.SetActive (false); } //Binding EventsTrans. Getcomponent<uieventlistener> (). OnClick =Itemclass.callback; //button.isenabled = Item. isenable = Item. isenable; }}
How to use:
First, build a list that contains the data for all the buttons in the current UI, then refresh the UI (Generate button, set button properties)
//button DataPrivateList<btnitemclass>uiconfiglist{Get { return NewList<btnitemclass>() { NewBtnitemclass ("btnherolist","Battleteam_icon_herostrong","NULL","Hero Enhancement", obj= Cnetplayer.checkpackageoverflow_withmsgbox (() = Cuiherolist.show ("Hero Enhancement"))), NewBtnitemclass ("weapon hardening, obj = Cuipowerup.showweaponstselectlist ()), }; }}//Refresh UIPrivate voidRefreshui () {varMax =Uiconfiglist.count; Cuihelper.resizecuitablegridgameobjects (Tablegrid, Max, commpicbtntemplate); for(intIDX =0; IDX < Max; idx++) {var trans=TableGrid.transform.GetChild (IDX); var itemclass=Uiconfiglist[idx]; Btnitemclass.bind (Itemclass, trans); } tablegrid.reposition ();}
Re-usability of mobile game UI (i)