|
My component has an array property for an ordered list of other GameObjects that it will work with. When I need to change the order of those game objects, it's a bit of a pain. In the worst case, moving the last one to the first slot, I need to reset every single element. Is there some other way of doing it? It'd be slick if I could drag elements around in the list, but that doesn't seem to work.
(comments are locked)
|
|
You might try using a List instead. IIRC, the inspector interface for List reflects that its interface is substantially different from that of an array (for example, I believe you can delete items in the list freely without affecting the values of other items). This still won't allow you to drag items around as you describe, but it might be an improvement over what you have currently. Another option might be to create a custom inspector or editor window that facilitated whatever operations you might need to perform. For example, you could create an editor window where you can select items in the list and then click 'up' or 'down' buttons to move them up or down in the list. (I've used this method myself, and it worked fine.) Maybe someone else will be able to off a better suggestion though. My suggestion is to request it. http://feedback.unity3d.com/
Oct 31 '10 at 05:31 PM
Jessy
List seemed to do the same thing as an array, but it turned out it wasn't a big deal to write a custom editor for this one case. It came out looking like this: http://www.pasteit4me.com/1473001 I don't suppose it's possible to do make Unity use a custom editor on all arrays all over the place, is it?
Oct 31 '10 at 08:35 PM
ExciteMike
Hey Jesse Anders, I know this post is quite old, but I've been trying to do this exact thing for days now and can't figure it out. Your solution is exactly what I've been trying to do. You mention you've done it with the buttons for up and down before. How did you get which item is selected? or how did you display the array contents for that matter?
Jan 31 '12 at 10:26 PM
Adsy
@ExciteMike do you still have that code?
Nov 13 '12 at 02:49 PM
sebas77
I'm pretty sure I still have it... but I can't remember which project I was working on at the time, which makes it really hard to find :/
Nov 13 '12 at 03:49 PM
ExciteMike
(comments are locked)
|
|
Actually, Ctrl-D works on Windows, but Ctrl-Backspace doesn't. Does Ctrl-Delete work on Windows?
Dec 18 '11 at 10:27 PM
Michael Ryan
Use Shift-Delete to delete on Windows (Using 3.5 beta).
Jan 14 '12 at 04:40 PM
centaurianmudpig
(comments are locked)
|
|
As far as moving the last one to the first slot, you can duplicate the first slot, change the value of the duplicate, and delete the last slot. You don't need a List for that; it works fine with an array. Depends how simple the "value" is. I have arrays of big complicated structs, and they're nested (so CustomEditor can't really help). Time to write the array reordering window suggested above.
Jun 02 '11 at 01:09 AM
Waz
Ugh. Done, but it's so ugly, and SerializedProperty is so under-documented and full of gotchas, that I'm not going to post it anywhere.
Jun 02 '11 at 02:22 AM
Waz
(comments are locked)
|
|
The way I approach this issue is by following a rule that all variables in scripts must get initialized with Editor scripts. If I need to change the order of an array, I change the code that initialized the array and run the editor script again. Our last project had about 10-20 minutes worth of linking that needed to be done when a new Maya Scene was imported. Things are going much better in this project, where everything is initialized by a single ScriptableWizard.
(comments are locked)
|
|
While there is no easy way to move elements around, you are able to duplicate existing array items and remove elements from the array using some shortcut keys. From the Unify Community wiki:
(comments are locked)
|

i never understood why they didn't replicate the Script Execution Order editor for arrays in the inspector. DragDrop reordering thanks!