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 zachwuzhere · May 11, 2017 at 09:42 PM · arraylistarraylist

Simple way to access data of different types within a nested array?

If for example, a high Adrenalin, heart thumping, full featured AAA production, action packed, competitive racing game where the primary receptacle for transportation is a magic umbrella where players float around racing to predetermined destination like Mary Poppins, I need a way to store the types of Umbrellas available for use. So if they choose to change from a full size "automatic" umbrella, to a faster lightweight solution like a "pocket" umbrella, I can use the array below as such:

    Dictionary<string, Dictionary<string, double>> Umbrellas = new Dictionary<string, Dictionary<string, double>>
             {
                 { "automatic", new Dictionary<string, double> { { "canopy_scale", 0.80 }, { "rib_count", 24 }, { "pole_height", 16 } } },
                 { "pocket", new Dictionary<string, double> { { "canopy_scale", 0.23 }, { "rib_count", 12 }, { "pole_height", 7 } } },
                 { "golf", new Dictionary<string, double> { { "canopy_scale", 0.70 }, { "rib_count", 30 }, { "pole_height", 20 } } }
             };
 
         var ChangeCanopy = true;
         var UmbrellaType = 2;
         var ChangeRibs = true;
         var UmbrellaRibs = 1;
     
         if(ChangeCanopy){
 
 
             var UmbrellaType = "";
 
             if( ChangeCanopy == 1 ){
 
                 //To scale the objects canopy to "automatic" size:
                 UmbrellaType = "automatic";
         
             }else if( ChangeCanopy == 2 ){
 
                 //To scale the objects canopy to "pocket" size:
                 umbrellaProperty = "canopy_scale";
 
             }else if( ChangeCanopy == 3 ){
 
                 //To scale the objects canopy to "golf" size:
                 umbrellaProperty = "canopy_scale";
 
             }else{
                 //Default if | input != (1,2,3)
                 umbrellaProperty = "automatic";
             }
 
             var scale = Umbrellas[UmbrellaType][umbrellaProperty];
 
             Umbrella.transform.localScale = new Vector3[scale, scale, scale];
 
 
         }else if(ChangeRibs){
 
 
             var RibType = "";
                 
             if( UmbrellaRibs == 1 ){
         
         ... ect.

This is not how the array would be used in practice, its an over exageration of its functionality. The primary purpose of doing it this was is to rely only on the data

structure itself without any function overhead, or complex classes ... can this be done? In a more managble way then this horid nested array declaration, can an array be

nested inside an array, like so with different types of data where it can contain strings with float or ints as well?? like this:

         Dictionary Umbrellas = new Dictionary<string>;
 
         Umbrellas["automatic"]= { "canopy_scale", 0.80 }, { "rib_count", 24 }, { "pole_height", 16 };
         Umbrellas["pocket"]= { "canopy_scale", 0.23 }, { "rib_count", 12 }, { "pole_height", 7 };
         Umbrellas["golf"]= { "canopy_scale", 0.70 }, { "rib_count", 30 }, { "pole_height", 20 } };
         
         Umbrellas["color"]= { "string", new Dictionary<string> }, { "hex", new Dictionary<string> } };
         Umbrellas["color"]["string"]={ "automatic", "red" }, { "pocket", "green" }, { "golf", "blue" };
         Umbrellas["color"]["hex"]={ "automatic", 0xFF0000 }, { "pocket", 0x00FF00 }, { "golf", 0x0000FF };


Is there any way to achieve ^ in this a manner, or even a better simple way to organize data that can potentially achieve better performance??? I have searched and cannot find how to nest arrays, and access the value of differing data types by key-name. This is not premature optimization, there has to be a best way to do this ... that is what I am asking

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

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.

Follow this Question

Answers Answers and Comments

110 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 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 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

Array problem, I'm novice 1 Answer

Cant figure out how to implement a inventory system 1 Answer

Destroy GameObject after certain amount is reached? 1 Answer

Remove connection between lists or arrays 3 Answers

Building tycoon game, need help storing variables into an array. 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