Unity3d:NGUI实现背包物品拖拽,交换位置

128 篇文章 1 订阅
64 篇文章 1 订阅
  1. public class DragAndDropEquipment : UIDragDropItem
  2. {
  3.     /// <summary>
  4.     /// 重写拖动结束后
  5.     /// </summary>
  6.     /// <param name="surface"></param>
  7.     protected override void OnDragDropRelease(GameObject surface)
  8.     {
  9.         // base.OnDragDropRelease(surface);
  10.         if (surface.tag == "Item")
  11.         {
  12.             Transform old = this.transform.parent;
  13.             Transform newold = surface.transform.parent;
  14.             surface.transform.SetParent(old);
  15.             surface.transform.localPosition = Vector3.zero;
  16.  
  17.             this.transform.SetParent(newold);
  18.             this.transform.localPosition = Vector3.zero;
  19.             this.GetComponent<BoxCollider>().enabled = true;
  20.         }
  21.         else
  22.         if (surface.tag == "Box" && surface.transform.childCount == 0)
  23.         {
  24.             //设置物品的父对象(将物品放入格子中)
  25.             this.transform.parent = surface.transform;
  26.             //把物品居中
  27.             this.transform.localPosition = Vector3.zero;
  28.             this.GetComponent<BoxCollider>().enabled = true;
  29.         }
  30.         else
  31.         if (surface.tag == "Box" && surface.transform.childCount == 1)
  32.         {
  33.             Transform old = this.transform.parent;
  34.             Transform newold = surface.transform;
  35.             GameObject go = surface.transform.GetChild(0).gameObject;
  36.             go.transform.SetParent(old); ;
  37.             go.transform.localPosition = Vector3.zero;
  38.             this.transform.SetParent(newold);
  39.             this.transform.localPosition = Vector3.zero;
  40.             this.GetComponent<BoxCollider>().enabled = true;
  41.  
  42.         }
  43.         else
  44.         {
  45.             this.transform.localPosition = Vector3.zero;
  46.         }
  47.  
  48.     }
  49. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值