static int RecurseBuildParameterInfo(List <VFXParameterInfo> infos, System.Type type, string path, object obj) { if (!type.IsValueType) { return(0); } int count = 0; var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public); var subList = new List <VFXParameterInfo>(); foreach (var field in fields) { var info = new VFXParameterInfo(field.Name, field.FieldType.Name); var subObj = field.GetValue(obj); info.path = path + "_" + field.Name; var tooltip = field.GetCustomAttributes(typeof(TooltipAttribute), true).FirstOrDefault() as TooltipAttribute; if (tooltip != null) { info.tooltip = tooltip.tooltip; } var fieldName = VisualEffectSerializationUtility.GetTypeField(field.FieldType); if (fieldName != null) { info.sheetType = fieldName; RangeAttribute attr = field.GetCustomAttributes(true).OfType <RangeAttribute>().FirstOrDefault(); if (attr != null) { info.min = attr.min; info.max = attr.max; } info.descendantCount = 0; info.defaultValue = new VFXSerializableObject(field.FieldType, subObj); } else { if (field.FieldType == typeof(VFXCoordinateSpace)) // For space { continue; } info.descendantCount = RecurseBuildParameterInfo(subList, field.FieldType, info.path, subObj); } infos.Add(info); infos.AddRange(subList); subList.Clear(); count++; } return(count); }
void BuildValue(List <Action <List <object> > > cmdList, Type type, string propertyPath) { string field = VisualEffectSerializationUtility.GetTypeField(type); if (field != null) { var vfxField = m_VFXPropertySheet.FindPropertyRelative(field + ".m_Array"); SerializedProperty property = null; if (vfxField != null) { for (int i = 0; i < vfxField.arraySize; ++i) { property = vfxField.GetArrayElementAtIndex(i); var nameProperty = property.FindPropertyRelative("m_Name").stringValue; if (nameProperty == propertyPath) { break; } property = null; } } if (property != null) { property = property.FindPropertyRelative("m_Value"); //Debug.Log("PushProperty" + propertyPath + "("+property.propertyType.ToString()+")"); cmdList.Add( o => PushProperty(o, property) ); } } else { foreach (var fieldInfo in type.GetFields(BindingFlags.Public | BindingFlags.Instance)) { if (fieldInfo.FieldType == typeof(VFXCoordinateSpace)) { continue; } //Debug.Log("Push "+type.UserFriendlyName()+"."+fieldInfo.Name+"("+fieldInfo.FieldType.UserFriendlyName()); cmdList.Add(o => { Push(o, fieldInfo); }); BuildValue(cmdList, fieldInfo.FieldType, propertyPath + "_" + fieldInfo.Name); //Debug.Log("Pop "+type.UserFriendlyName()+"."+fieldInfo.Name+"("+fieldInfo.FieldType.UserFriendlyName()); cmdList.Add(o => Pop(o, fieldInfo) ); } } }
void BuildValue(List <Action <List <object> > > cmdList, Type type, string propertyPath) { m_SerializedObject.Update(); string field = VisualEffectSerializationUtility.GetTypeField(type); if (field != null) { var vfxField = m_VFXPropertySheet.FindPropertyRelative(field + ".m_Array"); SerializedProperty property = null; if (vfxField != null) { for (int i = 0; i < vfxField.arraySize; ++i) { property = vfxField.GetArrayElementAtIndex(i); var nameProperty = property.FindPropertyRelative("m_Name").stringValue; if (nameProperty == propertyPath) { break; } property = null; } } if (property != null) { var overrideProperty = property.FindPropertyRelative("m_Overridden"); property = property.FindPropertyRelative("m_Value"); cmdList.Add(o => { if (overrideProperty.boolValue) { PushProperty(o, property); } }); } } else { foreach (var fieldInfo in type.GetFields(BindingFlags.Public | BindingFlags.Instance)) { if (fieldInfo.FieldType == typeof(VFXCoordinateSpace)) { continue; } cmdList.Add(o => { Push(o, fieldInfo); }); BuildValue(cmdList, fieldInfo.FieldType, propertyPath + "_" + fieldInfo.Name); cmdList.Add(o => Pop(o, fieldInfo) ); } } }
static void BuildCategoryParameterInfo(VFXParameter[] parameters, List <VFXParameterInfo> infos) { var subList = new List <VFXParameterInfo>(); foreach (var parameter in parameters) { string rootFieldName = VisualEffectSerializationUtility.GetTypeField(parameter.type); VFXParameterInfo paramInfo = new VFXParameterInfo(parameter.exposedName, parameter.type.Name); paramInfo.tooltip = parameter.tooltip; if (rootFieldName != null) { paramInfo.sheetType = rootFieldName; paramInfo.path = paramInfo.name; if (parameter.valueFilter == VFXValueFilter.Range) { float min = (float)System.Convert.ChangeType(parameter.min, typeof(float)); float max = (float)System.Convert.ChangeType(parameter.max, typeof(float)); paramInfo.min = min; paramInfo.max = max; } else if (parameter.valueFilter == VFXValueFilter.Enum) { paramInfo.enumValues = parameter.enumValues.ToList(); } paramInfo.defaultValue = new VFXSerializableObject(parameter.type, parameter.value); paramInfo.descendantCount = 0; } else { paramInfo.descendantCount = RecurseBuildParameterInfo(subList, parameter.type, parameter.exposedName, parameter.value); } infos.Add(paramInfo); infos.AddRange(subList); subList.Clear(); } }
bool BuildPropertyValue <T>(List <Action <List <object>, object> > cmdList, Type type, string propertyPath, string[] memberPath, int depth, FieldInfo specialSpacableVector3CaseField = null) { string field = VisualEffectSerializationUtility.GetTypeField(type); if (field != null) { var vfxField = m_VFXPropertySheet.FindPropertyRelative(field + ".m_Array"); if (vfxField == null) { return(false); } SerializedProperty property = null; if (vfxField != null) { for (int i = 0; i < vfxField.arraySize; ++i) { property = vfxField.GetArrayElementAtIndex(i); var nameProperty = property.FindPropertyRelative("m_Name").stringValue; if (nameProperty == propertyPath) { break; } property = null; } } if (property != null) { SerializedProperty overrideProperty = property.FindPropertyRelative("m_Overridden"); property = property.FindPropertyRelative("m_Value"); cmdList.Add((l, o) => overrideProperty.boolValue = true); } else { return(false); } if (depth < memberPath.Length) { cmdList.Add((l, o) => l.Add(GetObjectValue(property))); if (!BuildPropertySubValue <T>(cmdList, type, memberPath, depth)) { return(false); } cmdList.Add((l, o) => SetObjectValue(property, l[l.Count - 1])); return(true); } else { var currentValue = GetObjectValue(property); if (specialSpacableVector3CaseField != null) { cmdList.Add( (l, o) => { object vector3Property = specialSpacableVector3CaseField.GetValue(o); SetObjectValue(property, vector3Property); }); } else { if (!typeof(T).IsAssignableFrom(currentValue.GetType())) { return(false); } cmdList.Add((l, o) => SetObjectValue(property, o)); } return(true); } } else if (depth < memberPath.Length) { FieldInfo subField = type.GetField(memberPath[depth]); if (subField == null) { return(false); } return(BuildPropertyValue <T>(cmdList, subField.FieldType, propertyPath + "_" + memberPath[depth], memberPath, depth + 1)); } else if (typeof(Position) == type || typeof(Vector) == type || typeof(DirectionType) == type) { if (typeof(T) != type) { return(false); } FieldInfo vector3Field = type.GetFields(BindingFlags.Instance | BindingFlags.Public).First(t => t.FieldType == typeof(Vector3)); string name = vector3Field.Name; return(BuildPropertyValue <T>(cmdList, typeof(Vector3), propertyPath + "_" + name, new string[] { name }, 1, vector3Field)); } Debug.LogError("Setting A value across multiple property is not yet supported"); return(false); }