コード例 #1
0
    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);
    }
コード例 #2
0
    /// <summary>
    /// Verifies a condition on the specified GameObject.
    /// </summary>
    /// <param name="gameObject">The GameObject on which to enforce a condition.</param>
    /// <returns>A List of FieldViolations that are present, or an empty list of no such violations were found.</returns>
    public List <FieldViolation> VerifyCondition(GameObject gameObject)
    {
        Asserter.NotNull(gameObject, "BaseConditionVerifier.VerifyConditions:gameObject is null");

        List <FieldViolation> fieldViolations = new List <FieldViolation>();

        foreach (MonoBehaviour component in gameObject.GetComponents <MonoBehaviour>())
        {
            if (!component)
            {
                continue;
            }
            List <MemberInfo> members = VerifierUtils.GetMembersWithAttribute(component, GetAttributeType);

            foreach (MemberInfo member in members)
            {
                FieldViolation[] fieldViolation;
                if (VerifyMember(component, member, VerifierUtils.GetAttributesOfType <T>(member), out fieldViolation))
                {
                    fieldViolations.AddRange(fieldViolation);
                }
            }
        }

        return(fieldViolations);
    }
コード例 #3
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);
    }
コード例 #4
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);
    }