コード例 #1
0
        /// <summary>
        /// Check for similar or null references in the Seiralized property
        /// </summary>
        /// <param name="property"></param>
        /// <param name="hasNullRef"></param>
        /// <param name="hasSimialRefs"></param>
        public static void CheckForNullOrSimilarRefs(this SerializedProperty property, ref bool hasNullRef, ref bool hasSimialRefs)
        {
            hasNullRef    = false;
            hasSimialRefs = false;

            if (!property.isArray)
            {
                hasNullRef = property.objectReferenceValue != null;
                return;
            }

            for (int i = 0; i < property.arraySize; i++)
            {
                Object refToCheck = property.GetArrayElementAtIndex(i).objectReferenceValue;
                if (refToCheck != null)
                {
                    if (!hasSimialRefs)
                    {
                        if (property.ContainsObjects(refToCheck, 2))
                        {
                            hasSimialRefs = true;
                        }
                    }
                }
                else
                {
                    if (!hasNullRef)
                    {
                        hasNullRef = true;
                    }
                }
            }
        }