子类化拖拽容器组件,复写拖拽结束逻辑。
using UnityEngine;
using System.Collections;
public class MyDrag : UIDragDropItem
{
//拖拽结束时
//surface拖拽结束时碰到的精灵
protected override void OnDragDropRelease(GameObject surface)
{
base.OnDragDropRelease(surface);
Transform releaseParent = transform.parent;
if (surface != null)
{
if (surface.tag == "Back"){
transform.parent = surface.transform;
transform.localPosition = Vector3.zero;
}
else if (surface.tag == "Obj"){
Transform surfaceParent = surface.transform.parent;
transform.parent = surfaceParent;
transform.localPosition = Vector3.zero;
surface.transform.parent = releaseParent;
surface.transform.localPosition = Vector3.zero;
}
}
else
transform.localPosition = Vector3.zero;
}
}