OnDragDropRelease的使用

来源:互联网 发布:自动生产线数据采集器 编辑:程序博客网 时间:2024/05/11 04:30

1.: UIDragDropItem {}

继承于UIDragDropItem这个类。

2. //重写方法 当拖拽释放的时候调用
    protected override void OnDragDropRelease(GameObject surface)
    {
        base.OnDragDropRelease(surface);


        print(surface);
            print(surface.tag);
            this.transform.parent = surface.transform; //把物品放入格子里面


            this.transform.localPosition = Vector3.zero;//把物品居中
 
    }


    protected override void OnDragDropStart()
    {
        base.OnDragDropStart();
        print("移动开始");
    }

表示拖拽到了哪个gameobject上,目标点有boxcollider

可以动态添加boxcollider

Bounds bound = NGUIMath.CalculateRelativeWidgetBounds( transform ) ;//计算边界
BoxCollider collider = GetComponent<BoxCollider>() ;
if(collider == null)
{
collider =transform.gameObject.AddComponent<BoxCollider>();
}
collider.center = bound.center ;
collider.size = new Vector3( 100 , 100, 0 ) ;
collider.enabled = true ;

0 0
原创粉丝点击