- 鼠標懸浮、點擊放大特效
Button Scale:
- 按鈕點擊事件
將新建的Login腳本掛到Scene下:
方法一:
1)獲取輸入框及按鈕
2) 注冊監聽器,綁定的是BoxCollider的gameObject
3) 填寫按鈕事件
private UIInput input1; private UIInput input2; void Start () { // 1)獲取輸入框及按鈕 input1 = transform.Find("Input1").GetComponent<UIInput>(); input2 = transform.Find("Input2").GetComponent<UIInput>(); BoxCollider btnLogin = transform.Find("BtnLogin").GetComponent<BoxCollider>(); //2) 注冊監聽器 UIEventListener listener = UIEventListener.Get(btnLogin.gameObject); listener.onClick = ButtonClick; } void ButtonClick(GameObject click) { // 3) 填寫按鈕事件 Debug.Log(input1.value + "-----" + input2.value); }
方法二:
1)獲取輸入框及按鈕
2) 用ButtonMessage注冊事件
a)給BtnLogin添加腳本Button Message
Target是綁定了Login腳本的對象,Function Name是點擊按鈕后要調用的方法名
3) 填寫按鈕事件
- 設置攝像機渲染層:
- 克隆Item:
private GameObject mItem; // Use this for initialization void Start () { // 獲取Item mItem = transform.Find("PanelMove/Items/Item").gameObject; ShowMove(); } void ShowMove() { // 克隆item的實例,減少內存消耗 for (int i = 0; i < 10; i++) { GameObject item = Instantiate(mItem) as GameObject; item.transform.parent = mItem.transform.parent; item.transform.localEulerAngles = Vector3.zero; item.transform.localScale = Vector3.one; item.transform.localPosition = new Vector3(0, 170 - i * 120, 0); item.SetActive(true); item.name = i.ToString(); // 注冊監聽 BoxCollider[] boxArr = item.GetComponentsInChildren<BoxCollider>(); foreach(BoxCollider box in boxArr) { UIEventListener listen = UIEventListener.Get(box.gameObject); listen.onClick = ButtonClick; } } } void ButtonClick(GameObject click) { Destroy(click.transform.parent.gameObject); }
- 設置拖拽:
1. 建一個Panel,設置參數
2. 往Panel里掛ScrollView腳本
3. 往需要拖拽的背景的Sprite和Item上添加DragScrollView腳本,且都有BoxCollider
往背景添加:
往Item添加:
// 添加DragScrollView item.AddComponent<UIDragScrollView>();
- 修改圖標和郵件標題、時間:
// 設置郵件名字和時間 UILabel title = item.transform.Find("Title").GetComponent<UILabel>(); UILabel time = item.transform.Find("Time").GetComponent<UILabel>(); UISprite icon = item.transform.Find("Head/Icon").GetComponent<UISprite>(); title.text = "王麻子給你的來信" + index.ToString(); time.text = System.DateTime.Now.ToString(); icon.spriteName = (3050 + index).ToString();