Exemple #1
0
        public override object ReadYaml(ref ObjectContext objectContext)
        {
            if (recursionLevel++ == 0)
            {
                SetupMaxExpectedDepth(objectContext);
            }

            ++levelSinceScriptComponent;
            if (objectContext.Descriptor.Type == typeof(ScriptComponent))
            {
                levelSinceScriptComponent = 0;
            }

            try
            {
                var result = base.ReadYaml(ref objectContext);

                if (objectContext.Descriptor.Type == typeof(EntityHierarchyData))
                {
                    // Let's fixup entity references after serialization
                    EntityAnalysis.FixupEntityReferences((EntityHierarchyData)objectContext.Instance);
                }

                return(result);
            }
            finally
            {
                recursionLevel--;
                levelSinceScriptComponent--;
            }
        }
Exemple #2
0
        public static EntityAsset ExtractSceneClone(EntityAsset source, Guid sourceRootEntity)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // Note: Instead of copying the whole asset (with its potentially big hierarchy), we first copy the asset only (without the hierarchy), then the sub-hierarchy to extract.

            // create the hierarchy of the sub-tree
            var subTreeRoot      = source.Hierarchy.Entities[sourceRootEntity];
            var subTreeHierarchy = new EntityHierarchyData {
                Entities = { subTreeRoot }, RootEntities = { sourceRootEntity }
            };

            foreach (var subTreeEntity in subTreeRoot.EnumerateChildren(true))
            {
                subTreeHierarchy.Entities.Add(subTreeEntity);
            }

            // clone the entities of the sub-tree
            var clonedHierarchy = (EntityHierarchyData)AssetCloner.Clone(subTreeHierarchy);

            clonedHierarchy.Entities[sourceRootEntity].Transform.Parent = null;

            // set to null reference outside of the sub-tree
            EntityAnalysis.FixupEntityReferences(clonedHierarchy);

            // temporary nullify the hierarchy to avoid to clone it
            var sourceHierarchy = source.Hierarchy;

            source.Hierarchy = null;

            // clone asset without hierarchy
            var clonedAsset = (EntityAsset)AssetCloner.Clone(source);

            clonedAsset.Hierarchy = clonedHierarchy;

            // revert the source hierarchy
            source.Hierarchy = sourceHierarchy;

            return(clonedAsset);
        }
Exemple #3
0
            public void ApplyChanges()
            {
                // "Garbage collect" entities that are not referenced in hierarchy tree anymore
                var entityHashes = new HashSet <Guid>();

                CollectEntities(entityHashes, source.RootEntity);

                source.Entities.Clear();
                foreach (var item in this)
                {
                    if (entityHashes.Contains(item.Key))
                    {
                        source.Entities.Add(item.Value);
                    }
                }

                // Fixup references
                EntityAnalysis.FixupEntityReferences(source);
            }
Exemple #4
0
        public override object ReadYaml(ref ObjectContext objectContext)
        {
            EnterNode(ref objectContext);

            try
            {
                var result = base.ReadYaml(ref objectContext);

                if (objectContext.Descriptor.Type == typeof(EntityHierarchyData))
                {
                    // Let's fixup entity references after serialization
                    EntityAnalysis.FixupEntityReferences((EntityHierarchyData)objectContext.Instance);
                }

                return(result);
            }
            finally
            {
                LeaveNode(ref objectContext);
            }
        }