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 panoramabeats · Feb 18, 2019 at 01:41 AM · c#texturearraytexture2d

How to load a folder of textures automatically to an array of Raw Images?

edit: preferably in C#

I’m trying to load multiple images from a folder, non-specifically, so that no matter what the contents are, it automatically populates into the images in the scene.

Currently, I’m using a script that allows an image to be inserted from the inspector, via a public Texture. See Image Class script attached.

For the purposes of my app, I’d like it to take any folder and assign the images to a series of Raw Image objects within a single Canvas object.

I’ve been messing around with sort array/manager script but can’t seem to figure anything out. Does anyone have any idea for how to achieve this?

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class ImageClass : MonoBehaviour {

 public GameObject ImageOnPanel;  ///set this in the inspector
 public Texture NewTexture;


 private RawImage img;

 void Start () {
     img = (RawImage)ImageOnPanel.GetComponent<RawImage>();
     img.texture = (Texture)NewTexture;

 }


 // Update is called once per frame
 void Update () {

 }

}

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
0

Answer by xxmariofer · Feb 18, 2019 at 09:32 AM

first you need to access the folder with the textures, you can use for example application.datapath for that or whaatever folder like streaming assets or persistent data path. i will share with your a code i used once for creating textures that were downloaded at runtime, tell me if you need any explnation

     for (int i = 0; i < desserts.paths.GetLength(0) - 1; i++)//iterate over the textures
     {
         Texture2D texture = new Texture2D(1, 1); //generates a texture with that dimension

         WWW www = new WWW("file://" + exportPath + "/" + desserts.paths[i]);//i am using www since it is an android project and textures were saved into jar

         while (!www.isDone)
         {
             yield return new WaitForSeconds(0.1f);//waits untill it is done thge download of the textre
         }

         www.LoadImageIntoTexture(texture); //www method for loading texture

         listOfSprites.Add(Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f)); //generate a sprite and add it, you dont need this if you are only usnig textures. just added ot amy list of sprites.
     }
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
avatar image
0

Answer by panoramabeats · Feb 20, 2019 at 02:25 AM

Hey, Thank you so much for your answer. I'm sure this gets me on the right track. - How did you assign the variable exportPath? This is the name of the folder? Does 'file://' go to the root folder on Android? I'm assuming that's the jar or 'exportPath' is the string to the directory? maybe - sorry I'm novice at programming. I wish I could follow - An explanation would be nice but I may be too much noob anyway.

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 xxmariofer · Feb 20, 2019 at 10:52 AM 0
Share

hello, go step by step, first try it going first in the editor using application.datapath. but my export path is the path to the persistentdata path. you should check whats the best option for you, persistentdatapath strea$$anonymous$$gassets datapath etc... here is how i got the exportPath value

     string applicationPath;
     if (Application.platform == RuntimePlatform.Android)
     {
         applicationPath = Application.persistentDataPath;
     }
     else
     {
         applicationPath = Application.dataPath;
     }
     importPath = applicationPath + "/download.zip";
     exportPath = applicationPath + "/DownloadFile";

the path points to a folder called DownloadFile in the persistentDataPath in android and dataPath in windows(i did this just for testing) are you targeting android?

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

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

Unity WebCamTexture looks squashed in RawImage 0 Answers

Texture file is all alpha when resizing 0 Answers

Better way to edit RawImage texture data?,Better way to edit a RawImage texture? 0 Answers

Textures from a texture atalas turning black in the distance 0 Answers

Texture2D to Plane: Array Index is Out of Range 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