- 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;
- }
- }
- }
Unity3d:NGUI实现背包物品拖拽,交换位置
最新推荐文章于 2023-11-30 22:24:52 发布
本文详细介绍了在Unity中实现装备拖放系统的具体代码逻辑,包括如何处理不同类型的物品拖放到物品槽或箱子上的场景,以及如何进行物品的交换和放置。

3116

被折叠的 条评论
为什么被折叠?



