コード例 #1
0
 private void Save(AIBaseNode node)
 {
     FieldInfo[] props = node.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     foreach (FieldInfo prop in props)
     {
         AISerializedVariable v = prop.GetCustomAttribute <AISerializedVariable>();
         if (v == null)
         {
             continue;
         }
         context[node.GetInstanceID() + prop.Name] = prop.GetValue(node);
     }
 }
コード例 #2
0
 private void Load(AIBaseNode node)
 {
     FieldInfo[] props = node.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     foreach (FieldInfo prop in props)
     {
         AISerializedVariable v = prop.GetCustomAttribute <AISerializedVariable>();
         if (v == null)
         {
             continue;
         }
         if (context.ContainsKey(node.GetInstanceID() + prop.Name))
         {
             prop.SetValue(node, context[node.GetInstanceID() + prop.Name]);
         }
         else
         {
             Type type = prop.FieldType;
             var  d    = type.IsValueType ? Activator.CreateInstance(type) : null;
             prop.SetValue(node, d);
         }
     }
 }