最近要实现一个NGUI效果。

  

  

  查看了一下,NGUI有个自带 UIDragDropItem.cs 的组件进过修改后即可以实现。

   下面贴上UI布局,代码:

  

  mDragDropItem.cs
 using UnityEngine;
using System;
using System.Collections; public class mDragDropItem : UIDragDropItem
{
public BingZhong_Id bingzhong_id; protected override void OnDragDropStart()
{
base.OnDragDropStart(); ///一旦被克隆,克隆体设置新的参数
///表示 克隆体移动 是直接移动本体
if (this.cloneOnDrag)
{
this.cloneOnDrag = false;
this.restriction = Restriction.None;
Destroy(GetComponent<UIDragScrollView>());
}
} protected override void OnDragDropRelease(GameObject surface)
{
// Is there a droppable container?
UIDragDropContainer container = surface ? NGUITools.FindInParents<UIDragDropContainer>(surface) : null; //检测到容器
if (container != null)
{
//clear child
foreach (Transform item in container.transform)
{
Destroy(item.gameObject);
} mTouchID = int.MinValue; // Re-enable the collider
if (mButton != null) mButton.isEnabled = true;
else if (mCollider != null) mCollider.enabled = true; mTrans.parent = (container.reparentTarget != null) ? container.reparentTarget : container.transform;
mTrans.localPosition = Vector3.zero; // Update the grid and table references
mParent = mTrans.parent; // Notify the widgets that the parent has changed
NGUITools.MarkParentAsChanged(gameObject);
}
//没有检测到
else
{
NGUITools.Destroy(gameObject);
}
}
}

  

  在本体上设置如上图的参数, 这样你拖出来就可以是克隆体,原来Grid的Item不变。

  但是 克隆体自己 要重新设置参数,

  参数设置在 OnDragDropStart() 函数中

(注意:OnDragDropStart() 函数是由本体调用克隆体的, 本体不会调用自己的 OnDragDropStart(), 所以你不用担心你在修改本体的参数)

  

拖放结束,克隆体 调用 OnDragDropRelease(GameObject surface) 方法,

  GameObject surface 表示释放后 NGUI射线 检测到的碰撞体,

    如果是NULL或者 没有检测到UIDragDropContainer,则销毁自己,

    不然如果有 UIDragDropContainer,则重新设置自己的位置,重新设置自己的parent。

NGUI 自定义 Drag Item Script的更多相关文章

  1. 使用自定义的item、Adapter和AsyncTask、第三方开源框架PullToRefresh联合使用实现自定义的下拉列表(从网络加载图片显示在item中的ImageView)

    AsyncTask使用方法详情:http://www.cnblogs.com/zzw1994/p/4959949.html 下拉开源框架PullToRefresh使用方法和下载详情:http://ww ...

  2. NGUI ScrollView 循环 Item 实现性能优化

    今天来说说一直都让我在项目中头疼的其中一个问题,NGUI 的scrollView 列表性能问题,实现循环使用item减少性能上的开销. 希望能够给其他同学们使用和提供一个我个人的思路,这个写的不是太完 ...

  3. NGUI UIScrollView - 大量item子项的性能优化

    一.当UIScrollView的以下的包括的子项太多(二三十个之上)时.它的滚动就会变的有些卡不流畅,尤其是在手机上. 对些网上也有非常多的优化它的相关,以下是我的一个优化: 1.将在超出裁剪框的一个 ...

  4. 如何自定义RecycleView item的间距

    引言 在以前使用ListView和GridView时,设置item之间的间距还是相对比较简单的,因为它们的基本属性里面Android已经定义好了,可以直接设置属性值即可.但Google为了通用性和灵活 ...

  5. Android 自定义ListView Item侧滑删除

    本程序是基于网上开源项目修改而来,具体来源忘了,懒得搜了,如果有不合适的地方,请原作者联系我,我会及时回复和处理的! 该例子程序中主要包含两个ListView,一个是实现侧滑删除,一个是侧滑出菜单,代 ...

  6. listview自定义背景以及item自定义背景

    item向自定义背景,可以根据position来设置不同的背景. listview背景设置是需要注意设置下面这几项: //点下时整个页面的背景 android:cacheColorHint=" ...

  7. Qt-网易云音乐界面实现-7 消息中心实现,主要是QListWidget 自定义Item 和QTabwidget使用

    最近写的有点烦躁, 感觉内容真的很多!很多!很多. 目前真的想知道网易官方在出这款产品是,用了多少人和多长时间. 今天写的这个消息中心,有点糙,只是原理实现了没有完全复制过来,心里有团火,不想写了. ...

  8. Qt listwigwt item 加入自定义元素

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  9. NGUI Scroll List

    NGUI Scroll List 1.Add GameObject with Script UI Panel(NGUI -> UI -> NGUI Panel) and Script UI ...

随机推荐

  1. python二叉树递归算法之后序遍历,前序遍历,中序遍历

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2016-11-18 08:53:45 # @Author : why_not_try ...

  2. Requests:Python HTTP Module学习笔记(一)(转)

    Requests:Python HTTP Module学习笔记(一) 在学习用python写爬虫的时候用到了Requests这个Http网络库,这个库简单好用并且功能强大,完全可以代替python的标 ...

  3. Test,Nginx Hello World Module

    ngx_addon_name=ngx_http_mytest_module HTTP_MODULES="$HTTP_MODULES ngx_http_mytest_module" ...

  4. Hashset,Iterator

    HashSet类主要是设计用来做高性能集运算的,例如对两个集合求交集.并集.差集等.集合中包含一组不重复出现且无特性顺序的元素. (一)HashSet的一些特性如下: 1.HashSet中的值不能重复 ...

  5. poj 3625 Building Roads

    题目连接 http://poj.org/problem?id=3625 Building Roads Description Farmer John had just acquired several ...

  6. hdu 5154 Harry and Magical Computer

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5154 Harry and Magical Computer Description In reward ...

  7. Java使用JSP Tag Files & JSP EL Functions打造你自己的页面模板

    1. 简单说明:在JSP 2.0后, 你不再需要大刀阔斧地定义一堆TagSupport或BodyTagSupport, 使用JSP Tag Files技术可以实现功能强大的页面模板技术. 在这里抛砖引 ...

  8. 基于jquery的页面代码的优化

    高亮显示,选中的文字链接 显示效果如下 默认选择“通知公告”效果 通知公告 学院动态 行业动态       选择“学院动态”效果 通知公告 学院动态 行业动态       选择“行业动态”效果 通知公 ...

  9. exception -----> Typedefs & Classes

    #include <exception> Typedefs exception_ptr 一种类型,描述了一个指向异常的指针 terminate_handler 一种类型,描述了一个适合作为 ...

  10. 如何设置电脑的IP

    先找到自己的ip,在设置ip. 图1 图2 图3 图4 图5 图6