private static void GetComponentsInternal <TComponent, TStopComponent, TResult>(Transform transform, bool includeInactive, EComponentSearchOption searchOption, List <TResult> result) where TComponent : Component, TResult where TStopComponent : Component { int count = transform.childCount; for (int i = 0; i < count; ++i) { Transform child = transform.GetChild(i); if (!child.gameObject.activeSelf && !includeInactive) { continue; } if (GetComponentsInternalSelf <TComponent, TStopComponent, TResult>(child, searchOption, result)) { GetComponentsInternal <TComponent, TStopComponent, TResult>(child, includeInactive, searchOption, result); } } }
private static bool GetComponentsInternalSelf <TComponent, TResult>(Transform transform, EComponentSearchOption searchOption, Component stopTarget, List <TResult> result, bool isThis = false) where TComponent : Component, TResult { bool findTargets = true; bool containsStopTarget = false; if (stopTarget != null) { if (isThis) { findTargets = ((searchOption & EComponentSearchOption.IncludeTargetComponent_InStop_This) != 0); } else { findTargets = ((searchOption & EComponentSearchOption.IncludeTargetComponent_InStop_Children) != 0); } containsStopTarget = true; } if (findTargets) { var targets = transform.GetComponents <TComponent>(); if (targets != null) { result.AddRange(targets); } } if (isThis && ((searchOption & EComponentSearchOption.SearchChildren_Ignore_SearchThisResult) != 0)) { return(true); } return(!containsStopTarget); }
private static bool GetComponentsInternalSelf <TComponent, TStopComponent, TResult>(Transform transform, EComponentSearchOption searchOption, List <TResult> result, bool isThis = false) where TComponent : Component, TResult where TStopComponent : Component { Component stopTarget = transform.GetComponent <TStopComponent>(); return(GetComponentsInternalSelf <TComponent, TResult>(transform, searchOption, stopTarget, result, isThis)); }
/// <summary> /// Get components in children (TTargetComponent, TStopComponent, TTargetComponentAsResult) /// </summary> /// <typeparam name="TComponent">The target component type</typeparam> /// <typeparam name="TStopComponent">The stop condition component type</typeparam> /// <param name="transform">start from here</param> /// <param name="includeInactive">include inactive gameObject</param> /// <param name="result">the result</param> public static void GetComponentsInChildren <TComponent, TStopComponent, TResult>(this Transform transform, bool includeInactive, EComponentSearchOption searchOption, List <TResult> result) where TComponent : Component, TResult where TStopComponent : Component { ProfilingUtility.BeginSample("GetComponentsInChildren_StopType_" + transform.name); bool continueToGet = true; if ((searchOption & EComponentSearchOption.SearchThis) != 0) { continueToGet = GetComponentsInternalSelf <TComponent, TStopComponent, TResult>(transform, searchOption, result, true); } if (continueToGet) { GetComponentsInternal <TComponent, TStopComponent, TResult>(transform, includeInactive, searchOption, result); } ProfilingUtility.EndSample(); }