Unity3d基础学习第7天

1. widget 控件容器

划分区域, 设置深度不会更改其子对象的深度(当2个widget容器重合的时候,显示谁在前后)

2. Panel 控件容器

可以统一更改子对象的深度,有裁切功能,通常于widget一同使用
Clipping:裁切
1.Texture Mask 根据图片裁切
2.Soft Clip 超出边界裁切
3.不裁切
在这里插入图片描述

3.Scroll View 滚动视图控件

给Panel添加其脚本
Content Origin: 视图内容的原点
Movement: 移动方向,水平 垂直
Drag Effect: 拖拽特效,回弹效果
Scroll Wheel Factor:滑轮灵敏度
在这里插入图片描述

4.Grid 网络视图控件

Arrangement: 排列方式 水平 垂直
Cell Width: 单元格宽度
Cell Height: 单元格高度
Column Limit: 水平限制列数,垂直限制行数
Pivot: 重心
在这里插入图片描述

5.实例化物品,点击查看信息,代码实例

   public class Eaddgrid : MonoBehaviour
    {
	public GameObject gb; //面板推拽赋值预设体
	void Start ()
	 {
		int flag = 1;
		for (int i = 0; i < 15; i++) 
		{
			GameObject o= Instantiate (gb);
			o.transform.parent = this.gameObject.transform;
			//o.transform.localPosition = new Vector3 (0,0,0);  //201  -154
			o.transform.localScale = Vector3.one;	
			o.name = (flag).ToString ();
			if (flag>12) 
			{
				flag = 1;
				o.name = (flag).ToString (); //物品名字:0-11
			}
				
	    	//EventDelegate d=newEventDelegate (GetComponent<Eclicksc>(),"myclickname");
			
            EventDelegate d = new EventDelegate (this,"myclickname");  //委托调用本类中的方法
			d.parameters [0] = new EventDelegate.Parameter (o, "name");
			o.GetComponent<UIButton> ().onClick.Add (d);
			o.GetComponent<UISprite> ().spriteName = "a" + flag;
			flag++;
		}

		GetComponent<UIGrid> ().Reposition ();

	}
	
	void myclickname(string name)
	{
		GameObject.Find ("namelabel").GetComponent<UILabel> ().text ="a" + name;
		GameObject.Find ("wupinsprite").GetComponent<UISprite> ().spriteName = "a" + name;
	}
}

猜你喜欢

转载自blog.csdn.net/JingDuiTell/article/details/88813504
今日推荐