public void SyncNode(Transform t) { SyncNodeData rootData = null; SyncNodeData data = null; Transform curr = t; while (curr) { SyncNodeData pdata = null; if (data == null) { pdata = ExportNode(curr, true, true); data = pdata; } else { pdata = ExportNode(curr, true); } var lastData = rootData; rootData = pdata; if (lastData != null) { if (!syncedNodes.ContainsKey(lastData.uuid)) { syncedNodes.Add(lastData.uuid, lastData); rootData.childrenData.Add(lastData); } } curr = curr.parent; } if (!syncedNodes.ContainsKey(rootData.uuid)) { syncedNodes.Add(rootData.uuid, rootData); sceneData.childrenData.Add(rootData); } }
SyncNodeData ExportNode(Transform t, bool syncComponent = false, bool syncChildren = false) { SyncNodeData data = null; var uuid = getGuid(t); if (syncedNodes.ContainsKey(uuid)) { syncedNodes.TryGetValue(uuid, out data); return(data); } data = new SyncNodeData(); data.uuid = uuid; data.name = t.name; data.position = t.localPosition; data.scale = t.localScale; data.eulerAngles = t.localEulerAngles; data.rotation = t.localRotation; sceneData.nodeCount++; if (syncComponent) { foreach (var comp in t.GetComponents <Component>()) { if (comp as MonoBehaviour) { if (!(comp as MonoBehaviour).enabled) { continue; } } SyncComponentData compData = null; if (comp is Terrain) { compData = new SyncTerrainData(); } else if (comp is MeshRenderer) { compData = new SyncMeshRendererData(); } else if (comp is SkinnedMeshRenderer) { compData = new SyncSkinnedMeshRendererData(); } else if (comp is InstanceObject) { data.needMerge = true; compData = new SyncInstanceObjectData(); } else if (comp is Light) { compData = new SyncLightData(); } else if (comp is ReflectionProbe) { compData = new SyncReflectionProbeData(); } else if (comp is Motions) { compData = new SyncAnimatorData(); } if (compData != null) { compData.Sync(comp); compData.uuid = comp.GetInstanceID().ToString(); sceneData.componentCount++; data.components.Add(compData.GetData()); } } } if (syncChildren) { var maxChildCount = this.MaxChildCount; var group = t.GetComponent <LODGroup>(); if (group) { maxChildCount = 1; } var childCount = Math.Min(t.childCount, maxChildCount); for (var i = 0; i < childCount; i++) { var c = t.GetChild(i); if (!c.gameObject.activeInHierarchy) { continue; } var childData = ExportNode(c, syncComponent, syncChildren); if (!syncedNodes.ContainsKey(childData.uuid)) { syncedNodes.Add(childData.uuid, childData); data.childrenData.Add(childData); } } } return(data); }