Unity:用UI制作ScrollView

1.创建空object

2.将上面object放入canvas中

3.为之加入组件:UI->Scroll Rect

4.在这个object中加入2D的Panel

5.确定这个Panel大小

6.放入你的控件(按钮之类)

7.将这个panel拖入到object的Conent栏位中

试试吧...

 

参考文章:

Create A Level Select Scroll Menu - Unity 4.6

 
There will be times when we want to add a Scroll Menu to our game, for instance, we use it for a  Level Selection Menu. We will be learning how to achieve this with the all new Unity 4.6 uGUI.


Need an inspiration to follow this post?




If you're inspired and want to learn, then, let's start the learning.

1. To begin, we need to create a Unity Project, if one is not existing already. Create a New Scene named Level Select.

2. Create a Canvas by navigating to Create->UI->Canvas in the Hierarchy.


3. Create an Empty GameObject and rename it as ScrollView. Make it the child object of the Canvas.


4. With the ScrollView selected in the Hierarchy, move to the Inspector panel and click on Add Component->UI->Scroll Rect to add a Scroll Rect script to the ScrollView object.
Once you do it, modify the configurations as in the image below.


- We have unchecked the Horizontal checkbox, as we do not want the horizontal movement.
- The Deceleration Rate is set to a very low value of 0.0001 for the rate at which the ScrollView decelerates. Lower the value, lesser the movement on release of the cursor / touch.

5. Add a Text component within the Canvas we created earlier and name it TextSelectlevel.
- Change the Text to be displayed in the Text (Script) as SELECT LEVEL.
- Check the Best Fit checkbox. Set the Min Size to 10 and Max Size to 50 (or any value you like, for that matter).
- Place the Text somewhere near the top to make it look like a Menu Heading. Position the four anchor points at the edges of the Text. 
(Take a look at the image below)


6. Select the Rect Transform tool from the tools section and resize the ScrollView as in the GIF below

 


7. Right Click on the ScrollView in the Hierarchy and create a Panel. Resize the panel as shown in the gif below to add our Level buttons.


Note: In case you want the Scroll Rect to Resize dynamically, place the anchor point of it's to the corners as in the image below


8. Create a Button inside the Panel. Rename it as Level1 and set it's Text component to LEVEL 1.
Position it near the top end of the Panel. Resize it as per your needs and place the anchor points to it's edges to resize the button dynamically.
Check the Best Fit checkbox of the Text component to resize the Text.


9. Duplicate the Button by pressing ctrl+D while the Level1 button is selected. Rename and reposition the button according to your needs. Also, reposition the anchors of each button to their edges. The below image shows a sample arrangement of the buttons.

 

10. Drag and drop the Panel into the Content field of the Scroll Rect script component of the ScrollView object. Once you do that you can scroll the menu to see the level buttons which was not possible earlier.


11. If the Select Level text is not center aligned, you can do so as in the image below


12. You can add an Image to be displayed behind the Select Level Text so that it looks aesthetic. You can try various color combinations and design your menu as you like. 
I have never been a good designer, but I have managed to design one for this, might not be as good as you people might do though. The reason behind doing this was to demonstrate how powerful the new Unity UI system is.

   
13. If you add a background image for the Select Level Text, remember to place it above the Text in the inspector, as the one with lower position is placed over the above objects in the Hierarchy.


You can download the Unity package of this post from the link below:
Scroll Menu using scrollbar - Unity 4. 6
 

转载于:https://www.cnblogs.com/ArthurLu/p/4718160.html

你可能感兴趣的:(Unity:用UI制作ScrollView)