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 rodrigozol · Nov 21, 2014 at 05:18 PM · texturearraywww

Load textures from external path, without change their names.

I've read some post about load texture using WWW(url), like this one:

http://answers.unity3d.com/questions/813495/can-i-load-textures-outside-the-resources-folder.html.

I was wondering if it is possible to load the textures/images without change their names(the post suggest to use a sequencial names) ? If there any function that can read how many images are in the external path and then create an array or list?

Thanks all

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

Answer by Pawscal · Nov 21, 2014 at 05:44 PM

There is a coupple of solutions availaible to you if you want to load images dynamically whatever the name of the images are.

We have done this on many of our projects.

The easiest way would be to use something like this:

 using UnityEngine;
 using System.IO;
 using System.Collections.Generic;
 using System.Collections;
 
 public class MyClass : MonoBehaviour {
 
     public string _imageFolderPath = @"C:\My\Image\Path";
     List<Texture2D> _projectImages = new List<Texture2D>();
 
 
     IEnumerator BatchLoadImages()
     {
         if(Directory.Exists(_imageFolderPath))
         {
             // Make sure your list is empty your list
             _projectImages.Clear();
             //get path for all .jpg files in directory and subDirectories.
             string[] dirPaths = Directory.GetFiles(_imageFolderPath,"*.jpg" ,SearchOption.AllDirectories); 
             if(dirPaths.Length>0)
             {
                 //load each images
                 foreach (string path in dirPaths)
                 {
                     string url = "";
                     // look if the path is an url or a local path
                     if(path.Contains("http:"))
                     {
                         url = path;
                     }
                     else
                     {
                         url = "file://" + path;
                     }
                     // Create an empty texture
                     Texture2D newTexture = new Texture2D (512,512,TextureFormat.ARGB32,true);
                     // loads the image
                     WWW www = new WWW (url);
                     yield return www;
                     // Load it into a Texture2D
                     www.LoadImageIntoTexture (newTexture);
                     //add texture to the list.
                     _projectImages.Add(newTexture);
                 }
             }
         }
         else
         {
             Debug.LogWarning("The Image loading path does not exist");
         }
     }
 }
 

this would return an array of texture2D you could then use to suits your needs.

If you need something more robust with more infos that just an image path, you can use a data base that generates an XML file that will hold all the info you need about each images you want to load , parse it in Unity and use the data to load your images.

Hope it helps, tell me if you need more details

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 rodrigozol · Nov 22, 2014 at 05:50 PM 0
Share

Tks Pawscal, works great!

avatar image Pawscal · Apr 27, 2015 at 07:47 PM 0
Share

Glad i could help :)

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

27 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

Related Questions

Exception: not implemented? 2 Answers

Assigning Texture using WWW into Texture Array? 1 Answer

Image loaded with LoadImageIntoTexture gets inverted 0 Answers

Host Image/Texture using Unity server, then request it using WWW on client 0 Answers

Using WWW in public method of a GameObject in Unity C# 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