public static SerializedGraph SerializeGraph(uNode.uNodeRoot root) { SerializedGraph graph = new SerializedGraph(); List <Transform> transforms = new List <Transform>(); { if (root.RootObject != null) { var children = root.RootObject.GetComponentsInChildren <Transform>(true); transforms.AddRange(children); } graph.graphType = new MemberData(root.GetType(), MemberData.TargetType.Type); } var graphRoot = Serialize(root.gameObject, new Component[] { root }, transforms); if (root as uNode.uNodeBase && (root as uNode.uNodeBase).NestedClass) //Handle nested types. { transforms = new List <Transform>(); List <Component> roots = new List <Component>(); var comps = (root as uNode.uNodeBase).NestedClass.GetComponents <Component>(); foreach (var c in comps) { if (c is uNode.uNodeRoot || c is uNode.uNodeData || !(c is MonoBehaviour)) { roots.Add(c); } } foreach (var r in roots) { if (r is uNode.uNodeRoot) { var nodeRoot = r as uNode.uNodeRoot; if (nodeRoot.RootObject != null) { var children = nodeRoot.RootObject.GetComponentsInChildren <Transform>(true); transforms.AddRange(children); } } } var nestedTypes = Serialize((root as uNode.uNodeBase).NestedClass.gameObject, roots, transforms); graph.nestedTypes = nestedTypes; } { graph.serializedGraph = graphRoot; graph.variables = root.Variables.ToArray(); } return(graph); }