コード例 #1
0
    public static bool CompareArrays(this SerializedProperty property, object[] array, object target)
    {
        if (!property.IsCollection())
        {
            return(false);
        }
        if (property.arraySize != array.Length)
        {
            return(false);
        }
        if (property.arraySize < 1)
        {
            return(true);
        }
        var propertyType  = property.GetArrayElementAtIndex(0).propertyType;
        var propertyArray = PropertyUtilities.SetArrayGenericValue(property, propertyType, target);

        if (propertyArray == null)
        {
            return(false);
        }
        switch (propertyType)
        {
        case SerializedPropertyType.Enum:
        {
            var comparer = new EnumComparer <object>();
            return(new HashSet <object>(propertyArray, comparer).SetEquals(new HashSet <object>(array, comparer)));
        }

        case SerializedPropertyType.Generic:
        {
            var comparer = new GenericComparer <object>();
            return(new HashSet <object>(propertyArray, comparer).SetEquals(new HashSet <object>(array, comparer)));
        }

        default:
            return(new HashSet <object>(propertyArray).SetEquals(array));
        }
    }
コード例 #2
0
    public static bool CompareArrays(this SerializedProperty property, SerializedProperty other, object target)
    {
        if (!property.IsCollection() || !other.IsCollection())
        {
            return(false);
        }
        if (property.arraySize != other.arraySize)
        {
            return(false);
        }
        if (property.propertyType != other.propertyType)
        {
            return(false);
        }
        if (property.arraySize < 1)
        {
            return(true);
        }

        var propertyType  = property.GetArrayElementAtIndex(0).propertyType;
        var propertyArray = PropertyUtilities.SetArrayGenericValue(property, propertyType, target);

        if (propertyArray == null)
        {
            return(false);
        }
        var otherArray = PropertyUtilities.SetArrayGenericValue(other, propertyType, target);

        if (otherArray == null)
        {
            return(false);
        }

        return(propertyType == SerializedPropertyType.Generic
            ? new HashSet <object>(propertyArray, new GenericComparer <object>()).SetEquals(
                   new HashSet <object>(propertyArray, new GenericComparer <object>()))
            : new HashSet <object>(propertyArray).SetEquals(otherArray));
    }