コード例 #1
0
        protected override InitState InitPropertyImpl(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            if (!property.isArray)
            {
                return(new InitState(false, "\"" + property.displayName + "\" should be an array"));
            }

            if (!property.GetSystemType().IsSubclassOf(typeof(Object)))
            {
                return(new InitState(false, "\"" + property.displayName + "\" array type should inherit from UnityEngine.Object"));
            }

            var objects = FoundArray(property, baseAttribute);

            if (property.CompareArrays(objects))
            {
                return(new InitState(true));
            }

            property.ClearArray();
            for (var i = 0; i < objects.Length; i++)
            {
                property.InsertArrayElementAtIndex(i);
                property.GetArrayElementAtIndex(i).objectReferenceValue = objects[i];
            }

            return(new InitState(true));
        }
コード例 #2
0
        protected override InitState InitPropertyImpl(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            if (!typeof(Object).IsAssignableFrom(property.GetSystemType()))
            {
                return(new InitState(false, "\"" + property.displayName + "\" should inherit from UnityEngine.Object"));
            }

            property.objectReferenceValue = property.GetGameObject().GetComponent(property.GetSystemType());
            return(new InitState(true));
        }
コード例 #3
0
        protected override InitState InitPropertyImpl(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            var layerNameAttribute = (LayerNameAttribute)baseAttribute;

            if (property.propertyType != SerializedPropertyType.Integer)
            {
                return(new InitState(false, "\"" + property.displayName + "\" should be of type int"));
            }

            property.intValue = layerNameAttribute.LayerId;
            return(new InitState(true));
        }
コード例 #4
0
        protected override InitState InitPropertyImpl(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            if (property.isArray)
            {
                return(new InitState(false, "\"" + property.displayName + "\" should not be an array"));
            }

            if (!typeof(Object).IsAssignableFrom(property.GetSystemType()))
            {
                return(new InitState(false, "\"" + property.displayName + "\" should inherit from UnityEngine.Object"));
            }

            Find(property, baseAttribute);
            return(new InitState(true));
        }
コード例 #5
0
        protected override InitState InitPropertyImpl(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            var animatorParameter = (AnimatorParameterAttribute)baseAttribute;
            var attributeTarget   = property.GetAttributeTarget <AnimatorParameterAttribute>();

            if (property.propertyType != SerializedPropertyType.Integer)
            {
                return(new InitState(false, "\"" + property.displayName + "\" should be of type int"));
            }

            var name = animatorParameter.ParameterName;

            if (animatorParameter.NameAsCallback && property.GetValueFromMember(attributeTarget, name, out string nameValue))
            {
                name = nameValue;
            }

            property.intValue = Animator.StringToHash(name);
            return(new InitState(true));
        }
コード例 #6
0
        protected override InitState InitPropertyImpl(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            if (!property.isArray)
            {
                return(new InitState(false, "\"" + property.displayName + "\" should be an array"));
            }

            var attribute       = (ArraySizeAttribute)baseAttribute;
            var attributeTarget = property.GetAttributeTarget <ArraySizeAttribute>();

            if (!property.GetValueFromMember(attributeTarget, attribute.SizeCallback, out int size))
            {
                size = attribute.Size;
            }

            if (size != property.arraySize)
            {
                property.arraySize = size;
                property.serializedObject.ApplyModifiedProperties();
            }
            return(new InitState(true));
        }
コード例 #7
0
        protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            var attribute = (FindObjectsAttribute)baseAttribute;

            return(property.FindObjectsWithName(attribute.Name, attribute.IncludeInactive));
        }
コード例 #8
0
 protected abstract Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute);
コード例 #9
0
ファイル: BaseAutoValueDrawer.cs プロジェクト: Nama3/madrace
 public InitState InitProperty(MightySerializedField serializedField, BaseAutoValueAttribute baseAttribute) =>
 baseAttribute.ExecuteInPlayMode ? InitPropertyImpl(serializedField, (T)baseAttribute) :
 !EditorApplication.isPlaying ? InitPropertyImpl(serializedField, (T)baseAttribute) : new InitState(true);
コード例 #10
0
 protected abstract InitState InitPropertyImpl(SerializedProperty property, BaseAutoValueAttribute baseAttribute);
コード例 #11
0
 public InitState InitProperty(SerializedProperty property, BaseAutoValueAttribute baseAttribute) =>
 baseAttribute.ExecuteInPlayMode ? InitPropertyImpl(property, baseAttribute) :
 !EditorApplication.isPlaying ? InitPropertyImpl(property, baseAttribute) : new InitState(true);
コード例 #12
0
ファイル: ValueFromDrawer.cs プロジェクト: Elvyira/DreamCards
        protected override InitState InitPropertyImpl(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            var attribute       = (ValueFromAttribute)baseAttribute;
            var attributeTarget = property.GetAttributeTarget <ValueFromAttribute>();
            var propertyTarget  = property.GetPropertyTargetReference();

            if (!attributeTarget.GetType().InfoExist(attribute.ValueName))
            {
                return(new InitState(false, "Callback name: \"" + attribute.ValueName + "\" is invalid"));
            }

            if (!attributeTarget.GetType().GetMemberInfo(attribute.ValueName, new CallbackSignature(property.GetSystemType(), true), out _))
            {
                return(new InitState(false, "\"" + attribute.ValueName + "\" type is invalid"));
            }

            if (!property.isArray || property.propertyType == SerializedPropertyType.String)
            {
                return(SerializedPropertyUtility.SetGenericValue(propertyTarget, property, attribute.ValueName, property.propertyType)
                    ? new InitState(true)
                    : new InitState(false, "\"" + property.displayName + "\" type is not serializable"));
            }

            var state = new InitState(true);
            var index = 0;

            if (property.GetArrayValueFromMember(attributeTarget, attribute.ValueName, out var outArray) &&
                property.CompareArrays(outArray, propertyTarget))
            {
                return(state);
            }

            if (property.arraySize == 0)
            {
                property.InsertArrayElementAtIndex(0);
            }

            if (property.GetArrayElementAtIndex(0).propertyType == SerializedPropertyType.Generic)
            {
                try
                {
                    var propertyType  = property.GetSystemType();
                    var propertyField = propertyTarget.GetField(property.name);
                    var array         = (IList)Array.CreateInstance(propertyType, outArray.Length);

                    for (var i = 0; i < outArray.Length; i++)
                    {
                        array[i] = outArray[i];
                    }

                    propertyField.SetValue(propertyTarget, array);
                    return(new InitState(true));
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex);
                    property.DeleteArrayElementAtIndex(index);
                    return(new InitState(false, "\"" + property.displayName + "\" type is not serializable"));
                }
            }

            property.ClearArray();
            while (index < outArray.Length)
            {
                try
                {
                    property.InsertArrayElementAtIndex(index);
                    if (!(state = SerializedPropertyUtility.SetArrayElementGenericValue(attributeTarget,
                                                                                        property.GetArrayElementAtIndex(index), attribute.ValueName,
                                                                                        property.GetArrayElementAtIndex(index).propertyType, index)
                        ? new InitState(true)
                        : new InitState(false, "\"" + property.displayName + "\" type is not serializable")).isOk)
                    {
                        return(state);
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex);
                    property.DeleteArrayElementAtIndex(index);
                    break;
                }

                index++;
            }

            return(state);
        }
コード例 #13
0
        protected override void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            var attribute = (GetComponentInChildrenWithTagAttribute)baseAttribute;

            property.objectReferenceValue = property.GetComponentInChildrenWithTag(attribute.Tag, attribute.IncludeInactive);
        }
コード例 #14
0
        protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            var attribute = (GetComponentsInChildrenWithLayerAttribute)baseAttribute;

            return((Object[])property.GetComponentsInChildrenWithLayer(attribute.Layer, attribute.IncludeInactive));
        }
コード例 #15
0
        protected override void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            var attribute = (FindObjectAttribute)baseAttribute;

            property.objectReferenceValue = property.FindObjectWithName(attribute.Name, attribute.IncludeInactive);
        }
コード例 #16
0
 protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
 {
     return(property.GetGameObject().GetComponents(property.GetSystemType()));
 }
コード例 #17
0
 protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute) =>
 property.FindAssetsWithName(((FindAssetsAttribute)baseAttribute).Name);
コード例 #18
0
 protected abstract void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute);
コード例 #19
0
        protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            var attribute = (FindAssetsInFoldersAttribute)baseAttribute;

            return(property.FindAssetsInFolders(attribute.Name, attribute.Folders));
        }
コード例 #20
0
ファイル: FindAssetDrawer.cs プロジェクト: Elvyira/DreamCards
 protected override void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute) =>
 property.objectReferenceValue = property.FindAssetWithName(((FindAssetAttribute)baseAttribute).Name);
コード例 #21
0
        protected override void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute)
        {
            var attribute = (FindAssetInFoldersAttribute)baseAttribute;

            property.objectReferenceValue = property.FindAssetInFolders(attribute.Name, attribute.Folders);
        }