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 IMoriarty · Dec 14, 2011 at 03:30 AM · dataarraylist

ArrayLists?

So, I'm attempting to create a list of values to be loaded during run time, and different sets of these values will need to be referable by the data holder and by the index within the holder. I was initially leaning towards an ArrayList since the data will be various types (int, floats, and strings) and I'll want to refer to the whole set by name.

However, in looking into ArrayLists I come upon scores of comments and such that are outright derisive of ArrayLists as being outmoded, outdated, or poor performance-wise.

Sadly, not one of them can actually be bothered to suggest what I should use instead that has the same functionality. I can only assume there's another data type I should be using, but I don't know what to look for so I can't find it.

My requirements include:

Must support multiple data types within the same container. Must be easy to reference an individual piece of data without having to pull apart the container with a custom function

My Wants:

I'd like the individual slots within the container to be strongly typed, so I don't have to cast the data out of it in code.

Ideally:

I'd like to be able to label these fields within the container and be able to reference the field via dot notation.

Container does not need to be dynamically sized, as the data is static and just referenced by the code elsewhere.

Any ideas?

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
1
Best Answer

Answer by jahroy · Dec 14, 2011 at 03:47 AM

It seems pretty clear to me that you want to use a class, not an ArrayList.

You say that you want your container to hold different types of objects.

Then you say you want the slots of your container to be strongly typed.

This either makes no sense, is a bad idea, or means you want to use a class.

Example:

var theBox : ToolBox;

function Start () { theBox = new ToolBox("Rick's Toolbox");

 theBox.position = new Vector3(3, 5, 23);

}

function Update () { / make the hammer get stronger and stronger every second! /

 theBox.nailTool.power = Time.time * Time.time;    

}

class ToolBox { var boxName : String = "Some Toolbox"; var position : Vector3 = Vector3(2, 3, 4);

 var screwTool  :  Screwdriver;
 var nailTool   :  Hammer;


 /* example constructor that takes one argument */

 function ToolBox ( someName : String )
 {
     boxName = someName;
 }

 /* simple example function */

 function showMyTools ()
 {
     Debug.Log("Tools in " + boxName);

     if ( screwTool != null ) {
         Debug.Log("I have a screw driver");
     }

     if ( nailTool != null ) {
         Debug.Log("I have a hammer");
     }
 }

}

/ another example class - even simpler /

class Hammer { var name : String = "Some Hammer"; var power : float = 2.0; }

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 IMoriarty · Dec 14, 2011 at 03:59 AM 0
Share

I'm gonna go with "D: All of the Above." I'll see what I can put together class wise and check back in a bit.

avatar image IMoriarty · Dec 14, 2011 at 04:32 AM 0
Share

I think I'll go with the class solution, which opens up my next issue - to be posted in another question. Thanks Jahroy.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

ArrayLists vs Generic Lists 1 Answer

Transfer ArrayList data into another script 1 Answer

Is it possible to use a custom object in java (my WeaponObject) as a data type (like Vector3) 1 Answer

Load Data from EditorWindow to Prefab 0 Answers

How to pass data from Unity Scene to Android Activity 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