Created
January 3, 2019 12:47
-
-
Save jeffvella/e7275f15fcba26498b66c836cbb383ba to your computer and use it in GitHub Desktop.
Invert the current Unity project / assets selection
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; | |
| using UnityEngine; | |
| using UnityEditor; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading.Tasks; | |
| using Object = UnityEngine.Object; | |
| public class InvertSelection : ScriptableWizard | |
| { | |
| [MenuItem("Assets/Selection/Invert", false, 50)] | |
| static void InvertAssetSelection() | |
| { | |
| EditorUtility.DisplayProgressBar("Inverting Selection", "Working...", 0); | |
| var oldSelection = Selection.GetFiltered(typeof(Object), SelectionMode.Assets).ToList(); | |
| var newSelection = new List<Object>(); | |
| var allAssets = AssetDatabase.FindAssets(string.Empty); | |
| for (var i = 0; i < allAssets.Length; i++) | |
| { | |
| var guid = allAssets[i]; | |
| var path = AssetDatabase.GUIDToAssetPath(guid); | |
| var asset = AssetDatabase.LoadAssetAtPath<Object>(path); | |
| if (!oldSelection.Contains(asset)) | |
| { | |
| newSelection.Add(asset); | |
| } | |
| var progress = (i / (float) allAssets.Length); | |
| EditorUtility.DisplayProgressBar("Inverting Selection", $"{progress*100f:N0}% Complete", progress); | |
| } | |
| Selection.objects = newSelection.ToArray(); | |
| EditorUtility.ClearProgressBar(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment