9965人加入学习
(107人评价)
UGUI整体解决方案-基础篇(Unity 2019.1.0f2)

2019-06-01

价格 免费

必须存在依赖IDrag接口方法,其他三个无法使用。

out参数的使用?

var rect =Getcomponent<Recttransform>();
Vector2 pos=Vector zero;
Recttransformutility. Screenpointtoworldpointinrectangle(rect, eventdata position, eventdata.entereventcamera, out pos);

rec.position = pos;

[展开全文]

其实直接transform.position = eventData.position就完了

[展开全文]

拖动功能接口 必须要有OnDarg 否则其他3个不执行

图形拖动实现

使用RectTransformUtility.ScreenPointToWorldPointInRectangle获取世界坐标,赋值给图形

    void IDragHandler.OnDrag(PointerEventData eventData)
    {
        RectTransform rect = GetComponent<RectTransform>();
        Vector3 pos = Vector3.zero;

        RectTransformUtility.ScreenPointToWorldPointInRectangle(rect, eventData.position, eventData.enterEventCamera,
            out pos);
        rect.position = pos;
    }

 

[展开全文]

所有的拖拽接口都依赖于OnDrag

也就是说如果想实现拖拽功能的话,必须要有OnDrag

 

[展开全文]

授课教师

课程特色

视频(61)
下载资料(1)