UGUI学习笔记6——官方教程Draggable Panel练习

来源:互联网 发布:电子小报制作软件 编辑:程序博客网 时间:2024/06/01 09:47

Draggable Panel这个Demo主要还是用到了前面提到的几个接口。
以及这个方法:
public static bool ScreenPointToLocalPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector2 localPoint);
直接搬来官方文档:
rect The RectTransform to find a point inside.
cam The camera associated with the screen space position.
screenPoint Screen space position.
localPoint Point in local space of the rect transform.

Draggable Panel这个Demo主要实现的是拖动panel和改变panel大小的功能。分别在DragPanel和ResizePanel两个脚本中。思路还是通过UI事件的方式,通过获得鼠标点击以及鼠标位置来实现。
改变大小是用RectTransform中的sizeDelta属性来实现的,表示RectTransform的相对于锚点位置距离的size。

搜了一下网上关于EventSystem的文章。这一篇写的不错:
http://www.manew.com/blog-56596-2917.html

其实脚本中的接口对应的就是 Event Trigger中的那些方法。
如下:
IPointerEnterHandler - OnPointerEnter - Called when a pointer enters the object
IPointerExitHandler - OnPointerExit - Called when a pointer exits the object
IPointerDownHandler - OnPointerDown - Called when a pointer is pressed on the object
IPointerUpHandler - OnPointerUp - Called when a pointer is released (called on the original the pressed object)
IPointerClickHandler - OnPointerClick - Called when a pointer is pressed and released on the same object
IInitializePotentialDragHandler - OnInitializePotentialDrag - Called when a drag target is found, can be used to initialise values
IBeginDragHandler - OnBeginDrag - Called on the drag object when dragging is about to begin
IDragHandler - OnDrag - Called on the drag object when a drag is happening
IEndDragHandler - OnEndDrag - Called on the drag object when a drag finishes
IDropHandler - OnDrop - Called on the object where a drag finishes
IScrollHandler - OnScroll - Called when a mouse wheel scrolls
IUpdateSelectedHandler - OnUpdateSelected - Called on the selected object each tick
ISelectHandler - OnSelect - Called when the object becomes the selected object
IDeselectHandler - OnDeselect - Called on the selected object becomes deselected
IMoveHandler - OnMove - Called when a move event occurs (left, right, up, down, ect)
ISubmitHandler - OnSubmit - Called when the submit button is pressed
ICancelHandler - OnCancel - Called when the cancel button is pressed

官网连接:http://docs.unity3d.com/Manual/SupportedEvents.html

另外:
关于UI元素的中心点,我在5.2.1中还是不知道如何在scene面板中拖动设置。目前是通过点击anchor presets设置的。

实现接口中的方法要用Public修饰,在重写代码是有几次忘记了。

0 0