一、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. Tomcat+Apache集群方案

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha # environment slash for Windows(反斜杠代表Windows ...

  2. HDU 1698 Just a Hook (线段树)

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

  3. Test20171009 考试总结 NOIP模拟赛

    题目难度合适,区分度适中,但是本人水平不佳,没有拿到满意的分数. T1(matrix) 一种比较容易想到的想法是枚举起点求出最长全1串做预处理,这是O(n^2)的. 接着枚举列起点,列终点,通过后缀和 ...

  4. bzoj 4097: [Usaco2013 dec]Vacation Planning

    4097: [Usaco2013 dec]Vacation Planning Description Air Bovinia is planning to connect the N farms (1 ...

  5. MySql - GROUP BY 和 HAVING关键字

    本文主要针对GROUP BY 和 HAVING两个关键字进行分析 使用测试表如下: 测试前,只知道GROUP BY 这个关键字的作用是根据一个字段进行分组,去重.HAVING对分组设置条件. 具体分组 ...

  6. 腾讯通消息webSDK踩坑

    1.腾讯通提供一个通过http协议的接口,可用于发送消息,公告等功能,要使用其功能首先要开启RTX_HTTPServer服务. 2.阅读文档http://rtx.tencent.com/sdk/,为了 ...

  7. bzoj 4874: 筐子放球

    4874: 筐子放球 Time Limit: 10 Sec  Memory Limit: 256 MB Description 小N最近在研究NP完全问题,小O看小N研究得热火朝天,便给他出了一道这样 ...

  8. External components provide true shutdown for boost converter

    The step-up switching-converter circuit in Figure 1 presents a familiar problem: If you shut down bo ...

  9. [翻译] PBJNetworkObserver 网络监控

    PBJNetworkObserver 网络监控 https://github.com/piemonte/PBJNetworkObserver Introduction 'PBJNetworkObser ...

  10. [gevent源代码分析] 深度分析gevent执行流程

    一直对gevent执行流程比較模糊,近期看源代码略有所得.不敢独享.故分享之. gevent是一个高性能网络库,底层是libevent,1.0版本号之后是libev.核心是greenlet.geven ...