Created
March 7, 2017 21:04
-
-
Save geekrelief/a038a365b3b10a1b3e7ed9b48e4cdb81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for getting the order of selections in Unity's hierarchy.