一、createScrollView

1、First, select the panel you want to be your scroll view and right-click anywhere in the Scene View to bring up the context menu, then choose Attach -> Scroll View.

2、The last step is to add the UIDragScrollView script to at least one collide. like create sprite then Attach -> box colider. Again, select the collider, right click in the scene view, Attach -> Drag Scroll View

3 、Now you Can Drag Sprite Only you Drag Sprite.

二、ScrollView_V2
   ScorllView 创建之后只能在item上拖动才能有效,实现在ScorllView 区域内都能drag item。
1 Create ->Widget scale the screen size equle to the size of Scroll View
2 attach the box colider then attach the UIDragScrollView
3 Now you can drag scroll view item which  contains the ScrollView Rectangle
 注意 Scorll View 和 UIRoot Depth 都有panel组件,所以即使Widget 的depth 高于 item的depth ,

因为Scroll View Panel 的 depth 高于UIRoot ,所以不用担心item接受不到drag event.

三、Drag Item && Grid

  很多时候我们需要在Scroll View中Drag Item 到外面(Attach - > UIDragDropItem ,但是一旦脱出Scorll View 之后就消失不见了,可以再加一个Panel,Attach - > UIDragDropRoot 让其出Scroll View 可见,但是一旦放松鼠标之后还会不见)。

  如果 release 鼠标后 item就要回来,要保证不能超出Scorll View ,这就要用到Grid。

  To use UIGrid, select a panel, right-click anywhere in the scene view, and choose the Gridfrom the [/b]Create menu. You may also simply attach the UIGrid component to any empty game object.

  

  接下来让我们实现这个效果:

  1、select all sprite attach DragDropItem script then we can drag items (like sprite1 ,sprite 2)

  2、create UIGrid ,select all sprite as it's child,you can set Arrangement and Sorting  

    Arrangement: item 排列的方式

    Sorting :item drag 之后的排列,比如 horizontal 可以让item drag 到最后面。

  3 set restriction of all sprite's DragDropItem script to vertically

  4 这样drag item 之后就可以主动回来了。

   这样item 就只能向上拉影响item位置,而不会左右拉影响item位置

  

四、TWO Drag

  看ngui 的 scrollview example 我们就可以看到两个grid,他们之间可以互相拖动物体到对方的grid中。

  让我们来实现个效果:

  注意,如果你的item drag出 scroll view 之后就消失了,那么你需要create -> uipanel, then add DragDropRoot on it,这样你的item 拖出来之后就可见了。上面已经讲过了

  

1、create gameobject attach boxcolider ,then add DragDopContainer on it ,name it Container1.(这个就保证我们拖出来的在这个区域可见,而不是放松鼠标就消失了)

2、之后使用上面第三步创建的scrollView,copy一个,去掉里面所有的sprite name it ScorllView1.

3 、将Container1 的 DragDopContainer 中的Reparent Targe reference to  ScrollView1 / Grid (copy 之后的 ScrollView中的子物体)

4、然后我们就可以拖动第一个scrollview 中的item (sprite) 到这个区域,这个item会自动排列到另一个 Scrollview1中去了。

5,但是我们还不能拖回去,当然实现的原理是一样的,copy 一个Container,用这个Container来引用第一个ScrollView中的Grid子物体即可。

   

PS:一般将ScrollView作为Container的子物体。

  如果你将item拖到别的contain上要求平滑过渡到中间你可以如下设置:

  

    

五、Last

  如果你觉得还有点问题,我就放个Demo上来吧

  http://yunpan.cn/Q7nXTchHfX6AR  访问密码 c033

  

NGUI Tutorial 4 ScrollView的更多相关文章

  1. [Unity]Unity开发NGUI代码实现ScrollView(放大视图)

    Unity开发NGUI代码实现ScrollView(放大视图) 下载NGUI包 导入NGUI3.9.1版本package 创建MainCameraScript.cs脚本 MainCameraScrip ...

  2. [Unity]Unity开发NGUI代码实现ScrollView(滚动视图)

    Unity开发NGUI代码实现ScrollView(滚动视图) 下载NGUI包 导入NGUI3.9.1版本package 链接: http://pan.baidu.com/s/1mgksPBU 密码: ...

  3. NGUI Tutorial 3

    一. Create a Button 一.(Menu)NGUI -> Create -> Sprite 二.attach box colider to the Sprite , then ...

  4. NGUI ScrollView总结

    1顶级父类加boxCollider和UIDragScrollView脚本保证在item拖走后也能通过拖拽剩余区域的方式操作. 2下一级添加UIPanel在Clipping设定区域,注意如果设定soft ...

  5. Unity3d之ScrollView实现图片浏览切换功能----折磨的学习

    由于项目需要,需要用NGUi实现一个图片浏览切换的功能,于是参考官方NGUI例子的ScrollView做了一个例子,初始看上去基本实现了自己想要的功能. 但是测试后发现当隐藏其中一张图片后,后面图片不 ...

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

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

  7. 使用泛型简单封装NGUI的ScrollView实现滑动列表

    懒,是老毛病了,周末跑了半马,跑完也是一通累,好久没锻炼了..也是懒的,有时都懒的写博客..最近看到项目中各种滑动列表框,本着要懒出水平来的原则,决定花点时间简单处理下(暂时未做列表太多时的优化):1 ...

  8. 关于Unity中NGUI的背包实现之Scrollview(基于Camera)

    基于UIPanel的scrollview实现方式在移动设备上的性能不如基于camera的方式.因为UIPanel的scrollview实现方式要渲染很多的道具图,性能自然就降低了.如果是用第二个摄像机 ...

  9. 关于Unity中NGUI的Tab商城、Scrollview和打字机效果的实现

    Tab商城实例 UIToggle 和 UIToggledObjects+ Box Collider(实现商城功能必备) 1.创建两个个UI Sprite,Sprite1和Sprite2 2.给Spri ...

随机推荐

  1. Linux下sublime的中文输入问题

    比较久了,今天找到了解决方案: git clone https://github.com/lyfeyaj/sublime-text-imfix.git cd sublime-text-imfix &a ...

  2. bzoj 1115: [POI2009]石子游戏Kam -- 博弈论

    1115: [POI2009]石子游戏Kam Time Limit: 10 Sec  Memory Limit: 162 MB Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前 ...

  3. SCOJ 4493: DNA 最长公共子串 后缀自动机

    4493: DNA 题目连接: http://acm.scu.edu.cn/soj/problem.action?id=4493 Description Deoxyribonucleic acid ( ...

  4. HDU 4619 Warm up 2 最大独立集

    Warm up 2 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4619 Description Some 1×2 dominoes are pla ...

  5. Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present 记忆化搜索

    D. Mysterious Present 题目连接: http://www.codeforces.com/contest/4/problem/D Description Peter decided ...

  6. acdream 1725 哗啦啦的小彭玉染色问题 离散化并查集

    哗啦啦的小彭玉染色问题 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acdream.info/problem?pid=1725 Descri ...

  7. Linux6.9用RPM方式安装MySQL5.7.21

    1.下载安装包 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-1.el6.x86_64.rpm-bundle.tar ...

  8. web前端笔记整理,从入门到上天,周周更新

    由于大前端知识点太多,所以一一做了分类整理,详情可见本人博客 http://www.cnblogs.com/luxiaoyao/ 一.HTML 1.注释 格式:<!-- 注释内容 --> ...

  9. 发现一个可以搜索常用rpm包的地址(http://www.rpmfind.net/)

    http://www.rpmfind.net/ 虽然资源不多,但也够用.

  10. 在WPF中显示动态GIF

    在我们寻求帮助的时候,最不愿意听到的答复是:很抱歉,在当前版本的产品中还没有实现该功能... 在WPF中显示动态的GIF图像时便遇到了这样的问题,WPF中强大的Image控件却不支持动态的GIF(其只 ...