Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by bhambhu · Oct 20, 2015 at 07:34 PM · guidynamicmenu screen

Dynamic Menu creation

Hello Friends,

I need to create a dynamic menu in which there can be different elements like Buttons/Toggle/Checkboxes/Textboxes. You can say like the one of Google Chrome's Setting menu. For reference i am attaching a image.

The problem is its is easy to create this type of menu statically. But i need to do this dyynamically so thaalt textt if i want 10 more buttons/checkboxes so that i can change easily at run time.

menu.png (47.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by bhambhu · Dec 08, 2015 at 05:14 PM

Hello Everyone and @Statement .

Sorry for late replying , I solved this dynamic menu creation problem using SetInsetAndSizeFromParentEdge .

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Statement · Oct 20, 2015 at 08:23 PM

Create prefabs for the buttons.
Make a menu builder script that populate the UI.
If you want objects to automatically layout, you need to write some layout class to handle that.

This is not a small question. There are lots of moving parts depending on how complex you want to get it and where you skill level is at. To start somewhere, create a button in Unity and make it a prefab. Then decide which parent they should be instantiated at (the canvas or some panel?).

Maybe something like this:

 void AddButton(Button prefab, string name, UnityAction callback)
 {
     Button button = Instantiate(prefab);
     button.name = name;
     button.onClick.AddListener(callback);
 
     Text text = button.GetComponentInChildren<Text>();
     if (text)
         text.text = name;
 
     RectTransform transform = button.GetComponent<RectTransform>();
     transform.SetParent(canvas.transform);
     transform.anchoredPosition = nextLayoutPosition;
     nextLayoutPosition += Vector3.down * transform.rect.height;
 }

Optionally you can access a git repo (or download as zip) here, or view source code files:

  • ButtonBuilder.cs

  • UIBuilder.cs

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bhambhu · Oct 23, 2015 at 08:03 AM 0
Share

Thanks @Statement . I am giving it a try . Thanks a lot . I am very hopeful that it will help me. Will update after going through.

avatar image Statement bhambhu · Oct 24, 2015 at 12:52 AM 0
Share

Sure, also check out the UI auto layout stuff. I didn't think of it when I wrote the example.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

42 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UI problems 0 Answers

How to create scene with multiple panels? 0 Answers

I cant see border on dynamically created button 0 Answers

How can i make a button appears when an inputfield is filled? 0 Answers

Trying to get Canvas child Panel to resize. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges