Example #1
0
        private void ProcessHierarchy(AssetDocumentHierarchyElement owner, IHierarchyElement element,
                                      IGameObjectConsumer consumer, bool prefabImport, HashSet <ulong> visited)
        {
            if (element == null)
            {
                return;
            }

            if (visited.Contains(element.Location.LocalDocumentAnchor))
            {
                return;
            }

            if (element is IGameObjectHierarchy gameObjectHierarchy)
            {
                ProcessGameObject(owner, gameObjectHierarchy, consumer, prefabImport, visited);
            }
            else if (element is IComponentHierarchy componentHierarchy)
            {
                var gameObjectReference = componentHierarchy.OwningGameObject;
                var gameObject          = myAssetDocumentHierarchyElementContainer.GetHierarchyElement(gameObjectReference, prefabImport) as IGameObjectHierarchy;

                ProcessGameObject(owner, gameObject, consumer, prefabImport, visited);
            }
            else
            {
                Assertion.Fail($"Unsupported type: {element.GetType().Name}");
            }
        }
Example #2
0
        private void ProcessGameObject(AssetDocumentHierarchyElement owner, IGameObjectHierarchy gameObject,
                                       IGameObjectConsumer consumer, bool prefabImport, HashSet <ulong> visited)
        {
            var transform = gameObject?.GetTransformHierarchy(owner);

            if (transform == null)
            {
                return;
            }

            if (!consumer.AddGameObject(owner, gameObject))
            {
                return;
            }

            var parentTransform = myAssetDocumentHierarchyElementContainer.GetHierarchyElement(transform.ParentTransform, prefabImport) as ITransformHierarchy;

            if (parentTransform == null)
            {
                return;
            }

            visited.Add(gameObject.Location.LocalDocumentAnchor);
            ProcessHierarchy(owner, parentTransform, consumer, prefabImport, visited);
        }
Example #3
0
        private static void Write(UnsafeWriter writer, AssetDocumentHierarchyElement value)
        {
            writer.Write(value.myOtherBoxedElements.Count);
            writer.Write(value.myGameObjectHierarchies.Count);
            writer.Write(value.myTransformElements.Count);
            writer.Write(value.myScriptComponentElements.Count);
            writer.Write(value.myComponentElements.Count);

            foreach (var v in value.myOtherBoxedElements)
            {
                WriteHierarchyElement(writer, v);
            }

            foreach (var v in value.myGameObjectHierarchies)
            {
                GameObjectHierarchy.Write(writer, v);
            }

            foreach (var v in value.myTransformElements)
            {
                TransformHierarchy.Write(writer, v);
            }

            foreach (var v in value.myScriptComponentElements)
            {
                ScriptComponentHierarchy.Write(writer, v);
            }

            foreach (var v in value.myComponentElements)
            {
                ComponentHierarchy.Write(writer, v);
            }
        }
 private static void Write(UnsafeWriter writer, AssetDocumentHierarchyElement value)
 {
     writer.Write(value.myLocalAnchorToHierarchyElement.Count);
     foreach (var v in value.myLocalAnchorToHierarchyElement)
     {
         writer.WritePolymorphic(v.Value);
     }
 }
Example #5
0
        public void Merge(IPsiSourceFile currentAssetSourceFile, AssetDocumentHierarchyElement hierarchyElement, IUnityAssetDataElementPointer unityAssetDataElementPointer, IUnityAssetDataElement unityAssetDataElement)
        {
            var element = unityAssetDataElement as AssetDocumentHierarchyElement;

            myAssetDocumentsHierarchy[currentAssetSourceFile] = unityAssetDataElementPointer;
            element.RestoreHierarchy(this, currentAssetSourceFile);

            myPrefabImportCache.OnHierarchyCreated(currentAssetSourceFile, element);
        }
        public void Merge(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement hierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var element = unityAssetDataElement as AssetDocumentHierarchyElement;

            element.AssetDocumentHierarchyElementContainer = this;
            element.IsScene = sourceFile.GetLocation().ExtensionWithDot.Equals(UnityYamlConstants.Scene);
            myAssetDocumentsHierarchy[sourceFile] = element;
            element.RestoreHierarchy();

            myPrefabImportCache.Add(sourceFile, element);
        }
        private static object Read(UnsafeReader reader)
        {
            var count  = reader.ReadInt32();
            var result = new AssetDocumentHierarchyElement();

            for (int i = 0; i < count; i++)
            {
                var hierarchyElement = reader.ReadPolymorphic <IHierarchyElement>();
                result.myLocalAnchorToHierarchyElement[hierarchyElement.Location.LocalDocumentAnchor] = hierarchyElement;
                if (hierarchyElement is ITransformHierarchy transformHierarchy)
                {
                    result.myTransformHierarchies.Add(transformHierarchy);
                }

                if (hierarchyElement is IPrefabInstanceHierarchy prefabInstanceHierarchy)
                {
                    result.myPrefabInstanceHierarchies.Add(prefabInstanceHierarchy);
                }
            }
            return(result);
        }
Example #8
0
        private static object Read(UnsafeReader reader)
        {
            var otherCount       = reader.ReadInt32();
            var gameObjectsCount = reader.ReadInt32();
            var transformCount   = reader.ReadInt32();
            var scriptCount      = reader.ReadInt32();
            var componentsCount  = reader.ReadInt32();


            var result = new AssetDocumentHierarchyElement(otherCount, gameObjectsCount, transformCount, scriptCount, componentsCount);

            for (int i = 0; i < otherCount; i++)
            {
                var hierarchyElement = ReadHieraerchyElement(reader);
                result.myOtherBoxedElements.Add(hierarchyElement);
            }

            for (int i = 0; i < gameObjectsCount; i++)
            {
                result.myGameObjectHierarchies.Add(GameObjectHierarchy.Read(reader));
            }

            for (int i = 0; i < transformCount; i++)
            {
                result.myTransformElements.Add(TransformHierarchy.Read(reader));
            }

            for (int i = 0; i < scriptCount; i++)
            {
                result.myScriptComponentElements.Add(ScriptComponentHierarchy.Read(reader));
            }

            for (int i = 0; i < componentsCount; i++)
            {
                result.myComponentElements.Add(ComponentHierarchy.Read(reader));
            }

            return(result);
        }
Example #9
0
 public void Drop(IPsiSourceFile currentAssetSourceFile, AssetDocumentHierarchyElement hierarchyElement, IUnityAssetDataElement unityAssetDataElement)
 {
     myPrefabImportCache.OnHierarchyRemoved(currentAssetSourceFile, unityAssetDataElement as AssetDocumentHierarchyElement);
     myAssetDocumentsHierarchy.TryRemove(currentAssetSourceFile, out _);
 }
 public bool AddGameObject(AssetDocumentHierarchyElement owner, IGameObjectHierarchy gameObject)
 {
     myParts.Push(gameObject.Name ?? "...");
     myIndex.Push(gameObject.GetTransformHierarchy(owner).NotNull("gameObject.GetTransformHierarchy(cache, owner) != null").RootIndex);
     return(!myOnlyName);
 }