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
1
Question by bateras · Dec 20, 2011 at 09:56 AM · arrayimageloaddynamicfolder

How do i load entire folders into arrays?

I've seen this already asked but i've not seen any useful or working answer to my problem so i've gotta ask it in a little bit specific way.

I've got several folders, loaded with images. By now all those images in one of them have the same name and a number. the usual way now would be run through their numbers, but i've been asked to do it counting with they could have different names.

anyway, by now, this is my folder

http://i304.photobucket.com/albums/nn200/bateras/img1.jpg

From my script, i need to load an array with those images for each folder, which means i need to have 3 "catX" arrays with their respective images, which means i need to check what's inside "ImagenesGaleria", inside "Editor"

and i can't do it. I've tried with "Resources.loadAll" and nothing happened.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Rabwin · Dec 20, 2011 at 10:33 AM

why do you have your images stored under the folder Editor? I believe that is usually used by Unity for other purposes.

If you want to use Resources.Load, I believe you have to create a folder called Resources and place your images under that directory, for example "Resources/ImagenesGaleria/Catx"

Then you would use Resources.Loadall with that particular directory. OR If you know the names of the files, I guess you can use Resources.Load and manually add them to the array with a simple loop structure.

Edit: Making a change to add some code according to comments to try and explain how I would separate the "folders" for your system. This code is in C#. Showing you the struct I define, and the start function using the method I describe in the comments.

 public struct NumAndImages
 {
     uint x;
     Texture2D[] texArray;
 
     public uint X
     {
         get
         {
             return x;
         }
         set
         {
             x = value;
         }
     }
 
     public Texture2D[] aTexture
     {
         get
         {
             return texArray;
         }
         set
         {
             texArray = value;
         }
     }
 }
 
 void Start()
 {
     ArrayList textureArrays = new ArrayList();
     bool noImage = false;
     uint counter = 0;
     while(!noImage)
     {
         NumAndImages NAI;
         NAI.X = counter;
         NAI.aTexture = Resources.LoadAll("ImagenesGaleria/Cat" + counter);
         if(NAI.aTexture == null)
         {
             noImage = true;
             print("Found up to Cat" + counter-1 + ". No more images to load");
         }
         else
         {
             textureArrays.Add(NAI);
         }
     }
 
     //how many catx do I have
     int howmany = textureArrays.Count;
 
     //Load an image from the first catx
     NumAndImages NAI = textureArrays[0];
     Texture2D image = NAI.aTexture[0];
 
     //load the last image in the last catx
     NumAndImages NAI = textureArrays[textureArrays.Count];
     Texture2D image = NAI.aTexture[NAI.aTexture.Length];
 
 
 }
Comment
Add comment · Show 7 · 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 bateras · Dec 20, 2011 at 10:50 AM 0
Share

I've used Editor because my last try was with "AssetDatabase.LoadAllAssetsAtPath". I've just thought... i tried with "resources" yesterday... but i think i hadn't writen Shift r in "Resources"... let me try again :s i'll tell you shortly

avatar image bateras · Dec 20, 2011 at 10:59 AM 0
Share

allright, i'm such an ass... it was that f....ng "R" i wrote yesterday "r". so Resources.Loadall("ImagenesGaleria") really works. is there a way to separate all pictures from different subdirectories?

Is there any way of getting the path where those images were once you've loaded them?

avatar image Rabwin · Dec 20, 2011 at 01:47 PM 0
Share

I'm not sure how to do that, other than hard coding it in which is fine because when you build the executable, Unity will take care of that stuff. But the problem is that it seems like you have many files you want to store in arrays.

The reason I believe unity doesn't give you a directory for loaded images, is because when you make a build, all your resources (scripts, models, textures, etc) will get placed into a single file database. Have a look for yourself, I think it's called resources.assets.

Why would you need the directory anyway? If you're trying to get another object to load those textures/images, just pass the image you cached in the current object holding the array, it's much faster.

avatar image bateras · Dec 20, 2011 at 02:20 PM 0
Share

this project is some kind of image viewer mixed with a catalog using TUIO. Each folder "CatX" stores different images; it's a subcatalogue. several buttons are created according to folder number the main idea is that you hit the button created for Cat1 [which shows the first image in its array] and you have it loaded in the viewer. the viewer has next and previous buttons and you change through elements in the array. those images are shown in a pane [or thin cube] and you can use touchable surface to make it bigger and smaller.

avatar image Rabwin · Dec 20, 2011 at 02:41 PM 0
Share

Why not hardcode the directories to those resources then? Resources.Load doesn't throw an error if you try to load something that doens't exist, the object simply remains null. You can use a looping structure to check if an image was loaded in catx.

If you only have up to cat3 and tried to load an image from cat4(who doesn't exist), the texture array would have nothing loaded and would remain null, so you can use an if statement to check if the array is null, then ter$$anonymous$$ate the loop since theres no more images to grab.

Sorry, I'm finding it a bit hard to understand exactly what you are trying to do.

Edit: Okay I might understand now. $$anonymous$$aybe you can use a custom struct which contains 1. a string 2. a Texture2D[] (an array of Texture2D) Using a looping structure, you check which catx you are up to and create a new struct and set the string to whichever x you're up to (on second thought, it might be better to use an unsigned short to store the directory ins$$anonymous$$d, which uses less memory) This way, your struct contains an array of images from catx, and it also knows which catx those images came from. You will store all these structs in an ArrayList.

If this is what you wanted, let me know and i'll update my answer with some example code.

Show more comments
avatar image
0

Answer by jahroy · Dec 20, 2011 at 05:23 PM

Check out both of these:

  • Unity's AssetDatabase functions

  • .Net's FileSystemInfo library

Comment
Add comment · Show 1 · 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 bateras · Dec 21, 2011 at 08:49 AM 0
Share

hey thanks a lot for your answer, I'm gonna try it now if it works, i'll let you know asap.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

non-dynamic asset load? 1 Answer

load images in sequence into a gui? 2 Answers

Best way to speed up loading texture from file 0 Answers

Loading image for inventory from calculated path 0 Answers

Loading with ArrayPrefs 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