NGU-学习笔记(1)-动态添加删除图集

现在 正在做unity的方向 不得不说我选的是UI方向 Unity中很有名的就是NGUI插件了.今天做了个ngui的简单背包系统。非常简陋。。初学着 自己mark下

(1)预览

NGU-学习笔记(1)-动态添加删除图集

主要就是个 simple popup list控件(为label制作动态字体方便支持中文)

设置如图NGU-学习笔记(1)-动态添加删除图集

NGU-学习笔记(1)-动态添加删除图集

mark为空物体,作为动态生成的图集的坐标。为他绑定脚本 child:

using UnityEngine;
using System.Collections; public class child : MonoBehaviour { // Use this for initialization
void Start () { } // Update is called once per frame
void Update () {
Transform[] chinds = this.GetComponentsInChildren<Transform>();
if (chinds.Length >= )
{ Destroy(chinds[].gameObject); } }
}

camera得脚本:

 using UnityEngine;
using System.Collections; public class load_sprite : MonoBehaviour
{
public GameObject parent;
private UIDragObject ud;
// Use this for initialization
void Start()
{ } // Update is called once per frame
void Update()
{
parent.transform.position = new Vector3(-1.782f, -0.29f, );
}
public void create()
{
UIAtlas atlas = (UIAtlas)Resources.Load("Atlas/New Atlas_1", typeof(UIAtlas));
UISprite sprite = NGUITools.AddSprite(parent, atlas, UIPopupList.current.value);
sprite.transform.localScale = new Vector3(2.0f, 2.0f, 2.0f);
sprite.transform.localPosition = Vector3.zero;
sprite.gameObject.AddComponent<BoxCollider>().size=new Vector3(,,);
sprite.gameObject.AddComponent<Drop_PM>();
sprite.tag = "item";
sprite.depth = ; GameObject go = GameObject.Find("Sprite");
BoxCollider col = go.AddComponent<BoxCollider>();
col.size = new Vector3(, , );
go.AddComponent<UIDragDropItem>();
go.GetComponent<UIWidget>().depth = ; }
}

project视图(必须为Resources,内放图集)

NGU-学习笔记(1)-动态添加删除图集

还有个动态加载的脚本 重写uidragdropitem

 using UnityEngine;
using System.Collections; public class MyDragItem : UIDragDropItem { protected override void OnDragDropRelease(GameObject surface)
{
base.OnDragDropRelease(surface); print(surface); this.transform.parent = surface.transform;
this.transform.localPosition = Vector3.zero;
}
}

很简单的一个入门实验。

上一篇:关于Tomcat的URIEncoding以及GET乱码


下一篇:postgresql分组后获取第一条数据