Skip to content

Instantly share code, notes, and snippets.

@geekrelief
Created March 7, 2017 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save geekrelief/a038a365b3b10a1b3e7ed9b48e4cdb81 to your computer and use it in GitHub Desktop.
Save geekrelief/a038a365b3b10a1b3e7ed9b48e4cdb81 to your computer and use it in GitHub Desktop.
// using System.Collections.Generic;
// using UnityEngine;
// using UnityEditor;
// for ordered selection
HashSet<GameObject> selectionSet = new HashSet<GameObject>();
HashSet<GameObject> newSet = new HashSet<GameObject>();
HashSet<GameObject> deleteSet = new HashSet<GameObject>();
List<GameObject> selectionOrdered = new List<GameObject>();
private void OnSelectionChange()
{
newSet.Clear();
newSet.UnionWith(Selection.gameObjects);
deleteSet.Clear();
deleteSet.UnionWith(selectionSet);
deleteSet.ExceptWith(newSet);
foreach (var g in deleteSet)
{
selectionSet.Remove(g);
selectionOrdered.Remove(g);
}
newSet.ExceptWith(selectionSet);
foreach (var g in newSet)
{
selectionSet.Add(g);
selectionOrdered.Add(g);
}
for (var i = 0; i < selectionOrdered.Count; ++i)
{
Debug.Log(i + " " + selectionOrdered[i].name);
}
}
@geekrelief
Copy link
Author

for getting the order of selections in Unity's hierarchy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment