示例#1
0
        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);
        }
示例#2
0
 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("]");
         }
     }
 }
示例#3
0
        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);
        }