- public class DragAndDropEquipment : UIDragDropItem
- {
- /// <summary>
- /// 重写拖动结束后
- /// </summary>
- /// <param name="surface"></param>
- protected override void OnDragDropRelease(GameObject surface)
- {
- // base.OnDragDropRelease(surface);
- if (surface.tag == "Item")
- {
- Transform old = this.transform.parent;
- Transform newold = surface.transform.parent;
- surface.transform.SetParent(old);
- surface.transform.localPosition = Vector3.zero;
- this.transform.SetParent(newold);
- this.transform.localPosition = Vector3.zero;
- this.GetComponent<BoxCollider>().enabled = true;
- }
- else
- if (surface.tag == "Box" && surface.transform.childCount == 0)
- {
- //设置物品的父对象(将物品放入格子中)
- this.transform.parent = surface.transform;
- //把物品居中
- this.transform.localPosition = Vector3.zero;
- this.GetComponent<BoxCollider>().enabled = true;
- }
- else
- if (surface.tag == "Box" && surface.transform.childCount == 1)
- {
- Transform old = this.transform.parent;
- Transform newold = surface.transform;
- GameObject go = surface.transform.GetChild(0).gameObject;
- go.transform.SetParent(old); ;
- go.transform.localPosition = Vector3.zero;
- this.transform.SetParent(newold);
- this.transform.localPosition = Vector3.zero;
- this.GetComponent<BoxCollider>().enabled = true;
- }
- else
- {
- this.transform.localPosition = Vector3.zero;
- }
- }
- }