Search Unity

Automatically adding a sequence of assets to an array

Discussion in 'Scripting' started by housewarmer, Aug 8, 2008.

  1. housewarmer

    housewarmer

    Joined:
    Apr 18, 2008
    Posts:
    74
    I'm trying to set up an image sequence as an array. I know how to add items to the array through the inspector, but for anything longer than a few frames it gets laborious. How would I go about telling the script to add all the files in the sequence automatically?

    Thanks!
    Mark
     
  2. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    What is your sequence of frames of exactly? Unity had a way to play animations based on a frame sequence in 1.x but, it seams that they got rid of that because you can now use movies in Unity Pro and they probably don't want anybody hacking they're way around that.

    Depending on what type of animation you're doing, there might be another way to accomplish it.

    For instance, I had a conveyor belt animation in one of my 1.x projects that was 30 frames long. Now I know that I can use 1 frame and just animate the offset of the texture instead.

    I'm no expert, but, I think if you want to play an animation of any great length, the only real way to go about it is to buy Pro and load it in as a movie.

    Maybe someone else can offer better insight.

    Hope this helps,
    Nathan
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could use Resources.Load and a bit of code, assuming you name the image sequence in a way that lends itself to that approach (frame01, frame02, etc.).

    --Eric
     
  4. Lucas Meijer_old

    Lucas Meijer_old

    Joined:
    Apr 5, 2008
    Posts:
    436
    What I do is use OnPostprocessAllAssets.
    For each folder that I find a file called "iwantanassetlisthere" in, my editor script creates an "assetlist", which is a scriptableobject.

    during onpostprocessallassets you can query the filesystem using standard .net api's. so that gives you a list of textures, (or animations, or whatever you want to use this technique for).

    the assetlist object then gets created right next to the iwantanassetlisthere file.

    In code where you want to use a sequence of images, you use a "public AssetList mytextures;", onto which you can drag your assetlist. the assetlist would have a properery .Textures, so you can get at your textures like that.

    It's more work than using Resources.Load, but is better from a runtime perspective, as Resources.Load requires your stuff to be loaded before the game starts. The asset list approach plays nice with unity's dependency tracking.

    I'm pretty sure I logged a feature request to allow something like:

    public Folder myAssets;

    so that you can drag a folder onto a monobehaviour's public variable.

    PS This technique gets annoying if you use the asset server, since you ideally do not want to version the assetlist, you would want to version the iwantanassetlist file. last time I checked the asset server didn't have a way of "not versioning" a specific file. I'm using a svn based versioning system these days, where I added *.assetlist as files always to ignore.

    Bye, Lucas
     
  5. Orion

    Orion

    Joined:
    Mar 31, 2008
    Posts:
    261
    Would be nice if you could share this script with us. I'm having trouble recreating it from scratch :(