void RestoreComponent(GameObject go, SerializedComponent serializedComponent) { Component component = null; if (!loadedAssemblies.ContainsKey(serializedComponent.assemblyName)) { loadedAssemblies.Add(serializedComponent.assemblyName, Assembly.Load(serializedComponent.assemblyName)); } Type type = loadedAssemblies[serializedComponent.assemblyName].GetType(serializedComponent.typeName); Debug.Assert(type != null, "Type '" + serializedComponent.typeName + "' not found in assembly '" + serializedComponent.assemblyName + "'"); if (type == typeof(Transform)) { component = go.transform; } else { component = Undo.AddComponent(go, type); } // bool restore = true; // if(restore) { EditorJsonUtility.FromJsonOverwrite(serializedComponent.serializedData, component); RestoreObjectReference(serializedComponent.savedInstanceIDs, component); // } deserializedObjects.Add(component); deserializedComponents.Add(new DeserializedComponent(serializedComponent, component)); }
SerializedComponent SerializeComponent(Component component) { SerializedComponent serializedComponent = new SerializedComponent(component.GetType(), EditorJsonUtility.ToJson(component, false)); serializedComponent.savedInstanceIDs = GetInstanceReferenceIDs(component); return(serializedComponent); }
private void RestoreComponent(GameObject go, SerializedComponent serializedComponent) { if (!loadedAssemblies.ContainsKey(serializedComponent.assemblyName)) { loadedAssemblies.Add(serializedComponent.assemblyName, Assembly.Load(serializedComponent.assemblyName)); } Type type = loadedAssemblies[serializedComponent.assemblyName].GetType(serializedComponent.typeName); Debug.Assert(type != null, "Type '" + serializedComponent.typeName + "' not found in assembly '" + serializedComponent.assemblyName + "'"); var component = type == typeof(Transform) ? go.transform : Undo.AddComponent(go, type); EditorJsonUtility.FromJsonOverwrite(serializedComponent.serializedData, component); RestoreObjectReference(serializedComponent.savedInstanceIDs, component); deserializedObjects.Add(component); deserializedComponents.Add(new DeserializedComponent(serializedComponent, component)); }
public DeserializedComponent(SerializedComponent serializedComponent, Component component) { this.serializedComponent = serializedComponent; this.component = component; }