Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Griffo · May 28, 2014 at 04:14 PM · arraylistfloat

Array or List holding 3 floats, multidimensional, Jagged?

Hi,

As below I have 3 arrays holding floats, 7, 7 and 4 .. What I'd like to do is make a list or array (as I know lists are faster) with all these values in one list or array, so I could call 1,1 .. 1,2 .. 1,3 when I want the 1st values and 2,1 .. 2,2 .. 2,3 when I want the 2nd values .. ect .. ect

So would this be a multidimensional array, jagged or ?

What would be the best way to do this?

Would I use something like ..

 var aGrid : float[,];
 
 function Start () {
 
     aGrid = new float[ 7, 3 ];
 // Init aGrid
 // ----------------------
     aGrid[ 0, 0 ] = 5;
     aGrid[ 0, 1 ] = 2.5;
     aGrid[ 0, 2 ] = 1.4;
 // ----------------------
     aGrid[ 1, 0 ] = 4;
     aGrid[ 1, 1 ] = 2;
     aGrid[ 1, 2 ] = 1.2;
 // ----------------------
     aGrid[ 2, 0 ] = 3;
     aGrid[ 2, 1 ] = 1.5;
     aGrid[ 2, 2 ] = 0.8;
 // ----------------------    
     aGrid[ 3, 0 ] = 2;
     aGrid[ 3, 1 ] = 1;
     aGrid[ 3, 2 ] = 0.4;
 // ----------------------    
     aGrid[ 4, 0 ] = 2;
     aGrid[ 4, 1 ] = 2;
     aGrid[ 4, 2 ] = 0;
 // ----------------------    
     aGrid[ 5, 0 ] = 1.6;
     aGrid[ 5, 1 ] = 1.6;
     aGrid[ 5, 2 ] = 0;
 // ----------------------    
     aGrid[ 6, 0 ] = 1.08;
     aGrid[ 6, 1 ] = 1.08;
     aGrid[ 6, 2 ] = 0;
 // ----------------------
 }


Or have I missed it completely ?

Should I put all those numbers in a string then populate the array in a loop?

thanks ..

alt text

screen shot_01.jpg (40.4 kB)
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 cryingwolf85 · May 28, 2014 at 04:52 PM 0
Share

$$anonymous$$y answers is below, though I wanted to add to your statement of lists being faster than arrays: This is not true in most cases. A list has a lot of overhead, which requires more machine instructions (please correct me if i'm wrong). But I wouldn't worry much about it, then you start getting into micro optimization which is nothing to worry about unless you absolutely need it.

avatar image Griffo · May 28, 2014 at 04:59 PM 0
Share

cryingwolf85, Thanks for the input, 90% of what I've read in this forum has pointed to lists being faster, as you say it's micro optimisation I suppose I need not worry .. :)

Thank you for your answer below, as I'm .js I'll look into that, again thanks for the input.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by cryingwolf85 · May 28, 2014 at 04:43 PM

If I were going for simplicity, I would use an object to represent the other 3 numbers. For example:

 public class Nums {
 
     public float n1, n2, n3;
 
     public Nums(float n2, float n3, float n3){
         this.n1 = n1;
         this.n2 = n2;
         this.n3 = n3;
     }
     
 }

and then create a list like this:

 List<Nums> nums = new List<Nums>();
 nums.Add(new Nums(1.5f, 1.7f, 3.4f));

For however many nums you want. Hope that helps.

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

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

21 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

Related Questions

A node in a childnode? 1 Answer

Pick between two floats 2 Answers

how to define spesific object in list? 2 Answers

How do I add Prefabs from Resources folder to List 3 Answers

List of bools assigned to each Gameobject in List/Array 0 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