3using System.Collections;
4using System.Collections.Generic;
5using System.Runtime.Serialization;
20 modifiedValues =
new Dictionary<Component, Dictionary<string, object>>();
23 List<System.Type> keys;
24 List<Dictionary<string, object>> values;
29 public void GetObjectData(SerializationInfo info, StreamingContext context)
32 modifiedValues =
new Dictionary<Component, Dictionary<string, object>>();
34 List<System.Type> keys =
modifiedValues.Keys.Select(x => x.GetType()).ToList();
36 info.AddValue(
"components", keys, typeof(List<System.Type>));
37 info.AddValue(
"values",
modifiedValues.Values.ToList(), typeof(List<Dictionary<string, object>>));
45 modifiedValues =
new Dictionary<Component, Dictionary<string, object>>();
46 keys = (List<System.Type>) info.GetValue(
"components", typeof(List<System.Type>));
47 values = (List<Dictionary<string, object>>) info.GetValue(
"values", typeof(List<Dictionary<string, object>>));
56 GameObject go = component.gameObject;
60 if(md_component ==
null)
65 Dictionary<string, object> v;
67 if(diff.modifiedValues.TryGetValue(component, out v))
69 if(v.ContainsKey(name))
76 diff.modifiedValues.Add(component,
new Dictionary<string, object>() { {name, value} } );
87 if(keys.Count < 1 || values.Count != keys.Count)
90 modifiedValues =
new Dictionary<Component, Dictionary<string, object>>();
92 int entries = keys.Count;
95 Dictionary<System.Type,
int> dup_components =
new Dictionary<System.Type,
int>();
97 for(
int i = 0; i < entries; i++)
99 Component[] components = target.GetComponents(keys[i]);
101 if( dup_components.ContainsKey(keys[i]) )
102 dup_components[keys[i]]++;
104 dup_components.Add(keys[i], 0);
106 int index = System.Math.Min(dup_components[keys[i]], components.Length-1);
110 foreach(KeyValuePair<string, object> kvp
in values[i])
112 pb_Reflection.SetValue(components[index], kvp.Key, kvp.Value);
UnityEngine.Component Component
pb_ComponentDiff(SerializationInfo info, StreamingContext context)
void ApplyPatch(GameObject target)
void GetObjectData(SerializationInfo info, StreamingContext context)
static void AddDiff(Component component, string name, object value)
Dictionary< Component, Dictionary< string, object > > modifiedValues