About the stretch, prefab, Scroll view UI nodes in Unity

Source: Internet
Author: User

One, four petals of the last talk of Chrysanthemum, only four petals and the effect of the time together, is now the effect of the four petals of a separate chrysanthemum


1. Create a canvas
2. Initialize the canvas
3. Create an image UI node as a child node of the canvas, named BG.
4. Create a gameobject empty node as a child node of the canvas.
5. Create a UI child node of the image type named icon under Gameobject
6. Change the icon color to red for easy observation and change the size to 300x300
Click on the upper left corner of the stretch, pattern select the bottom right corner of the four petals corresponding to the state of Four Corners,
7. The role of chrysanthemum petals is the Father node Gameobject scaling how much, the child node icon scaling how much, four angle of the offset will not change, the relative distance is unchanged. Is that the child node is scaled with the parent node under the action of four petals.
8. If the upper middle two petals, below the middle two petals, then the parent node scaling, when the upper and lower, the child node is also up and down, when left and right, the child node will not shrink.

Second, the Precast body
Template, sometimes, a creep to generate 10, need a template
1. Create a canvas
2. Initialize the canvas
3. Create an image UI node as a child node of the canvas, named item.
4. Create a folder under the resources folder called Prefabs
5. Drag the item directly into the Prefabs folder
6. Discovery will automatically generate a prefab, the original item node will also turn blue
7. At this time modify the Hierachy under the item node, the preform will also change, remember to click on the upper right corner of apply
8.Revert means that the preform is overwritten back to the node, but modifying the properties in the Rect transform is not revert. Apply is saved from the node back to the prefab
9. If you want to disconnect this connection, select the node--menu-->gameobject-->break Prefab Instance
Modify the preform, all the nodes associated with it are modified, unless the connection is disconnected, when the prefab is modified, the node will not change, but once clicked revert or apply will reestablish the connection


A prefab is also a replication of a node
Instantiating a prefab using code
1. Write a script called Game_scane and mount it on the canvas node
2. Define the public property in the script, public gameobject Item_prefab
3. Drag the preform into the Game_scane script's Item_prefab property on the hierachy panel

 Public classGame_scene:monobehaviour { PublicGameobject Item_prefab;//Use this for initializationvoidStart () {Gameobject Item= Gameobject.instantiate ( This. Item_prefab);//instantiate an object as a template with a preset bodyItem.transform.SetParent ( This. Transform);//placed under the correct parent node, do not write this will be placed under the root nodeItem.transform.localPosition =NewVector3 (0,0,0);//Set coordinates    }}


Third, Scroll view node


1. Create a canvas
2. Initialize the canvas
3. Create an image UI node as a child node of the canvas, named BG.
4. Create a scroll View UI node under canvas as a child node
The viewport child node under the 5.Scroll view node, the viewport child node has a mask component to clip the display range of its child nodes, and viewport is equivalent to a mask
A content node below the 6.Viewport node is used to store the contents
The 7.Scrollbar horizontal and Scrollbar vertical are child nodes of the scroll view, representing the pull bar.
8. Create multiple Imgae UI sub-nodes under content and drag the same picture in
9. Give the content a typeset script, here with a grid
10. It is possible to drag content from top to bottom or left or right after running, because the horizontal and vertical are checked in the scroll RECT properties panel of the Scroll view node, indicating that both pull and pull are allowed.
11. Sometimes up and down can not be dragged, because the content of the height is too small, the height of the picture is more than the height of the content, modify the content of the height of good, with a calculator to calculate the height of content.
12.Scrollbar cannot be hidden when associated, can be deleted directly. The associated method is to drag the scrollbar node directly into the scrollbar attribute of the scroll rect of scroll view


Make a leaderboard
1. Create a canvas
2. Initialize the canvas
3. Create an image UI node as a child node of the canvas, named BG.
4. Create a UI node called Rank's scroll view as a child node under the canvas
5. Give rank a background image of a leaderboard
6. Create a sub-image node under rank called Tital, which is used to display the title picture of the score rank
7. Background image to be placed outside the rank node is OK, preferably a bit larger than rank, you can give rank's image a color, and then hide the image component
8. In rank again create a rank_option child node, type is image
9. Under Rank_option Sub-node, create a mask child node to put the clip mask node of the Avatar, remember to add the mask clip component and drag into the crop sticker.
10. Create an image node named Avator below the mask node to represent the picture of the Avatar. This time found no crop success, because there is no running reason, run up, the avatar is cropped.
11. Create an empty parent node above the mask and create an image type node below the empty parent node to display the picture frame.
12. Create an Image type UI node below the rank_option child node to place the split line, called Slice_line
13. Create a text-type UI node below the rank_option child node called Unick
14. Drag the entire Rank_option node into the Prefab folder prefabs to hide the iamge component of the empty node and remove the white area.
15. Add a layout component grid to the content of the rank node, usually with a grid, and wait to get a lot of rank_option nodes in.
16. Use code to instantiate and bulk add and place rank_option nodes

 Public classGame_scene:monobehaviour { PublicGameobject Item_prefab; PublicGameobject Rank_prefab; PublicScrollRect rank;
//Use this for initializationvoidStart () {//rect transorm This. Rank.content.sizeDelta =NewVector2 (0, -* the); for(inti =0; I < -; i++) {gameobject opt= Gameobject.instantiate ( This. Rank_prefab); Opt.transform.SetParent ( This. rank.content); Opt.transform.Find ("Unick"). Getcomponent<text> (). Text =""+ (i +1); } }}

About the stretch, prefab, Scroll view UI nodes in Unity

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.