示例#1
0
            protected override void VisitNode(IGraphNode node)
            {
                var currentPath = CurrentPath.Clone();

                Result.Add(Tuple.Create(node, currentPath));
                base.VisitNode(node);
            }
            private void ProcessReferences(IGraphNode node, NodeIndex index, Type type)
            {
                if (node == null)
                {
                    return;
                }

                if (typeof(IGraphicsRendererBase).IsAssignableFrom(type))
                {
                    // Check if there is a setter
                    if (!((node as IMemberNode)?.MemberDescriptor.HasSet ?? true))
                    {
                        return;
                    }

                    var value = index == NodeIndex.Empty ? node.Retrieve() : node.Retrieve(index);

                    // Hide inlined renderers which don't have nodes
                    if ((value != null) && ((value as ISharedRenderer) == null))
                    {
                        return;
                    }

                    var path = CurrentPath.Clone();
                    if (index != NodeIndex.Empty)
                    {
                        path.PushIndex(index);
                    }
                    externalReferences.Add(new SharedRendererReferenceKey(path, node.Type), value as ISharedRenderer);
                }
            }
示例#3
0
 public override void VisitObjectMember(object container, ObjectDescriptor containerDescriptor, IMemberDescriptor member, object value)
 {
     if (sourceFiles != null)
     {
         if (member.Type == typeof(UFile) && value != null)
         {
             var file = (UFile)value;
             if (!string.IsNullOrWhiteSpace(file.ToString()))
             {
                 var attribute = member.GetCustomAttributes <SourceFileMemberAttribute>(true).SingleOrDefault();
                 if (attribute != null)
                 {
                     if (!sourceFiles.ContainsKey(file))
                     {
                         sourceFiles.Add(file, attribute.UpdateAssetIfChanged);
                     }
                     else if (attribute.UpdateAssetIfChanged)
                     {
                         // If the file has already been collected, just update whether it should update the asset when changed
                         sourceFiles[file] = true;
                     }
                 }
             }
         }
     }
     if (compilationInputFiles != null)
     {
         if (member.Type == typeof(UFile) && value != null)
         {
             var file = (UFile)value;
             if (!string.IsNullOrWhiteSpace(file.ToString()))
             {
                 var attribute = member.GetCustomAttributes <SourceFileMemberAttribute>(true).SingleOrDefault();
                 if (attribute != null && !attribute.Optional)
                 {
                     compilationInputFiles.Add(file);
                 }
             }
         }
     }
     if (sourceMembers != null)
     {
         if (member.Type == typeof(UFile))
         {
             var attribute = member.GetCustomAttributes <SourceFileMemberAttribute>(true).SingleOrDefault();
             if (attribute != null)
             {
                 sourceMembers[CurrentPath.Clone()] = value as UFile;
             }
         }
     }
     base.VisitObjectMember(container, containerDescriptor, member, value);
 }
示例#4
0
        private bool ProcessObject(object obj, Type expectedType)
        {
            var unloadable = obj as IUnloadable;

            if (unloadable != null)
            {
                unloadableitems.Add(new UnloadableItem(unloadable, CurrentPath.Clone()));

                // Don't recurse inside
                return(true);
            }
            return(false);
        }
示例#5
0
            public override void VisitObject(object obj, ObjectDescriptor descriptor, bool visitMembers)
            {
                bool processObject = true;

                ++scriptComponentDepth;

                if (componentDepth >= 1)
                {
                    var entity = obj as Entity;
                    if (entity != null)
                    {
                        Result.EntityReferences.Add(new EntityLink(entity, CurrentPath.Clone()));
                        processObject = false;
                    }

                    var entityComponent = obj as EntityComponent;
                    if (entityComponent != null)
                    {
                        Result.EntityReferences.Add(new EntityLink(entityComponent, CurrentPath.Clone()));
                        processObject = false;
                    }
                }
                if (scriptComponentDepth != 2 && obj is Script)
                {
                    Result.EntityReferences.Add(new EntityLink((Script)obj, CurrentPath.Clone()));
                    processObject = false;
                }

                if (obj is EntityComponent)
                {
                    componentDepth++;
                }

                if (obj is ScriptComponent)
                {
                    scriptComponentDepth = 0;
                }

                if (processObject)
                {
                    base.VisitObject(obj, descriptor, visitMembers);
                }

                if (obj is EntityComponent)
                {
                    componentDepth--;
                }

                --scriptComponentDepth;
            }
示例#6
0
        /// <inheritdoc/>
        protected override void VisitReference(IGraphNode referencer, ObjectReference reference)
        {
            var asset = reference.TargetNode.Retrieve() as Asset;

            if (asset != null)
            {
                assets.Add(CurrentPath.Clone(), asset);
            }
            // Don't continue the visit once we found an asset, we cannot have nested assets.
            else
            {
                base.VisitReference(referencer, reference);
            }
        }
        /// <inheritdoc/>
        public override void VisitObject(object obj, ObjectDescriptor descriptor, bool visitMembers)
        {
            // Same as previous VisitObjectMember() remark, we should probably unify IDataCustomVisitor and AssetVisitorBase
            var context = AssetCompositeSerializer.LocalContext.Value;

            if (context?.SerializeAsReference ?? false)
            {
                Result.Add(new AssetPartReference {
                    AssetPart = obj, Path = CurrentPath.Clone()
                });
            }
            else
            {
                base.VisitObject(obj, descriptor, visitMembers);
            }
        }
        /// <inheritdoc/>
        public override void VisitObject(object obj, ObjectDescriptor descriptor, bool visitMembers)
        {
            var shouldRemove = context.EnterNode(descriptor.Type);

            if (context.SerializeAsReference)
            {
                Result.Add(new AssetPartReference {
                    AssetPart = obj, Path = CurrentPath.Clone()
                });
            }
            else
            {
                base.VisitObject(obj, descriptor, visitMembers);
            }
            context.LeaveNode(descriptor.Type, shouldRemove);
        }
示例#9
0
        public override void VisitObjectMember(object container, ObjectDescriptor containerDescriptor, IMemberDescriptor member, object value)
        {
            // Don't visit base parts as they are visited at the top level.
            if (typeof(Asset).IsAssignableFrom(member.DeclaringType) && (member.Name == Asset.BasePartsProperty))
            {
                return;
            }

            if (sourceFiles != null)
            {
                if (member.Type == typeof(UFile) && value != null)
                {
                    var file = (UFile)value;
                    if (!string.IsNullOrWhiteSpace(file.ToString()))
                    {
                        var attribute = member.GetCustomAttributes <SourceFileMemberAttribute>(true).SingleOrDefault();
                        if (attribute != null)
                        {
                            if (!sourceFiles.ContainsKey(file))
                            {
                                sourceFiles.Add(file, attribute.UpdateAssetIfChanged);
                            }
                            else if (attribute.UpdateAssetIfChanged)
                            {
                                // If the file has already been collected, just update whether it should update the asset when changed
                                sourceFiles[file] = true;
                            }
                        }
                    }
                }
            }
            if (sourceMembers != null)
            {
                if (member.Type == typeof(UFile))
                {
                    var attribute = member.GetCustomAttributes <SourceFileMemberAttribute>(true).SingleOrDefault();
                    if (attribute != null)
                    {
                        sourceMembers[CurrentPath.Clone()] = value as UFile;
                    }
                }
            }
            base.VisitObjectMember(container, containerDescriptor, member, value);
        }
            public override void VisitObject(object obj, ObjectDescriptor descriptor, bool visitMembers)
            {
                var identifiable = obj as IIdentifiable;

                if (identifiable != null)
                {
                    HashSet <IIdentifiable> identifiables;
                    if (!IdentifiablesById.TryGetValue(identifiable.Id, out identifiables))
                    {
                        IdentifiablesById.Add(identifiable.Id, identifiables = new HashSet <IIdentifiable>());
                    }
                    identifiables.Add(identifiable);
                    List <MemberPath> paths;
                    if (!IdentifiablePaths.TryGetValue(identifiable, out paths))
                    {
                        IdentifiablePaths.Add(identifiable, paths = new List <MemberPath>());
                    }
                    paths.Add(CurrentPath.Clone());
                }
                base.VisitObject(obj, descriptor, visitMembers);
            }
            protected override bool ProcessObject(object obj, Type expectedType)
            {
                // TODO: More advanced checks if IUnloadable is supposed to be a type from the unloaded assembly (this would avoid processing unecessary IUnloadable)
                if (obj != null && (UnloadedAssemblies.Contains(obj.GetType().Assembly) || obj is IUnloadable))
                {
                    NodeIndex index;
                    var       settings = new SerializerContextSettings(Log);
                    var       path     = GraphNodePath.From(propertyGraph.RootNode, CurrentPath, out index);

                    var overrides = AssetPropertyGraph.GenerateOverridesForSerialization(path.GetNode());
                    overrides = RemoveFirstIndexInYamlPath(overrides, index);
                    if (overrides != null)
                    {
                        settings.Properties.Add(AssetObjectSerializerBackend.OverrideDictionaryKey, overrides);
                    }

                    var objectReferences = propertyGraph.GenerateObjectReferencesForSerialization(path.GetNode());
                    objectReferences = RemoveFirstIndexInYamlPath(objectReferences, index);
                    if (objectReferences != null)
                    {
                        settings.Properties.Add(AssetObjectSerializerBackend.ObjectReferencesKey, objectReferences);
                    }

                    var parsingEvents = new List <ParsingEvent>();
                    AssetYamlSerializer.Default.Serialize(new ParsingEventListEmitter(parsingEvents), obj, expectedType, settings);

                    // Buid parent path
                    var parentPath = CurrentPath.Clone();
                    parentPath.Pop();

                    ItemsToReload.Add(new ItemToReload(parentPath, CurrentPath.Clone(), parsingEvents, expectedType));

                    // Don't recurse inside
                    return(true);
                }
                return(false);
            }
示例#12
0
 private void AddLink(object value, Func <Guid?, string, object> updateReference)
 {
     References.Add(new AssetReferenceLink(CurrentPath.Clone(), value, updateReference));
 }