private GameObject GetGameObjectOfMember(MonoBehaviour target, MemberInfo member)
    {
        if (member is FieldInfo)
        {
            object value = (member as FieldInfo).GetValue(target);
            if (!VerifierUtils.IsNull(value))
            {
                if (value is GameObject)
                {
                    return(value as GameObject);
                }
                else if (value is MonoBehaviour)
                {
                    return((value as MonoBehaviour).gameObject);
                }
            }
        }

        if (member is Type)
        {
            return(target.gameObject);
        }

        return(null);
    }
Exemple #2
0
    protected override bool VerifyMember(MonoBehaviour target, MemberInfo member, HasComponentAttribute[] attributes, out FieldViolation[] fieldViolation)
    {
        List <FieldViolation> fieldViolationsList = new List <FieldViolation>();

        if (!(member is FieldInfo))
        {
            fieldViolation = null;
            return(false);
        }

        object memberValue = (member as FieldInfo).GetValue(target);

        if (memberValue is GameObject)
        {
            GameObject gameObject = memberValue as GameObject;
            foreach (HasComponentAttribute attribute in attributes)
            {
                Type requiredComponentType = attribute.ComponentType;
                if (VerifierUtils.IsNull(gameObject))
                {
                    fieldViolationsList.Add(new FieldViolation(target.gameObject, null, target.name + "." + member.Name + ": Object referenced by field must have " + requiredComponentType + ", but is null."));
                    continue;
                }
                if (gameObject.GetComponent(requiredComponentType) == null)
                {
                    fieldViolationsList.Add(new FieldViolation(target.gameObject, gameObject, target.name + "." + member.Name + ": Object referenced by field must have " + requiredComponentType + ", but does not."));
                }
            }
        }
        else if (memberValue is MonoBehaviour)
        {
            MonoBehaviour component = memberValue as MonoBehaviour;
            foreach (HasComponentAttribute attribute in attributes)
            {
                Type requiredComponentType = attribute.ComponentType;
                if (VerifierUtils.IsNull(component))
                {
                    fieldViolationsList.Add(new FieldViolation(target.gameObject, null, target.name + "." + member.Name + ": Object referenced by field must have " + requiredComponentType + ", but is null."));
                    continue;
                }
                if (component.GetComponent(requiredComponentType) == null)
                {
                    fieldViolationsList.Add(new FieldViolation(target.gameObject, component, target.name + "." + member.Name + ": Object referenced by field must have " + requiredComponentType + ", but does not."));
                }
            }
        }

        fieldViolation = fieldViolationsList.ToArray();

        if (fieldViolation.Length > 0)
        {
            return(true);
        }
        return(false);
    }
Exemple #3
0
    protected override bool VerifyMember(MonoBehaviour target, MemberInfo member, NonNullAttribute[] attributes, out FieldViolation[] fieldViolation)
    {
        fieldViolation = null;
        if (member is FieldInfo)
        {
            object value = (member as FieldInfo).GetValue(target);
            if (VerifierUtils.IsNull(value))
            {
                fieldViolation = new FieldViolation[] { new FieldViolation(target.gameObject, null, target.name + "." + member.Name + ": Object referenced by field cannot be null.") };
                return(true);
            }
        }

        return(false);
    }