Пример #1
0
        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;
            }
        }
Пример #2
0
        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");
            }
        }
Пример #3
0
 /// <summary>
 /// Sets the component filter.
 /// </summary>
 public void FilterByComponent <T>(ComponentLookupDirection inLookup = ComponentLookupDirection.Self)
 {
     FilterByComponent(typeof(T), inLookup);
 }
Пример #4
0
 /// <summary>
 /// Sets the component filter.
 /// </summary>
 public void FilterByComponent(Type inType, ComponentLookupDirection inLookup = ComponentLookupDirection.Self)
 {
     m_RequiredComponentType   = inType;
     m_RequiredComponentLookup = inLookup;
 }
Пример #5
0
 public RequiredAttribute(ComponentLookupDirection inAutoAssignDirection)
 {
     AutoAssignDirection = inAutoAssignDirection;
 }
Пример #6
0
 static public T GetComponent <T>(this Component inComponent, ComponentLookupDirection inDirection, bool inbIncludeInactive = false)
 {
     return(GetComponent <T>(inComponent.gameObject, inDirection, inbIncludeInactive));
 }
Пример #7
0
 public void Clear()
 {
     ComponentType   = null;
     LookupDirection = ComponentLookupDirection.Self;
 }
Пример #8
0
 public void InChildren <T>()
 {
     ComponentType   = typeof(T);
     LookupDirection = ComponentLookupDirection.Children;
 }
Пример #9
0
 public void InParent <T>()
 {
     ComponentType   = typeof(T);
     LookupDirection = ComponentLookupDirection.Parent;
 }
Пример #10
0
 public void OnObject <T>()
 {
     ComponentType   = typeof(T);
     LookupDirection = ComponentLookupDirection.Self;
 }