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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute) { var attribute = (FindObjectsAttribute)baseAttribute; return(property.FindObjectsWithName(attribute.Name, attribute.IncludeInactive)); }
protected abstract Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute);
public InitState InitProperty(MightySerializedField serializedField, BaseAutoValueAttribute baseAttribute) => baseAttribute.ExecuteInPlayMode ? InitPropertyImpl(serializedField, (T)baseAttribute) : !EditorApplication.isPlaying ? InitPropertyImpl(serializedField, (T)baseAttribute) : new InitState(true);
protected abstract InitState InitPropertyImpl(SerializedProperty property, BaseAutoValueAttribute baseAttribute);
public InitState InitProperty(SerializedProperty property, BaseAutoValueAttribute baseAttribute) => baseAttribute.ExecuteInPlayMode ? InitPropertyImpl(property, baseAttribute) : !EditorApplication.isPlaying ? InitPropertyImpl(property, baseAttribute) : new InitState(true);
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); }
protected override void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute) { var attribute = (GetComponentInChildrenWithTagAttribute)baseAttribute; property.objectReferenceValue = property.GetComponentInChildrenWithTag(attribute.Tag, attribute.IncludeInactive); }
protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute) { var attribute = (GetComponentsInChildrenWithLayerAttribute)baseAttribute; return((Object[])property.GetComponentsInChildrenWithLayer(attribute.Layer, attribute.IncludeInactive)); }
protected override void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute) { var attribute = (FindObjectAttribute)baseAttribute; property.objectReferenceValue = property.FindObjectWithName(attribute.Name, attribute.IncludeInactive); }
protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute) { return(property.GetGameObject().GetComponents(property.GetSystemType())); }
protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute) => property.FindAssetsWithName(((FindAssetsAttribute)baseAttribute).Name);
protected abstract void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute);
protected override Object[] FoundArray(SerializedProperty property, BaseAutoValueAttribute baseAttribute) { var attribute = (FindAssetsInFoldersAttribute)baseAttribute; return(property.FindAssetsInFolders(attribute.Name, attribute.Folders)); }
protected override void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute) => property.objectReferenceValue = property.FindAssetWithName(((FindAssetAttribute)baseAttribute).Name);
protected override void Find(SerializedProperty property, BaseAutoValueAttribute baseAttribute) { var attribute = (FindAssetInFoldersAttribute)baseAttribute; property.objectReferenceValue = property.FindAssetInFolders(attribute.Name, attribute.Folders); }