• 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 /
avatar image
1
Question by beans · Nov 11, 2010 at 07:57 PM · gameobjecthierarchybrowser

Creating a hierarchial GameObject Browser

I am trying to create an object browser for GameObjects in Unity. The user should be able to see the main parent object originally. If they select the main parent, they should be able to see the children (and so on and so forth). There should be some indicator of what objects have children (a toggle button, little arrow, etc). Every child of the selected parent should be given space and the things below them should be moved down. The problem I encounter is that formatting is very tricky (accessing children/parents is not the problem). I cannot use Windows.Forms because this project is supposed to be platform independent. How can I create a hierarchical object browser? For reference, the hierarchy view in the Unity window is a perfect example of what I am trying to do.

For some background, I have attempted to use buttons, but the code I am writing is being called from OnGUI and thus is called continuously. The effects of a button click get overwritten instantly. I am currently using toggle buttons in a recursive function that calls itself every time it encounters an object with children. It does not create toggle buttons for all children, just the first.

This is the code I have so far (I know there are a few errors in it currently): public struct member { public int level;

public member (List<bool> bools, int index, string name, int lev) { GUILayout.BeginHorizontal (); bools[index] = GUILayout.Toggle (bools[index], "", GUILayout.MaxWidth (15)); bools[index + 1] = GUILayout.Toggle (bools[index + 1], name, GUI.skin.GetStyle ("label")); level = lev; GUILayout.EndHorizontal (); }

}

void showChildren (GameObject parent, member parM) {

int level = parM.level; foreach (Transform child in parent.transform) { count += 2; Rect r = new Rect ((30 * level+1)+ 10*(count/2), (40 * level+1) + 20*(count/2), 350 - (10 * level), 350 - (20 * level)); GUILayout.BeginArea (r); toggles.Add (false); toggles.Add (false); member childT = new member (toggles, count, child.name, parM.level); if(child.transform.GetChildCount() != 0){ showChildren(child.gameObject, childT); } GUILayout.EndArea (); }

}

Comment
Add comment · Show 2
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 Jesse Anders · Nov 11, 2010 at 11:37 PM 0
Share

So you're essentially trying to create an 'in-game' version of the hierarchy view - is that correct? As far as the effects of button clicks being 'overwritten instantly', it's hard to say without seeing your code, but it sounds like you're not saving the current state of the hierarchy display correctly (or maybe at all).

avatar image beans · Nov 12, 2010 at 02:02 PM 0
Share

Yes, that is correct. The "overwriting" effect is due to the fact that button actions are only done when a button is pressed. So, the button is pressed and (for example) the text is written. Then, OnGUI is called, the button is not pressed, the text is not written and the effect of the button press is lost.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Is there anyway to batch renaming via Editor [not on Runtime] multiple game objects in the hierarchy ? 4 Answers

Using empty gameobjects as "folders" in scene hierarchy panel 1 Answer

Unity lag on selection 0 Answers

Unity IDE: Finding out object type of arbitrary item in Hierarchy 3 Answers

Hierarchy Foldout Variables Wanted 3 Answers


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