Now in the direction of unity I have to say I chose UI direction unity is famous for the Ngui plugin. Today I made a Ngui simple backpack system. Very humble. To be a beginner to his own mark.
(1) Preview
It's basically a simple popup list control (making dynamic fonts for label easy to support Chinese)
Set up
Mark is an empty object, as the coordinates of a dynamically generated atlas. Bind the script for him to child:
usingUnityengine;usingSystem.Collections; Public classChild:monobehaviour {//Use this for initialization voidStart () {}//Update is called once per frame voidUpdate () {transform[] chinds= This. Getcomponentsinchildren<transform>(); if(Child1. Length >=3) {Destroy (chinds[1].gameobject); } }}
Camera Script:
1 usingUnityengine;2 usingSystem.Collections;3 4 Public classLoad_sprite:monobehaviour5 {6 Publicgameobject parent;7 PrivateUidragobject ud;8 //Use this for initialization9 voidStart ()Ten { One A } - - //Update is called once per frame the voidUpdate () - { -Parent.transform.position =NewVector3 (-1.782f, -0.29f,0); - } + Public voidCreate () - { +Uiatlas Atlas = (Uiatlas) resources.load ("atlas/new atlas_1",typeof(Uiatlas)); AUisprite Sprite =Nguitools.addsprite (parent, Atlas, UIPopupList.current.value); atSprite.transform.localScale =NewVector3 (2.0f,2.0f,2.0f); -Sprite.transform.localPosition =Vector3.zero; -Sprite.gameobject.addcomponent<boxcollider> (). size=NewVector3 ( -, -,0); -Sprite.gameobject.addcomponent<drop_pm>(); -Sprite.tag ="Item"; -Sprite.depth =2; in - toGameobject go = Gameobject.find ("Sprite"); +Boxcollider col = go. Addcomponent<boxcollider>(); -Col.size =NewVector3 ( -, -,0); theGo. Addcomponent<uidragdropitem>(); *Go. Getcomponent<uiwidget> (). Depth =Ten; $ Panax Notoginseng - the + A } the}
Project view (must be resources, in-place Atlas)
There's also a dynamically loaded script rewrite Uidragdropitem
1 usingUnityengine;2 usingSystem.Collections;3 4 Public classMydragitem:uidragdropitem {5 6 protected Override voidondragdroprelease (gameobject surface)7 {8 Base. Ondragdroprelease (surface);9 Ten print (surface); One A This. transform.parent =Surface.transform; - This. transform.localposition =Vector3.zero; - } the}
A very simple introductory experiment.
ngu-Study Notes (1)-Dynamically add delete atlas