Ejemplo n.º 1
0
            public override void VisitCollectionItem(IEnumerable collection, CollectionDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
            {
                base.VisitCollectionItem(collection, descriptor, index, item, itemDescriptor);
                var assetReference    = item as AssetReference;
                var assetBase         = item as AssetBase;
                var attachedReference = item != null?AttachedReferenceManager.GetAttachedReference(item) : null;

                // TODO force support for IList in CollectionDescriptor
                if (assetReference != null)
                {
                    var list = (IList)collection;
                    AddLink(assetReference, (guid, location) => list[index] = AssetReference.New(descriptor.ElementType, guid.HasValue ? guid.Value : assetReference.Id, location));
                }
                else if (assetBase != null)
                {
                    var list = (IList)collection;
                    AddLink(assetBase, (guid, location) => list[index] = new AssetBase(location, assetBase.Asset));
                }
                else if (attachedReference != null)
                {
                    var list = (IList)collection;
                    AddLink(new AttachedContentReference(attachedReference), (guid, location) => list[index] = guid.HasValue && guid.Value != Guid.Empty ? AttachedReferenceManager.CreateSerializableVersion(descriptor.ElementType, guid.Value, location) : null);
                }
                else if (item is UFile)
                {
                    var list = (IList)collection;
                    AddLink(item, (guid, location) => list[index] = new UFile(location));
                }
                else if (item is UDirectory)
                {
                    var list = (IList)collection;
                    AddLink(item, (guid, location) => list[index] = new UDirectory(location));
                }
            }
Ejemplo n.º 2
0
        private async Task UpdateGameSideReference([NotNull] AssetCompositeEditorViewModel editor, [NotNull] IGraphNode gameSideNode, ContentChangeType changeType, object oldValue, object newValue, NodeIndex index)
        {
            if (editor == null)
            {
                throw new ArgumentNullException(nameof(editor));
            }

            if (!AssetRegistry.IsContentType(gameSideNode.Descriptor.GetInnerCollectionType()))
            {
                return;
            }

            // Grab the old referenced object if it's not null
            AttachedReference reference = null;

            if (!ReferenceEquals(oldValue, null))
            {
                reference = AttachedReferenceManager.GetAttachedReference(oldValue);
            }

            // Switch to game thread to actually update objects
            await editor.Controller.InvokeTask(() =>
            {
                // For references, push null instead of the real value, the editor asset loader will set the actual value later
                switch (changeType)
                {
                case ContentChangeType.ValueChange:
                    ((IMemberNode)gameSideNode).Update(null);
                    break;

                case ContentChangeType.CollectionUpdate:
                    ((IObjectNode)gameSideNode).Update(null, index);
                    break;

                case ContentChangeType.CollectionAdd:
                    ((IObjectNode)gameSideNode).Add(null, index);
                    break;

                case ContentChangeType.CollectionRemove:
                    var oldValueGameSide = gameSideNode.Retrieve(index);
                    ((IObjectNode)gameSideNode).Remove(oldValueGameSide, index);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(changeType), changeType, null);
                }

                if (oldValue == newValue)
                {
                    return(Task.CompletedTask);
                }

                // Unregister the previous value
                if (reference != null)
                {
                    return(editor.Controller.Loader.Manager.ClearContentReference(Owner.Id, reference.Id, gameSideNode, index));
                }
                return(Task.CompletedTask);
            });
        }
Ejemplo n.º 3
0
        private bool ShouldDisplayNavigationMesh(NavigationMeshAsset navigationMeshAsset)
        {
            // Don't show static navigation meshes when the dynamic system is enabled
            if (dynamicNavigationMeshSystem?.Enabled ?? false)
            {
                return(false);
            }

            var referencedSceneReference = AttachedReferenceManager.GetAttachedReference(navigationMeshAsset.Scene);

            if (referencedSceneReference == null)
            {
                return(false);
            }

            // Check the current scene and all child scenes if they are being referenced by this navigation mesh asset
            if (game.ContentScene == null)
            {
                return(false);
            }

            if (HasSceneOrChildSceneReference(referencedSceneReference, game.ContentScene))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
            public override void VisitObject(object obj, ObjectDescriptor descriptor, bool visitMembers)
            {
                // references and base
                var reference = obj as IReference;

                if (reference == null)
                {
                    var attachedReference = AttachedReferenceManager.GetAttachedReference(obj);
                    if (attachedReference != null && attachedReference.IsProxy)
                    {
                        reference = attachedReference;
                    }
                }

                if (reference != null)
                {
                    var isBase = reference is AssetBase;

                    // Don't record base import
                    if (isBase && ((AssetBase)reference).IsRootImport)
                    {
                        return;
                    }

                    dependencies.AddBrokenLinkOut(reference, (isBase ? ContentLinkType.Inheritance : 0) | ContentLinkType.Reference);
                }
                else
                {
                    base.VisitObject(obj, descriptor, visitMembers);
                }
            }
Ejemplo n.º 5
0
        private async void OpenDefaultScene(SessionViewModel session)
        {
            var startupPackage = session.LocalPackages.SingleOrDefault(x => x.IsCurrentPackage);

            if (startupPackage == null)
            {
                return;
            }

            var gameSettingsAsset = startupPackage.Assets.FirstOrDefault(x => x.Url == Assets.GameSettingsAsset.GameSettingsLocation);
            var defaultScene      = ((Assets.GameSettingsAsset)gameSettingsAsset?.Asset)?.DefaultScene;

            if (defaultScene == null)
            {
                return;
            }

            var defaultSceneReference = AttachedReferenceManager.GetAttachedReference(defaultScene);

            if (defaultSceneReference == null)
            {
                return;
            }

            var asset = session.GetAssetById(defaultSceneReference.Id);

            if (asset == null)
            {
                return;
            }

            await assetEditorsManager.OpenAssetEditorWindow(asset);
        }
Ejemplo n.º 6
0
        public Guid GetId(object instance)
        {
            // If the object is not identifiable, early exit
            if (!isIdentifiable)
            {
                return(Guid.Empty);
            }

            // Don't use  local id if the object is already identifiable

            // If an object has an attached reference, we cannot use the id of the instance
            // So we need to use an auto-generated Id
            var attachedReference = AttachedReferenceManager.GetAttachedReference(instance);

            if (attachedReference == null)
            {
                var @component = instance as IIdentifiable;
                if (@component != null)
                {
                    return(@component.Id);
                }
            }

            // If we don't have yet an id, create one.
            if (!id.HasValue)
            {
                id = Guid.NewGuid();
            }

            return(id.Value);
        }
Ejemplo n.º 7
0
        protected override void VisitNode(IGraphNode node)
        {
            var assetNode = (IAssetNode)node;
            // TODO: share the proper const
            var gameContent = assetNode.GetContent("Game");

            if (gameContent != null)
            {
                var memberContent = node as IMemberNode;
                if (memberContent != null)
                {
                    if (AssetRegistry.IsContentType(memberContent.Type))
                    {
                        var id = AttachedReferenceManager.GetAttachedReference(memberContent.Retrieve())?.Id ?? AssetId.Empty;
                        CollectContentReference(id, gameContent, NodeIndex.Empty);
                    }
                }
                var objectNode = node as IObjectNode;
                if (objectNode != null && objectNode.Indices != null)
                {
                    if (AssetRegistry.IsContentType(objectNode.Descriptor.GetInnerCollectionType()))
                    {
                        foreach (var index in objectNode.Indices)
                        {
                            var id = AttachedReferenceManager.GetAttachedReference(objectNode.Retrieve(index))?.Id ?? AssetId.Empty;
                            CollectContentReference(id, gameContent, index);
                        }
                    }
                }
            }
            base.VisitNode(node);
        }
Ejemplo n.º 8
0
        /// <inheritdoc/>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var attachedReference = AttachedReferenceManager.GetAttachedReference(value);
            var destinationType   = TypeConverterHelper.GetDestinationType(context);

            return(UrlReferenceHelper.CreateReference(destinationType, attachedReference.Id, attachedReference.Url));
        }
Ejemplo n.º 9
0
 public IEnumerable <IContentReference> GetDependencies()
 {
     if (CubeMap != null)
     {
         var reference = AttachedReferenceManager.GetAttachedReference(CubeMap);
         yield return(new AssetReference <TextureAsset>(reference.Id, reference.Url));
     }
 }
Ejemplo n.º 10
0
 public IEnumerable <IReference> EnumerateCompileTimeDependencies(PackageSession session)
 {
     foreach (var shapeDesc in ColliderShapes.OfType <ConvexHullColliderShapeDesc>())
     {
         var reference = AttachedReferenceManager.GetAttachedReference(shapeDesc.Model);
         yield return(new AssetReference(reference.Id, reference.Url));
     }
 }
Ejemplo n.º 11
0
            public override void VisitObjectMember(object container, ObjectDescriptor containerDescriptor, IMemberDescriptor member, object value)
            {
                base.VisitObjectMember(container, containerDescriptor, member, value);
                var assetReference    = value as AssetReference;
                var assetBase         = value as AssetBase;
                var attachedReference = value != null?AttachedReferenceManager.GetAttachedReference(value) : null;

                if (assetReference != null)
                {
                    AddLink(assetReference,
                            (guid, location) =>
                    {
                        var newValue = AssetReference.New(member.Type, guid.HasValue ? guid.Value : assetReference.Id, location);
                        member.Set(container, newValue);
                        return(newValue);
                    });
                }
                else if (assetBase != null)
                {
                    AddLink(assetBase,
                            (guid, location) =>
                    {
                        var newValue = new AssetBase(location, assetBase.Asset);
                        member.Set(container, newValue);
                        return(newValue);
                    });
                }
                else if (attachedReference != null)
                {
                    AddLink(new AttachedContentReference(attachedReference),
                            (guid, location) =>
                    {
                        object newValue = guid.HasValue && guid.Value != Guid.Empty ? AttachedReferenceManager.CreateSerializableVersion(member.Type, guid.Value, location) : null;
                        member.Set(container, newValue);
                        return(newValue);
                    });
                }
                else if (value is UFile)
                {
                    AddLink(value,
                            (guid, location) =>
                    {
                        var newValue = new UFile(location);
                        member.Set(container, newValue);
                        return(newValue);
                    });
                }
                else if (value is UDirectory)
                {
                    AddLink(value,
                            (guid, location) =>
                    {
                        var newValue = new UDirectory(location);
                        member.Set(container, newValue);
                        return(newValue);
                    });
                }
            }
Ejemplo n.º 12
0
            public override void VisitDictionaryKeyValue(object dictionaryObj, DictionaryDescriptor descriptor, object key, ITypeDescriptor keyDescriptor, object value, ITypeDescriptor valueDescriptor)
            {
                base.VisitDictionaryKeyValue(dictionaryObj, descriptor, key, keyDescriptor, value, valueDescriptor);
                var assetReference    = value as AssetReference;
                var assetBase         = value as AssetBase;
                var attachedReference = value != null?AttachedReferenceManager.GetAttachedReference(value) : null;

                if (assetReference != null)
                {
                    AddLink(assetReference,
                            (guid, location) =>
                    {
                        var newValue = AssetReference.New(descriptor.ValueType, guid.HasValue ? guid.Value : assetReference.Id, location);
                        descriptor.SetValue(dictionaryObj, key, newValue);
                        return(newValue);
                    });
                }
                else if (assetBase != null)
                {
                    AddLink(assetBase,
                            (guid, location) =>
                    {
                        var newValue = new AssetBase(location, assetBase.Asset);
                        descriptor.SetValue(dictionaryObj, key, newValue);
                        return(newValue);
                    });
                }
                else if (attachedReference != null)
                {
                    AddLink(new AttachedContentReference(attachedReference),
                            (guid, location) =>
                    {
                        object newValue = guid.HasValue && guid.Value != Guid.Empty ? AttachedReferenceManager.CreateSerializableVersion(descriptor.ValueType, guid.Value, location) : null;
                        descriptor.SetValue(dictionaryObj, key, newValue);
                        return(newValue);
                    });
                }
                else if (value is UFile)
                {
                    AddLink(value,
                            (guid, location) =>
                    {
                        var newValue = new UFile(location);
                        descriptor.SetValue(dictionaryObj, key, newValue);
                        return(newValue);
                    });
                }
                else if (value is UDirectory)
                {
                    AddLink(value,
                            (guid, location) =>
                    {
                        var newValue = new UDirectory(location);
                        descriptor.SetValue(dictionaryObj, key, newValue);
                        return(newValue);
                    });
                }
            }
Ejemplo n.º 13
0
            public override void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
            {
                base.VisitArrayItem(array, descriptor, index, item, itemDescriptor);
                var assetReference    = item as AssetReference;
                var assetBase         = item as AssetBase;
                var attachedReference = item != null?AttachedReferenceManager.GetAttachedReference(item) : null;

                if (assetReference != null)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = AssetReference.New(descriptor.ElementType, guid.HasValue ? guid.Value : assetReference.Id, location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (assetBase != null)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = new AssetBase(location, assetBase.Asset);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (attachedReference != null)
                {
                    AddLink(new AttachedContentReference(attachedReference),
                            (guid, location) =>
                    {
                        object newValue = guid.HasValue && guid.Value != Guid.Empty ? AttachedReferenceManager.CreateSerializableVersion(descriptor.ElementType, guid.Value, location) : null;
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (item is UFile)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = new UFile(location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
                else if (item is UDirectory)
                {
                    AddLink(item,
                            (guid, location) =>
                    {
                        var newValue = new UFile(location);
                        array.SetValue(newValue, index);
                        return(newValue);
                    });
                }
            }
Ejemplo n.º 14
0
        /// <inheritdoc/>
        public IEnumerable <IReference> EnumerateCompileTimeDependencies(PackageSession session)
        {
            var reference = AttachedReferenceManager.GetAttachedReference(Skeleton);

            if (reference != null)
            {
                yield return(new AssetReference <Asset>(reference.Id, reference.Url));
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Finds an asset from its attached reference.
        /// It will first try by id, then location.
        /// </summary>
        /// <param name="package">The package.</param>
        /// <param name="obj">The object containing the attached reference.</param>
        /// <returns>An <see cref="AssetItem" /> or <c>null</c> if not found.</returns>
        public static AssetItem FindAssetFromAttachedReference(this Package package, object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            var attachedReference = AttachedReferenceManager.GetAttachedReference(obj);

            return(attachedReference != null?package.FindAsset(attachedReference) : null);
        }
Ejemplo n.º 16
0
 public IEnumerable <AssetReference <MaterialAsset> > FindMaterialReferences()
 {
     foreach (var layer in Layers)
     {
         if (layer.Material != null)
         {
             var reference = AttachedReferenceManager.GetAttachedReference(layer.Material);
             yield return(new AssetReference <MaterialAsset>(reference.Id, reference.Url));
         }
     }
 }
Ejemplo n.º 17
0
        public static AssetItem FindAssetFromAttachedReference(this PackageSession session, object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var reference = AttachedReferenceManager.GetAttachedReference(obj);

            return(reference != null ? (FindAsset(session, reference.Id) ?? FindAsset(session, reference.Url)) : null);
        }
Ejemplo n.º 18
0
        public override string ConvertTo(ref ObjectContext objectContext)
        {
            var attachedReference = AttachedReferenceManager.GetAttachedReference(objectContext.Instance);

            if (attachedReference == null)
            {
                throw new YamlException(string.Format("Unable to extract asset reference from object [{0}]", objectContext.Instance));
            }

            return(string.Format("{0}:{1}", attachedReference.Id, attachedReference.Url));
        }
Ejemplo n.º 19
0
        public override string ConvertTo(ref ObjectContext objectContext)
        {
            var attachedReference = AttachedReferenceManager.GetAttachedReference(objectContext.Instance);

            if (attachedReference == null)
            {
                throw new YamlException($"Unable to extract asset reference from object [{objectContext.Instance}]");
            }

            return($"{attachedReference.Id}:{attachedReference.Url}");
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Retrieves the view model corresponding to the asset referenced by the <paramref name="source"/> parameter.
        /// </summary>
        /// <param name="session">The session view model to use to retrieve the asset view model.</param>
        /// <param name="source">The source of the reference.</param>
        /// <returns>The view model corresponding to the referenced asset if found, null otherwise.</returns>
        /// <remarks>The <paramref name="source"/> parameter must either be an <see cref="AssetReference"/>, or a proxy object of an <see cref="AttachedReference"/>.</remarks>
        public static AssetViewModel GetReferenceTarget(SessionViewModel session, object source)
        {
            var assetReference = source as AssetReference;

            if (assetReference != null)
            {
                return(session.GetAssetById(assetReference.Id));
            }
            var reference = AttachedReferenceManager.GetAttachedReference(source);

            return(reference != null?session.GetAssetById(reference.Id) : null);
        }
Ejemplo n.º 21
0
        public IEnumerable <IReference> EnumerateCompileTimeDependencies(PackageSession session)
        {
            if (Prefab != null)
            {
                // Return the prefab itself
                yield return(Prefab);

                // Then we need to return used models and materials because they affects how the meshes are generated
                var prefab = session.FindAsset(Prefab.Location)?.Asset as PrefabAsset;
                if (prefab != null)
                {
                    // Use a dictionary to ensure each reference is yielded only once
                    var references = new Dictionary <Guid, IReference>();
                    foreach (var entity in prefab.Hierarchy.Parts)
                    {
                        // Gather all entities with a model component and a valid model
                        var modelComponent = entity.Entity.Get <ModelComponent>();
                        if (modelComponent?.Model != null)
                        {
                            var modelReference = AttachedReferenceManager.GetAttachedReference(modelComponent.Model);
                            var model          = session.FindAsset(modelReference.Url)?.Asset as IModelAsset;
                            if (model != null)
                            {
                                // Build the list of material for this model
                                var materialList = model.Materials.Select(x => x.MaterialInstance.Material).ToList();
                                for (var i = 0; i < modelComponent.Materials.Count && i < materialList.Count; i++)
                                {
                                    // Apply any material override from the model component
                                    var material = modelComponent.Materials[i];
                                    if (material != null)
                                    {
                                        materialList[i] = material;
                                    }
                                }

                                // Add the model and the related materials to the list of reference
                                references[modelReference.Id] = modelReference;
                                foreach (var material in materialList)
                                {
                                    var materialReference = AttachedReferenceManager.GetAttachedReference(material);
                                    references[materialReference.Id] = materialReference;
                                }
                            }
                        }
                    }
                    // Finally return all the referenced models and materials
                    foreach (var reference in references.Values)
                    {
                        yield return(reference);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // Empty reference or different values
            if (value == null || value == NodeViewModel.DifferentValues)
            {
                return(null);
            }

            var contentReference = value as IReference ?? AttachedReferenceManager.GetAttachedReference(value);

            return(contentReference != null?SessionViewModel.Instance.GetAssetById(contentReference.Id) : null);
        }
Ejemplo n.º 23
0
            private void EnsureClonedSceneAndHash()
            {
                if (!sceneCloned)
                {
                    // Hash relevant scene objects
                    if (asset.Scene != null)
                    {
                        string sceneUrl   = AttachedReferenceManager.GetUrl(asset.Scene);
                        var    sceneAsset = (SceneAsset)package.Session.FindAsset(sceneUrl)?.Asset;

                        // Clone scene asset because we update the world transformation matrices
                        clonedSceneAsset = (SceneAsset)AssetCloner.Clone(sceneAsset);

                        // Turn the entire entity hierarchy into a single list
                        sceneEntities = clonedSceneAsset.Hierarchy.Parts.Select(x => x.Entity).ToList();

                        sceneHash = 0;
                        foreach (var entity in sceneEntities)
                        {
                            StaticColliderComponent collider = entity.Get <StaticColliderComponent>();

                            // Only process enabled colliders
                            bool colliderEnabled = collider != null && ((CollisionFilterGroupFlags)collider.CollisionGroup & asset.IncludedCollisionGroups) != 0 && collider.Enabled;
                            if (colliderEnabled) // Removed or disabled
                            {
                                // Update world transform before hashing
                                entity.Transform.UpdateWorldMatrix();

                                // Load collider shape assets since the scene asset is being used, which does not have these loaded by default
                                foreach (var desc in collider.ColliderShapes)
                                {
                                    var shapeAssetDesc = desc as ColliderShapeAssetDesc;
                                    if (shapeAssetDesc?.Shape != null)
                                    {
                                        var assetReference = AttachedReferenceManager.GetAttachedReference(shapeAssetDesc.Shape);
                                        PhysicsColliderShape loadedColliderShape;
                                        if (!loadedColliderShapes.TryGetValue(assetReference.Url, out loadedColliderShape))
                                        {
                                            loadedColliderShape = contentManager.Load <PhysicsColliderShape>(assetReference.Url);
                                            loadedColliderShapes.Add(assetReference.Url, loadedColliderShape); // Store where we loaded the shapes from
                                        }
                                        shapeAssetDesc.Shape = loadedColliderShape;
                                    }
                                }

                                // Finally compute the hash for this collider
                                sceneHash += NavigationMeshBuildUtils.HashEntityCollider(collider);
                            }
                        }
                    }
                    sceneCloned = true;
                }
            }
Ejemplo n.º 24
0
        public override IEnumerable <ObjectUrl> GetInputFiles(AssetItem assetItem)
        {
            var asset = (NavigationMeshAsset)assetItem.Asset;

            if (asset.Scene != null)
            {
                string sceneUrl   = AttachedReferenceManager.GetUrl(asset.Scene);
                var    sceneAsset = (SceneAsset)assetItem.Package.Session.FindAsset(sceneUrl)?.Asset;
                if (sceneAsset == null)
                {
                    yield break;
                }

                var sceneEntities = sceneAsset.Hierarchy.Parts.Select(x => x.Value.Entity).ToList();
                foreach (var entity in sceneEntities)
                {
                    var collider = entity.Get <StaticColliderComponent>();

                    // Only process enabled colliders
                    bool colliderEnabled = collider != null && ((CollisionFilterGroupFlags)collider.CollisionGroup & asset.IncludedCollisionGroups) != 0 && collider.Enabled;
                    if (colliderEnabled) // Removed or disabled
                    {
                        foreach (var desc in collider.ColliderShapes)
                        {
                            var shapeAssetDesc = desc as ColliderShapeAssetDesc;
                            if (shapeAssetDesc?.Shape != null)
                            {
                                var assetReference = AttachedReferenceManager.GetAttachedReference(shapeAssetDesc.Shape);
                                if (assetReference != null)
                                {
                                    yield return(new ObjectUrl(UrlType.Content, assetReference.Url));
                                }
                            }
                            else if (desc is HeightfieldColliderShapeDesc)
                            {
                                var heightfieldDesc = desc as HeightfieldColliderShapeDesc;
                                var heightmapSource = heightfieldDesc?.HeightStickArraySource as HeightStickArraySourceFromHeightmap;

                                if (heightmapSource?.Heightmap != null)
                                {
                                    var url = AttachedReferenceManager.GetUrl(heightmapSource.Heightmap);

                                    if (!string.IsNullOrEmpty(url))
                                    {
                                        yield return(new ObjectUrl(UrlType.Content, url));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 25
0
        public override string ConvertTo(ref ObjectContext objectContext)
        {
            var attachedReference = AttachedReferenceManager.GetAttachedReference(objectContext.Instance);

            if (attachedReference == null)
            {
                throw new YamlException(string.Format("Unable to extract asset reference from object [{0}]", objectContext.Instance));
            }

            var referenceId = IdentifiableHelper.GetId(objectContext.Instance);

            return($"{referenceId}/{attachedReference.Id}:{attachedReference.Url}");
        }
Ejemplo n.º 26
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, EntityAsset asset, AssetCompilerResult result)
        {
            foreach (var entityData in asset.Hierarchy.Entities)
            {
                // TODO: How to make this code pluggable?
                var modelComponent  = entityData.Components.Get(ModelComponent.Key);
                var spriteComponent = entityData.Components.Get(SpriteComponent.Key);
                var scriptComponent = entityData.Components.Get(ScriptComponent.Key);

                // determine the underlying source asset exists
                if (modelComponent != null)
                {
                    if (modelComponent.Model == null)
                    {
                        result.Warning(string.Format("The entity [{0}:{1}] has a model component that does not reference any model.", urlInStorage, entityData.Name));
                        continue;
                    }

                    var modelAttachedReference = AttachedReferenceManager.GetAttachedReference(modelComponent.Model);
                    var modelId = modelAttachedReference.Id;

                    // compute the full path to the source asset.
                    var assetItem = AssetItem.Package.Session.FindAsset(modelId);
                    if (assetItem == null)
                    {
                        result.Error(string.Format("The entity [{0}:{1}] is referencing an unreachable model.", urlInStorage, entityData.Name));
                        continue;
                    }
                }
                if (spriteComponent != null && spriteComponent.SpriteProvider == null)
                {
                    result.Warning(string.Format("The entity [{0}:{1}] has a sprite component that does not reference any sprite group.", urlInStorage, entityData.Name));
                }
                if (scriptComponent != null)
                {
                    foreach (var script in scriptComponent.Scripts)
                    {
                        if (script is UnloadableScript)
                        {
                            result.Error(string.Format("The entity [{0}:{1}] reference an invalid script '{2}'.", urlInStorage, entityData.Name, script.GetType().Name));
                        }
                    }
                }
            }

            result.BuildSteps = new AssetBuildStep(AssetItem)
            {
                new EntityCombineCommand(urlInStorage, AssetItem.Package, context, asset)
            };
        }
        public static void AddLoadingFromSession(this ShaderGeneratorContextBase context, Package package)
        {
            var previousGetAssetFriendlyName = context.GetAssetFriendlyName;
            var previousFindAsset            = context.FindAsset;

            // Setup the GetAssetFriendlyName callback
            context.GetAssetFriendlyName = runtimeAsset =>
            {
                string assetFriendlyName = null;

                if (previousGetAssetFriendlyName != null)
                {
                    assetFriendlyName = previousGetAssetFriendlyName(runtimeAsset);
                }

                if (string.IsNullOrEmpty(assetFriendlyName))
                {
                    var referenceAsset = AttachedReferenceManager.GetAttachedReference(runtimeAsset);
                    assetFriendlyName = string.Format("{0}:{1}", referenceAsset.Id, referenceAsset.Url);
                }

                return(assetFriendlyName);
            };

            // Setup the FindAsset callback
            context.FindAsset = runtimeAsset =>
            {
                object newAsset = null;
                if (previousFindAsset != null)
                {
                    newAsset = previousFindAsset(runtimeAsset);
                }

                if (newAsset != null)
                {
                    return(newAsset);
                }

                var reference = AttachedReferenceManager.GetAttachedReference(runtimeAsset);


                var assetItem = package.Session.FindAsset(reference.Id) ?? package.Session.FindAsset(reference.Url);

                if (assetItem == null)
                {
                    return(null);
                }
                return(assetItem.Asset);
            };
        }
Ejemplo n.º 28
0
            public override void VisitCollectionItem(IEnumerable collection, CollectionDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
            {
                base.VisitCollectionItem(collection, descriptor, index, item, itemDescriptor);
                var assetReference    = item as AssetReference;
                var attachedReference = AttachedReferenceManager.GetAttachedReference(item);

                // We cannot set links if we do not have indexer accessor
                if (!descriptor.HasIndexerAccessors)
                {
                    return;
                }

                if (assetReference != null)
                {
                    AddLink(assetReference, (guid, location) =>
                    {
                        var link = AssetReference.New(guid ?? assetReference.Id, location);
                        descriptor.SetValue(collection, index, link);
                        return(link);
                    });
                }
                else if (attachedReference != null)
                {
                    AddLink(attachedReference, (guid, location) =>
                    {
                        var link = guid.HasValue && guid.Value != AssetId.Empty ? AttachedReferenceManager.CreateProxyObject(descriptor.ElementType, guid.Value, location) : null;
                        descriptor.SetValue(collection, index, link);
                        return(link);
                    });
                }
                else if (item is UFile)
                {
                    AddLink(item, (guid, location) =>
                    {
                        var link = new UFile(location);
                        descriptor.SetValue(collection, index, link);
                        return(link);
                    });
                }
                else if (item is UDirectory)
                {
                    AddLink(item, (guid, location) =>
                    {
                        var link = new UDirectory(location);
                        descriptor.SetValue(collection, index, link);
                        return(link);
                    });
                }
            }
        private async Task ReloadGraphicsCompositor(bool forceIfSame)
        {
            var graphicsCompositorId    = AttachedReferenceManager.GetAttachedReference(settingsProvider.CurrentGameSettings.GraphicsCompositor)?.Id;
            var graphicsCompositorAsset = (GraphicsCompositorViewModel)(graphicsCompositorId.HasValue ? editor.Session.GetAssetById(graphicsCompositorId.Value) : null);

            // Same compositor as before?
            if (graphicsCompositorAsset == currentGraphicsCompositorAsset && !forceIfSame)
            {
                return;
            }

            // TODO: Start listening for changes in this compositor
            currentGraphicsCompositorAsset = graphicsCompositorAsset;

            // TODO: If nothing, fallback to default compositor, or stop rendering?
            if (graphicsCompositorAsset == null)
            {
                return;
            }

            // TODO: Prevent reentrency
            var database = editor.ServiceProvider.Get <GameStudioDatabase>();
            await database.Build(graphicsCompositorAsset.AssetItem);

            await controller.InvokeTask(async() =>
            {
                using (await database.MountInCurrentMicroThread())
                {
                    // Unlaod previous graphics compositor
                    if (loadedGraphicsCompositor != null)
                    {
                        game.Content.Unload(loadedGraphicsCompositor);
                        loadedGraphicsCompositor = null;
                    }
                    else
                    {
                        // Should only happen when graphics compositor is fallback one (i.e. first load or failure)
                        game.SceneSystem.GraphicsCompositor?.Dispose();
                    }

                    game.SceneSystem.GraphicsCompositor = null;

                    // Load and set new graphics compositor
                    loadedGraphicsCompositor = game.Content.Load <GraphicsCompositor>(graphicsCompositorAsset.AssetItem.Location);
                    game.UpdateGraphicsCompositor(loadedGraphicsCompositor);
                }
            });
        }
Ejemplo n.º 30
0
            public override void VisitObjectMember(object container, ObjectDescriptor containerDescriptor, IMemberDescriptor member, object value)
            {
                base.VisitObjectMember(container, containerDescriptor, member, value);
                var assetReference    = value as AssetReference;
                var attachedReference = AttachedReferenceManager.GetAttachedReference(value);

                if (assetReference != null)
                {
                    AddLink(assetReference,
                            (guid, location) =>
                    {
                        var newValue = AssetReference.New(guid ?? assetReference.Id, location);
                        member.Set(container, newValue);
                        return(newValue);
                    });
                }
                else if (attachedReference != null)
                {
                    AddLink(attachedReference,
                            (guid, location) =>
                    {
                        object newValue = guid.HasValue && guid.Value != AssetId.Empty ? AttachedReferenceManager.CreateProxyObject(member.Type, guid.Value, location) : null;
                        member.Set(container, newValue);
                        return(newValue);
                    });
                }
                else if (value is UFile)
                {
                    AddLink(value,
                            (guid, location) =>
                    {
                        var newValue = new UFile(location);
                        member.Set(container, newValue);
                        return(newValue);
                    });
                }
                else if (value is UDirectory)
                {
                    AddLink(value,
                            (guid, location) =>
                    {
                        var newValue = new UDirectory(location);
                        member.Set(container, newValue);
                        return(newValue);
                    });
                }
            }