public static BaseNode CloneWithoutChildren(BaseNode node) { if (node == null) { return(null); } var newNode = Activator.CreateInstance(node.GetType()) as BaseNode; foreach (var fi in ReactTypeRegister.GetFields(node)) { fi.SetValue(newNode, fi.GetValue(node)); } return(newNode); }
public void Serialize(BaseNode node) { if (node == null) { tokens.Add("null"); } else { tokens.Add("new"); tokens.Add(node.GetType().AssemblyQualifiedName); tokens.Add("{"); foreach (var fi in ReactTypeRegister.GetFields(node)) { tokens.Add(fi.Name); var o = fi.GetValue(node); if (fi.FieldType.IsSubclassOf(typeof(UnityEngine.Object))) { references.Add(o as UnityEngine.Object); } else { tokens.Add(ConvertToRepr(o)); } } tokens.Add("}"); var parent = node as IParentNode; if (parent != null) { tokens.Add("["); foreach (var child in parent.GetChildren()) { Serialize(child); } tokens.Add("]"); } } }
public static BaseNode Clone(BaseNode node) { if (node == null) { return(null); } var newNode = Activator.CreateInstance(node.GetType()) as BaseNode; foreach (var fi in ReactTypeRegister.GetFields(node)) { fi.SetValue(newNode, fi.GetValue(node)); } var nodeParent = node as IParentNode; if (nodeParent != null) { var newNodeParent = newNode as IParentNode; foreach (var c in nodeParent.GetChildren()) { newNodeParent.Add(Clone(c)); } } return(newNode); }