NGUI UIcenterOnChild
2017-06-12 16:29
1206 查看
首先给UIGrid添加UICenterOnChild脚本
在两个锁的点击事件中获取到UICenterOnChild CenterOn()方法进行传参 这样物体就能居中显示了
using UnityEngine;
using System.Collections;
public class OnCenterByOne : MonoBehaviour {
// Use this for initialization
public UICenterOnChild muicenterOnchild;
public GameObject mgrid;
public GameObject nextBtn;
public GameObject upBtn;
int number=2;
void Start () {
muicenterOnchild.CenterOn (mgrid.transform.GetChild (number).transform);
UIEventListener.Get (nextBtn.gameObject).onClick += NetxBtn;
UIEventListener.Get (upBtn.gameObject).onClick += UpBtn;
}
void NetxBtn(GameObject go){
//我那个是用Toggle 来判断当前在中间的是那个,你这个可以用一个int值来控制
if (number==3) {
nextBtn.gameObject.SetActive (false);
upBtn.gameObject.SetActive (true);
muicenterOnchild.CenterOn (mgrid.transform.GetChild (number+1).transform);
mgrid.transform.GetChild (number + 1).transform.localScale = new Vector3 (2, 2,2 );
mgrid.transform.GetChild (number).transform.localScale = new Vector3 (1, 1, 1);
number += 1;
}else {
muicenterOnchild.CenterOn (mgrid.transform.GetChild (number+1).transform);
mgrid.transform.GetChild (number + 1).transform.localScale = new Vector3 (2, 2, 2);
mgrid.transform.GetChild (number).transform.localScale = new Vector3 (1, 1, 1);
upBtn.gameObject.SetActive (true);
nextBtn.gameObject.SetActive (true);
number += 1;
}
}
void UpBtn(GameObject go){
if (number==1) {
upBtn.gameObject.SetActive (false);
muicenterOnchild.CenterOn (mgrid.transform.GetChild (number-1).transform);
mgrid.transform.GetChild (number - 1).transform.localScale = new Vector3 (2, 2, 2);
mgrid.transform.GetChild (number).transform.localScale = new Vector3 (1, 1, 1);
number -= 1;
}else {
muicenterOnchild.CenterOn (mgrid.transform.GetChild (number-1).transform);
mgrid.transform.GetChild (number - 1).transform.localScale = new Vector3 (2, 2, 2);
mgrid.transform.GetChild (number).transform.localScale = new Vector3 (1, 1, 1);
upBtn.gameObject.SetActive (true);
nextBtn.gameObject.SetActive (true);
number -= 1;
}
}
}
相关文章推荐
- unity开发 --------- NGUI (UIDragPanelContents、UIDraggablePanel、UICenterOnChild、UIScollBar、SpringPanel)
- Unity-NGUI组件UICenterOnChild使对象在UIDarggablePanel居中显示
- Unity-NGUI组件UICenterOnChild使对象在UIDarggablePanel居中显示
- NGUI UICenter On Child 在3.69版本中 不能居中!
- UICenterOnChild
- Click状态下 NGUI的CenterOnChild
- The specified child already has a parent. You must call removeView() on the child's parent first.
- [cnblogs镜像]ONGUI->NGUI->UGUI (Unity UI史)
- 当主页面关闭时关闭所有子窗口(Close all the child windows on unload of main page)
- ExpandableListView OnChildClickListener 失效解决
- unity gameObject --> center on child
- cancel-ng-swipe-right-on-child
- NGUI无法按住鼠标按住时无法监听OnHover事件
- 关于向父view添加相同的view问题!The specified child already has a parent. You must call removeView() on the chil
- The specified child already has a parent.You must call removeView() on the child's parent first问题
- The specified child already has a parent. You must call removeView() on the child's parent first.
- 【Android异常】The specified child already has a parent. You must call removeView() on the child's paren
- The specified child already has a parent. You must call removeView() on the child's parent first.
- [已]The specified child already has a parent. You must call removeView() on the child's parent first.
- Android完美解决The specified child already has a parent. You must call removeView() on the child