Search Unity

Drag&drop to populate a script's array in the inspector?

Discussion in 'Editor & General Support' started by bigkahuna, Dec 18, 2011.

  1. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Seems like it should be possible but I just can't find an easy way to do this:

    I have a script that has an variable that is an array of textures. I want to be able to drag and drop a list of textures from the Project window into the array variable in the Inspector. The textures are labeled sequentially xxx001, xxx002, etc. How do I do this? I tried highlighting the list in the Project windows and just dropping it into the array slot in the inspector but all that happens is the last texture in the list is added. I'm thinking there is a key combination to let me do this but for the life of me I can't find it.
     
    elenzil likes this.
  2. UnknownProfile

    UnknownProfile

    Joined:
    Jan 17, 2009
    Posts:
    2,311
    This would be so useful to have. Unfortunately, though, there is no native way to do this in Unity :(. I've heard that you would have to write an editor script for this.
     
  3. BlackSpider

    BlackSpider

    Joined:
    Oct 8, 2011
    Posts:
    50
    if I'm correct you can select the GameObject with the array attached. and lock the inspector window. Then in the Project menu Select all your textures and drag them in the array variable. This is how i load my array's with loads of objects.
     
    TheGering likes this.
  4. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Well that idea comes close to working. Except that instead of adding the textures like this: xxx000, xxx001, xxx002, etc. from the top it loaded them from the middle, to the end and then from the beginning like this: xxx088, xxx089, xxx090, xxx000, xxx001, etc. Is BlackSpider's method supposed to work? If so I'll post a bug report. I'm using 3.4.2 Pro for Windows.
     
  5. BlackSpider

    BlackSpider

    Joined:
    Oct 8, 2011
    Posts:
    50
    You can also make a function to Sort the array. But i think you have to do it in the editor trough editor script. also it has to be a List because i don't think Array's have a sort function.
     
  6. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I've got a couple ideas on how to do this in code, but I thought that something this common and simple had to have a keystroke / mouse click combination to accomplish in the editor. I think your first idea might work if I use smaller groups of assets, say 20 or so at a time.