实现方式
1、引入UGUI自带的事件系统 UnityEngine.EventSystems
2、为我们的类添加接口 IBeginDragHandler, IDragHandler, IEndDragHandler
1 usingUnityEngine;2 usingSystem.Collections;3 usingUnityEngine.EventSystems;4
5 public classDragOnPic : MonoBehaviour,IBeginDragHandler, IDragHandler, IEndDragHandler {6
7
8 public voidOnBeginDrag (PointerEventData eventData)9 {10 throw newSystem.NotImplementedException ();11 }12
13
14 voidIDragHandler.OnDrag (PointerEventData eventData)15 {16 throw newSystem.NotImplementedException ();17 }18
19
20 public voidOnEndDrag (PointerEventData eventData)21 {22 throw newSystem.NotImplementedException ();23 }24
25 }
拼图游戏实例
1、准备一张拼图要用到的图片素材,并拖入Unity中
2、图片的TextureType选为Sprite(2D and UI), 点击Apply
3、将SpriteMode改为Multiple,点击SpriteEditor,在弹出的窗口中点Slice,Type为Grid,我这张图片分辨率是500x500的