Unity makes scrolling Item interface

Source: Internet
Author: User
Tags addchild

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.