Is there a way to get the selection in the order that a user selected it? I’m really hoping I don’t have to track selections with any callbacks. It’s 2017 after all! I did see some other threads on this but they’re old and didn’t really have any good solutions.
As a simple example, renaming a selection of objects like this will do it in some other order. So I’ll get objects renamed as newName001, newName000, newName003, newName002, even though they were selected in sequence.
GameObject[] objs = Selection.gameObjects;
for (int i = 0; i < objs.Length; i++) {
objs*.name = string.Concat("newName", i.ToString("000"));*
No, as far as i know the editor does not track any order of your selection. The selection can be done in various ways where the order is not necessarily given. Also adding and removing items from a selection would make it difficult even for the user to determine the correct behaviour. Also “Selection.gameObjects” is already a filtered list as it only returns gameobjects. However the selection could include other items such as folders or other assets (I’, talking mainly about the project view).
If you want to implement a mass rename feature it would be the best to use an editor window or a wizard which the user opens and then select the objects in the order you want. This also allows a visual feedback and the reordering of the items in the wizard / editor window.