public void Update(ProgressBase progress) { Lookup.Clear(); Stack <PathSegment> stack = new Stack <PathSegment>(); TraverseValues traverseValues = new TraverseValues(); traverseValues.SceneObjects = new HashSet <UnityEngine.Object>(); GameObject[] rootGameObjects = GetRootGameObjects(); foreach (GameObject gameObject in rootGameObjects) { FindAllGameObjects(gameObject, traverseValues); } foreach (GameObject gameObject in rootGameObjects) { TraverseGameObject(gameObject, stack, traverseValues); } Nodes = new IResolvedNode[Lookup.Count]; int count = 0; foreach (KeyValuePair <string, InSceneDependencyMappingNode> pair in Lookup) { Nodes[count++] = pair.Value; } }
private void FindAllGameObjects(GameObject go, TraverseValues traverseValues) { int childCount = go.transform.childCount; traverseValues.SceneObjects.Add(go); for (int i = 0; i < childCount; ++i) { FindAllGameObjects(go.transform.GetChild(i).gameObject, traverseValues); } }
private void TraverseGameObject(GameObject go, Stack <PathSegment> stack, TraverseValues traverseValues) { Component[] components = go.GetComponents <Component>(); string goHash = go.GetHashCode().ToString(); InSceneDependencyMappingNode node = GetNode(goHash); foreach (Component component in components) { TraverseComponent(go, component, stack, traverseValues); } int childCount = go.transform.childCount; for (int i = 0; i < childCount; ++i) { Transform child = go.transform.GetChild(i); TraverseGameObject(child.gameObject, stack, traverseValues); } }
private void TraverseComponent(GameObject go, Component component, Stack <PathSegment> stack, TraverseValues traverseValues) { stack.Push(new PathSegment(component.GetType().Name, PathSegmentType.Component)); SerializedObject serializedObject = new SerializedObject(component); SerializedProperty serializedProperty = serializedObject.GetIterator(); while (serializedProperty.Next(true)) { if (serializedProperty.propertyType == SerializedPropertyType.ObjectReference) { UnityEngine.Object value = serializedProperty.objectReferenceValue; if (value == null) { continue; } Component componentValue = null; if (value is Component) { string propertyPath = serializedProperty.propertyPath; bool exclude = propertyPath.StartsWith("m_Children.") || propertyPath == "m_Father"; if (!exclude) { componentValue = (value as Component); value = componentValue.gameObject; } } if (value == go) { continue; } if (traverseValues.SceneObjects.Contains(value)) { string goHash = go.GetHashCode().ToString(); string valueHash = value.GetHashCode().ToString(); InSceneDependencyMappingNode node = GetNode(goHash); stack.Push(new PathSegment(serializedProperty.propertyPath, PathSegmentType.Property)); if (componentValue) { stack.Push(new PathSegment(componentValue.GetType().Name, PathSegmentType.Unknown)); node.Dependencies.Add(new Dependency(valueHash, "InScene", GetHandledNodeType(), stack.ToArray())); stack.Pop(); } else { node.Dependencies.Add(new Dependency(valueHash, "InScene", GetHandledNodeType(), stack.ToArray())); } stack.Pop(); } } } stack.Pop(); }