Ejemplo n.º 1
0
        private InSceneDependencyMappingNode GetNode(string id)
        {
            if (!Lookup.ContainsKey(id))
            {
                InSceneDependencyMappingNode node = new InSceneDependencyMappingNode();
                node.NodeId = id;
                Lookup.Add(id, node);
            }

            return(Lookup[id]);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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();
        }