Unity makes scrolling Item interface:
The first way: (Panel method implementation)
1. Create a Gameobject (a), add UIPanel and Uiscrollview
2. Add the drag Scroll View and the box colliders (usually add a grid, put the object into the grid, put the grid in a)
Precautions:
1. Dynamically loaded item coordinates are not correct, use grid component Reposititon () to update
Code implementation:
usingUnityengine;usingSystem.Collections;usingSystem.Collections.Generic; Public classRootpanel:monobehaviour { PublicUiscrollview View; Publicgameobject items; PublicGameobject Grid; PublicList<gameobject> itemList =NewList<gameobject>(); Public voidStart () {foreach(varIinchitemList) {grid.getcomponent<UIGrid>(). AddChild (I.transform); } view. Scroll (1f); } Public voidNextPage () {view. Moverelative (NewVector3 ( $,0,0)); View. Restrictwithinbounds (false,true,false); } Public voidPreviousPage () {view. Moverelative (NewVector3 (- $,0,0)); View. Restrictwithinbounds (false,true,false); } //Scroll to the front Public voidNext () {view. Scroll (1f); } //Scroll to the back Public voidPrevious () {view. Scroll (-1f); } //Add Public voidAdd () {varClone =(Gameobject) instantiate (items,vector3.zero,quaternion.identity); Clone.transform.parent=Grid.transform; Clone.transform.localScale=NewVector3 (1,1,1); Itemlist.add (clone); Grid.getcomponent<UIGrid>(). AddChild (Clone.transform); Grid.getcomponent<UIGrid>(). Reposition (); } //Delete intindex =0; Public voidRemove () {varGrid = Grid.getcomponent<uigrid>(); Destroy (Itemlist[index].gameobject); Index++; Grid.repositionnow=true; }}
Source code: Http://yunpan.cn/cyP9DQ22JpYJk Extract Code 7131
Unity makes scrolling item interface