public static ValueBase Clone(ValueBase source) { ValueBase v = new ValueBase(); FieldInfo[] infos = source.GetType().GetFields(); foreach (FieldInfo info in infos) { object value; if (info.FieldType.IsSubclassOf(typeof(Array))) { Array sourceArray = (Array)info.GetValue(source); if (sourceArray == null) { continue; } Array dest = Array.CreateInstance(info.FieldType.GetElementType(), sourceArray.Length); Array.Copy(sourceArray, dest, dest.Length); value = dest; } else { value = info.GetValue(source); } info.SetValue(v, value); } return(v); }
public BehaviorTreeArgsDict GetArgsDict() { BehaviorTreeArgsDict dict = new BehaviorTreeArgsDict(); foreach (var item in gameObject.GetComponents <BTTypeBaseComponent>()) { FieldInfo info = item.GetType().GetField("fieldValue"); ValueBase valueBase = new ValueBase(); if (item.GetType() == typeof(BTEnumComponent)) { valueBase.SetValueByType(typeof(Enum), info.GetValue(item)); } else { valueBase.SetValueByType(info.FieldType, info.GetValue(item)); } dict.Add(item.fieldName, valueBase); } return(dict); }
private static void NewSetValue(ref Node node, FieldInfo field, ValueBase valueBase, string nodeName) { field.SetValue(node, valueBase.GetValueByType(field.FieldType)); }