• 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
0
Question by Aurla · Jan 21, 2011 at 08:05 PM · classtreenode

Help creating a tree type data structure (C#)

I'm trying to store a branching string of Vector3s in a variable.

To do this, I figured I had to make my own class.

For a visualization:

Root Node: (0,0,0)
            /   \ 
        (1,2,3)  (4,5,6)
       /  |  \   /  |  \

and so on. I need to be able to dynamically add children and traverse each path and test for certain conditions. Can anyone help me out? Thanks.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by _Petroz · Jan 21, 2011 at 08:17 PM

It sounds like you want an unbalanced, non-binary tree.

This answer provides a possible implementation of the nodes of such a tree: http://stackoverflow.com/questions/66893/tree-data-structure-in-c/2012855#2012855

Usage of that code would be something like:

NTree<Vector3> vecTree = new vecTree(Vector3.zero);

// Add children to root node vecTree.addChild(new Vector3(1f, 2f, 3f)); vecTree.addChild(new Vector3(4f, 5f, 6f));

// Add a child to first child of the root node [ the one that is (1,2,3) ] vecTree.getChild(0).addChild(new Vector3(7f, 8f, 9f))

Comment
Add comment · Show 4 · 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 Aurla · Jan 21, 2011 at 08:57 PM 0
Share

This does look rather useful. However, I'm rather a novice at creating classes and then -using- them. Can I get an example on the implementation of this code?

avatar image _Petroz · Jan 21, 2011 at 10:08 PM 0
Share

I have edited my post to include example usage.

avatar image Aurla · Jan 21, 2011 at 10:21 PM 0
Share

Thank you for the reply. Using that, I get the error on the first line: "'searchWeb.vecTree' is a 'field' but is used like a 'type'

I am unsure if I set up the class script correctly. I pretty much copy and pasted it into a TreeVisitor.cs file.

avatar image crafTDev · Aug 29, 2013 at 06:20 PM 0
Share

Any more update to this? I'm trying to implement something like this. http://forum.unity3d.com/threads/198041-Creating-Tree-like-code-in-C

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

2 People are following this question.

avatar image avatar image

Related Questions

Tree Creator - Editting Node Count 1 Answer

Tree Creator Null Exception 0 Answers

Accessing Tree Nodes through Script 1 Answer

store data structure for dynamic object in pragma strict. 0 Answers

How does one adjust tree bend factor in animation timeline? 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