static private void TryAutoAssign(SerializedProperty inProperty, ComponentLookupDirection inLookup) { Type componentType = inProperty.GetPropertyType(); Component c = (Component)inProperty.serializedObject.targetObject; Component val; switch (inLookup) { case ComponentLookupDirection.Self: default: val = c.GetComponent(componentType); break; case ComponentLookupDirection.Parent: val = c.GetComponentInParent(componentType); break; case ComponentLookupDirection.Children: val = c.GetComponentInChildren(componentType, true); break; } if (val) { inProperty.objectReferenceValue = val; } }
static public T GetComponent <T>(this GameObject inGameObject, ComponentLookupDirection inDirection, bool inbIncludeInactive = false) { switch (inDirection) { case ComponentLookupDirection.Self: return(inGameObject.GetComponent <T>()); case ComponentLookupDirection.Parent: return(inGameObject.GetComponentInParent <T>()); case ComponentLookupDirection.Children: return(inGameObject.GetComponentInChildren <T>(inbIncludeInactive)); default: throw new ArgumentOutOfRangeException("inDirection"); } }
/// <summary> /// Sets the component filter. /// </summary> public void FilterByComponent <T>(ComponentLookupDirection inLookup = ComponentLookupDirection.Self) { FilterByComponent(typeof(T), inLookup); }
/// <summary> /// Sets the component filter. /// </summary> public void FilterByComponent(Type inType, ComponentLookupDirection inLookup = ComponentLookupDirection.Self) { m_RequiredComponentType = inType; m_RequiredComponentLookup = inLookup; }
public RequiredAttribute(ComponentLookupDirection inAutoAssignDirection) { AutoAssignDirection = inAutoAssignDirection; }
static public T GetComponent <T>(this Component inComponent, ComponentLookupDirection inDirection, bool inbIncludeInactive = false) { return(GetComponent <T>(inComponent.gameObject, inDirection, inbIncludeInactive)); }
public void Clear() { ComponentType = null; LookupDirection = ComponentLookupDirection.Self; }
public void InChildren <T>() { ComponentType = typeof(T); LookupDirection = ComponentLookupDirection.Children; }
public void InParent <T>() { ComponentType = typeof(T); LookupDirection = ComponentLookupDirection.Parent; }
public void OnObject <T>() { ComponentType = typeof(T); LookupDirection = ComponentLookupDirection.Self; }