Beispiel #1
0
    private object[] GetComponentsToReference(MonoBehaviour mb, GameObject go, Type componentType)
    {
        Type listElementType = AutoUtils.GetElementType(componentType);

        MethodInfo method = typeof(GameObject).GetMethods()
                            .First(m =>
        {
            bool result = true;
            result      = result && m.Name == GetMethodName();
            result      = result && m.IsGenericMethod;
            result      = result && m.GetParameters().Length == 1;
            result      = result && m.GetParameters()[0].ParameterType == typeof(bool);
            return(result);
        });
        //we want to pass true as arg, to get from inactive objs too
        MethodInfo generic = method.MakeGenericMethod(listElementType);

        object[] componentsToReference = generic.Invoke(go, new object[] { true }) as object[];

        return(componentsToReference);
    }
Beispiel #2
0
    private void MultipleComponentAssignment(MonoBehaviour mb, GameObject go, Type componentType, Action <MonoBehaviour, object> SetVariable)
    {
        Type listElementType = AutoUtils.GetElementType(componentType);

        MethodInfo method = typeof(GameObject).GetMethods()
                            .First(m =>
        {
            bool result = true;
            result      = result && m.Name == GetMethodName();
            result      = result && m.IsGenericMethod;
            result      = result && m.GetParameters().Length == 1;
            result      = result && m.GetParameters()[0].ParameterType == typeof(bool);
            return(result);
        });
        //we want to pass true as arg, to get from inactive objs too
        MethodInfo generic = method.MakeGenericMethod(listElementType);
        dynamic    componentsToReference = generic.Invoke(go, new object[] { true });

        if (componentsToReference.Length == 0)
        {
            if (logErrorIfMissing)
            {
                Debug.LogError(
                    string.Format("[Auto]: <color={3}><b>{1}</b></color> couldn't find any components <color=#cc3300><b>{0}</b></color> on <color=#e68a00>{2}.</color>",
                                  componentType.Name, mb.GetType().Name, go.name, MonoBehaviourNameColor)
                    , go);
            }
            return;
        }

        if (componentType.IsArray)
        {
            SetVariable(mb, componentsToReference);
        }
        else if (Rhm.IsList(componentType))
        {
            SetVariable(mb, Enumerable.ToList(componentsToReference));
        }
    }