• 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 jtcrash · Mar 07, 2012 at 11:46 PM · transformobjectwwwdataproperties

Adding data to a set of transforms

Hello,

I have a blank gameobject that contains 70 some odd prefabs (generated at run-time). I want to be able to loop through the prefabs and add a WWW object which will be setting its texture as soon as the download completes, but I need to track which prefabs have have WWW objects that aren't isDone, so that I could dispose of the WWW object that is associated with that particular prefab. Here is an example of what I have/need (simplified):

 for(var child : Transform in transform){
     var txt = new Texture2D(tileSize, tileSize, TextureFormat.DXT1, false);
     var www = new WWW("urlgoeshere");
     yield www;
     www.LoadImageIntoTexture(txt);
     child.guiTexture.texture = txt;    
     child.newpropertynamehere = www; // THIS IS WHAT I NEED
 }

So that later I can do:

 for(var child : Transform in transform){
     if(!child.newpropertynamehere.isDone) child.newpropertynamehere.Dispose();
 }
 

Any help would be greatly appreciated!

Jake

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

Answer by FishBone · Mar 08, 2012 at 04:48 PM

Let every GameObject have a script that loads the textures and keeps the variables for isDone.

 var children : WWWLoader[] = GetComponentsInChildren<WWWLoader>();
 for (child : WWWLoader in children)
 {
    child.Load("urlgoeshere");
 }

so later you can do:

 for (child : WWWLoader in children)
 {
    if(!child.isDone) child.Dispose();
 }


the WWWLoader-class would look something like

 var isDone : boolean;
 function Load (url : string) {
     var txt = new Texture2D(tileSize, tileSize, TextureFormat.DXT1, false);
     var www = new WWW(url);
     yield www;
     www.LoadImageIntoTexture(txt);
     guiTexture.texture = txt; 
     isDone = true;
 }
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 jtcrash · Mar 08, 2012 at 07:21 PM 0
Share

Thanks for your help on this, I am new to unity and game development so I have to think a bit differently.

I figured it would involve applying a class to the tiles, should I drop this WWWLoader script on the guitexture that is inside the prefab? Or the prefab itself?

Also, does the child.Dispose(); dispose of the WWW object or does it dispose of the whole prefab?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

MissingReferenceException Help 1 Answer

How to manage an object using joints? 0 Answers

problem with wheelcollider 0 Answers

rotation of the object to a given angle 1 Answer

JSON Error : ArgumentException: JSON must represent an object type. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges