Ngui的基本用法

然后导入NGUI插件包

1、打开UI向导

Ngui的基本用法_第1张图片

2、选择UI样式


3、UI面板

Ngui的基本用法_第2张图片

4、添加小工具

Ngui的基本用法_第3张图片


5、选择类型,拖入图集和字体集

Ngui的基本用法_第4张图片


6、拖入图集和字体集,选择控件模板

Ngui的基本用法_第5张图片

7、添加

Ngui的基本用法_第6张图片

8、结果

Ngui的基本用法_第7张图片


按钮事件



在面板上添加一个按钮

创建代码TestPanel如下:

[csharp]  view plain copy print ?
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class TestPanel : MonoBehaviour  
  5. {  
  6.     public GameObject button;  
  7.     // Use this for initialization  
  8.     void Start()  
  9.     {  
  10.         button = transform.FindChild("Button").gameObject;  
  11.         //给按钮添加NGUI委托事件  
  12.         UIEventListener.Get(button).onClick += TestButton;  
  13.     }  
  14.   
  15.     // Update is called once per frame  
  16.     void Update()  
  17.     {  
  18.   
  19.     }  
  20.   
  21.     void TestButton(GameObject go)  
  22.     {  
  23.         Debug.Log("你点击了"+go.name);  
  24.     }  
  25. }  

将代码拖到panel上

Ngui的基本用法_第8张图片


你可能感兴趣的:(unity)