Last active
March 13, 2017 20:43
-
-
Save ahokinson/77e2556fcd404d3698a3654fb6bc04fd 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.Linq; | |
using UnityEditor; | |
using UnityEngine; | |
namespace Gubbins.Editor | |
{ | |
public class Selections | |
{ | |
[MenuItem("Tools/Gubbins/Selections/Objects with Missing Scripts")] | |
public static void SelectMissing() | |
{ | |
Selection.objects = Object.FindObjectsOfType<Transform>() | |
.Where(t => t.GetComponents<Component>() | |
.Any(c => c == null)) | |
.Select(t => t.gameObject as Object) | |
.ToArray(); | |
} | |
public static void SelectObjectsWith<T>() where T : Component | |
{ | |
Selection.objects = Object.FindObjectsOfType<Transform>() | |
.Where(t => t.GetComponent<T>() != null) | |
.Select(t => t.gameObject as Object) | |
.ToArray(); | |
} | |
[MenuItem("Tools/Gubbins/Selections/Objects with Selected Component")] | |
private static void SelectWithComponent() | |
{ | |
var ms = Selection.activeObject as MonoScript; | |
var type = ms.GetClass(); | |
if (!type.IsSubclassOf(typeof(Component))) return; | |
var method = typeof(Selections).GetMethod("SelectObjectsWith"); | |
var typeMethod = method.MakeGenericMethod(type); | |
typeMethod.Invoke(new Selections(), new object[] {}); | |
} | |
[MenuItem("Tools/Gubbins/Selections/Objects with Selected Component", true)] | |
private static bool ValidateSelectWithComponent() | |
{ | |
return Selection.objects.Length == 1 && Selection.activeObject is MonoScript; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment