public static T[] FindAll <T>(SearchBy search, string query) where T : class { switch (search) { case SearchBy.Nothing: return(ArrayUtil.Empty <T>()); case SearchBy.Tag: { using (var tmp = com.spacepuppy.Collections.TempCollection.GetList <UnityEngine.GameObject>()) using (var results = com.spacepuppy.Collections.TempCollection.GetList <T>()) { GameObjectUtil.FindGameObjectsWithMultiTag(query, tmp); var e = tmp.GetEnumerator(); while (e.MoveNext()) { var o = ObjUtil.GetAsFromSource <T>(e.Current); if (o != null) { results.Add(o); } } return(results.ToArray()); } } case SearchBy.Name: { using (var tmp = com.spacepuppy.Collections.TempCollection.GetList <UnityEngine.GameObject>()) using (var results = com.spacepuppy.Collections.TempCollection.GetList <T>()) { GameObjectUtil.FindAllByName(query, tmp); var e = tmp.GetEnumerator(); while (e.MoveNext()) { var o = ObjUtil.GetAsFromSource <T>(e.Current); if (o != null) { results.Add(o); } } return(results.ToArray()); } } case SearchBy.Type: { using (var results = com.spacepuppy.Collections.TempCollection.GetList <T>()) { foreach (var o in UnityEngine.Object.FindObjectsOfType(TypeUtil.FindType(query))) { var o2 = ObjUtil.GetAsFromSource <T>(o); if (o2 != null) { results.Add(o2); } } return(results.ToArray()); } } default: return(null); } }
private System.Collections.IEnumerable ReduceTargets(object triggerArg) { switch (_find) { case FindCommand.Direct: { object obj = (_configured) ? _target : triggerArg; if (obj == null) { yield break; } switch (_resolveBy) { case ResolveByCommand.Nothing: yield return(obj); break; case ResolveByCommand.WithTag: { var go = GameObjectUtil.GetGameObjectFromSource(obj); if (go.HasTag(_queryString)) { yield return(obj); } } break; case ResolveByCommand.WithName: { var go = GameObjectUtil.GetGameObjectFromSource(obj); if (go.CompareName(_queryString)) { yield return(obj); } } break; case ResolveByCommand.WithType: { var o = ObjUtil.GetAsFromSource(TypeUtil.FindType(_queryString), GameObjectUtil.GetGameObjectFromSource(obj)); if (o != null) { yield return(o); } } break; } } break; case FindCommand.FindParent: { Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? _target : triggerArg); if (trans == null) { yield break; } switch (_resolveBy) { case ResolveByCommand.Nothing: { var t = trans.parent; if (t != null) { yield return(t); } } break; case ResolveByCommand.WithTag: { foreach (var p in GameObjectUtil.GetParents(trans)) { if (p.HasTag(_queryString)) { yield return(p); } } } break; case ResolveByCommand.WithName: { foreach (var p in GameObjectUtil.GetParents(trans)) { if (p.CompareName(_queryString)) { yield return(p); } } } break; case ResolveByCommand.WithType: { var tp = TypeUtil.FindType(_queryString); foreach (var p in GameObjectUtil.GetParents(trans)) { var o = ObjUtil.GetAsFromSource(tp, p); if (o != null) { yield return(o); } } } break; } } break; case FindCommand.FindInChildren: { Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? _target : triggerArg); if (trans == null) { yield break; } switch (_resolveBy) { case ResolveByCommand.Nothing: if (trans.childCount > 0) { yield return(trans.GetChild(0)); } break; case ResolveByCommand.WithTag: if (trans.childCount > 0) { using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildren(trans, lst); for (int i = 0; i < lst.Count; i++) { if (lst[i].HasTag(_queryString)) { yield return(lst[i]); } } } } break; case ResolveByCommand.WithName: if (trans.childCount > 0) { using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildren(trans, lst); for (int i = 0; i < lst.Count; i++) { if (lst[i].CompareName(_queryString)) { yield return(lst[i]); } } } } break; case ResolveByCommand.WithType: if (trans.childCount > 0) { var tp = TypeUtil.FindType(_queryString); using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildren(trans, lst); for (int i = 0; i < lst.Count; i++) { var o = ObjUtil.GetAsFromSource(tp, lst[i]); if (o != null) { yield return(o); } } } } break; } } break; case FindCommand.FindInEntity: { GameObject entity = GameObjectUtil.GetRootFromSource((_configured) ? _target : triggerArg); if (entity == null) { yield break; } ; switch (_resolveBy) { case ResolveByCommand.Nothing: yield return(entity); break; case ResolveByCommand.WithTag: { foreach (var o in entity.FindAllWithMultiTag(_queryString)) { yield return(o); } } break; case ResolveByCommand.WithName: { foreach (var o in GameObjectUtil.FindAllByName(entity.transform, _queryString)) { yield return(o); } } break; case ResolveByCommand.WithType: { var tp = TypeUtil.FindType(_queryString); using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildrenAndSelf(entity.transform, lst); for (int i = 0; i < lst.Count; i++) { var o = ObjUtil.GetAsFromSource(tp, lst[i]); if (o != null) { yield return(o); } } } } break; } } break; case FindCommand.FindInScene: { switch (_resolveBy) { case ResolveByCommand.Nothing: { var go = GameObjectUtil.GetGameObjectFromSource((_configured) ? _target : triggerArg); if (go != null) { yield return(go); } } break; case ResolveByCommand.WithTag: { foreach (var o in GameObjectUtil.FindGameObjectsWithMultiTag(_queryString)) { yield return(o); } } break; case ResolveByCommand.WithName: { foreach (var o in GameObjectUtil.FindAllByName(_queryString)) { yield return(o); } } break; case ResolveByCommand.WithType: { foreach (var o in ObjUtil.FindAll(SearchBy.Type, _queryString)) { yield return(o); } } break; } } break; case FindCommand.FindEntityInScene: { switch (_resolveBy) { case ResolveByCommand.Nothing: { var go = GameObjectUtil.GetGameObjectFromSource((_configured) ? _target : triggerArg); if (go != null) { yield return(go); } } break; case ResolveByCommand.WithTag: { var e = SPEntity.Pool.GetEnumerator(); while (e.MoveNext()) { if (e.Current.HasTag(_queryString)) { yield return(e.Current); } } } break; case ResolveByCommand.WithName: { var e = SPEntity.Pool.GetEnumerator(); while (e.MoveNext()) { if (e.Current.CompareName(_queryString)) { yield return(e.Current); } } } break; case ResolveByCommand.WithType: { var e = SPEntity.Pool.GetEnumerator(); var tp = TypeUtil.FindType(_queryString); while (e.MoveNext()) { var o = e.Current.GetComponent(tp); if (o != null) { yield return(o); } } } break; } } break; } }
private System.Collections.IEnumerable ReduceTargets(object triggerArg) { switch (_find) { case FindCommand.Direct: { object obj = (_configured) ? _target : triggerArg; if (obj == null) { yield break; } switch (_resolveBy) { case ResolveByCommand.Nothing: yield return(obj); break; case ResolveByCommand.WithTag: { var go = GameObjectUtil.GetGameObjectFromSource(obj); if (go.HasTag(_queryString)) { yield return(obj); } } break; case ResolveByCommand.WithName: { var go = GameObjectUtil.GetGameObjectFromSource(obj); if (go.CompareName(_queryString)) { yield return(obj); } } break; case ResolveByCommand.WithType: { if (ObjUtil.GetAsFromSource(TypeUtil.FindType(_queryString), GameObjectUtil.GetGameObjectFromSource(obj)) != null) { yield return(obj); } } break; } } break; case FindCommand.FindParent: { Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? _target : triggerArg); if (trans == null) { yield break; } switch (_resolveBy) { case ResolveByCommand.Nothing: { var t = trans.parent; if (t != null) { yield return(t); } } break; case ResolveByCommand.WithTag: { foreach (var p in GameObjectUtil.GetParents(trans)) { if (p.HasTag(_queryString)) { yield return(p); } } } break; case ResolveByCommand.WithName: { foreach (var p in GameObjectUtil.GetParents(trans)) { if (p.CompareName(_queryString)) { yield return(p); } } } break; case ResolveByCommand.WithType: { var tp = TypeUtil.FindType(_queryString); foreach (var p in GameObjectUtil.GetParents(trans)) { if (ObjUtil.GetAsFromSource(tp, p) != null) { yield return(p); } } } break; } } break; case FindCommand.FindInChildren: { Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? _target : triggerArg); if (trans == null) { yield break; } switch (_resolveBy) { case ResolveByCommand.Nothing: if (trans.childCount > 0) { yield return(trans.GetChild(0)); } break; case ResolveByCommand.WithTag: if (trans.childCount > 0) { foreach (Transform child in GameObjectUtil.GetAllChildren(trans)) { if (child.HasTag(_queryString)) { yield return(child); } } } break; case ResolveByCommand.WithName: if (trans.childCount > 0) { foreach (Transform child in GameObjectUtil.GetAllChildren(trans)) { if (child.CompareName(_queryString)) { yield return(child); } } } break; case ResolveByCommand.WithType: if (trans.childCount > 0) { var tp = TypeUtil.FindType(_queryString); foreach (Transform child in GameObjectUtil.GetAllChildren(trans)) { if (ObjUtil.GetAsFromSource(tp, child) != null) { yield return(child); } } } break; } } break; case FindCommand.FindInEntity: { GameObject entity = GameObjectUtil.GetRootFromSource((_configured) ? _target : triggerArg); if (entity == null) { yield break; } ; switch (_resolveBy) { case ResolveByCommand.Nothing: yield return(entity); break; case ResolveByCommand.WithTag: { foreach (var o in entity.FindAllWithMultiTag(_queryString)) { yield return(o); } } break; case ResolveByCommand.WithName: { foreach (var o in GameObjectUtil.FindAllByName(entity.transform, _queryString)) { yield return(o); } } break; case ResolveByCommand.WithType: { var tp = TypeUtil.FindType(_queryString); foreach (var t in GameObjectUtil.GetAllChildrenAndSelf(entity)) { if (ObjUtil.GetAsFromSource(tp, t) != null) { yield return(t); } } } break; } } break; case FindCommand.FindInScene: { switch (_resolveBy) { case ResolveByCommand.Nothing: { var go = GameObjectUtil.GetGameObjectFromSource((_configured) ? _target : triggerArg); if (go != null) { yield return(go); } } break; case ResolveByCommand.WithTag: { foreach (var o in GameObjectUtil.FindGameObjectsWithMultiTag(_queryString)) { yield return(o); } } break; case ResolveByCommand.WithName: { foreach (var o in GameObjectUtil.FindAllByName(_queryString)) { yield return(o); } } break; case ResolveByCommand.WithType: { foreach (var o in ObjUtil.FindAll(SearchBy.Type, _queryString)) { yield return(o); } } break; } } break; } }