Example #1
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)
            };
        }
Example #2
0
        protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var asset = (T)assetItem.Asset;

            foreach (var entityData in asset.Hierarchy.Parts.Values)
            {
                // TODO: How to make this code pluggable?
                var modelComponent = entityData.Entity.Components.Get <ModelComponent>();
                if (modelComponent != null)
                {
                    if (modelComponent.Model == null)
                    {
                        result.Warning($"The entity [{targetUrlInStorage}:{entityData.Entity.Name}] has a model component that does not reference any model.");
                    }
                    else
                    {
                        var modelAttachedReference = AttachedReferenceManager.GetAttachedReference(modelComponent.Model);
                        var modelId = modelAttachedReference.Id;

                        // compute the full path to the source asset.
                        var modelAssetItem = assetItem.Package.Session.FindAsset(modelId);
                        if (modelAssetItem == null)
                        {
                            result.Error($"The entity [{targetUrlInStorage}:{entityData.Entity.Name}] is referencing an unreachable model.");
                        }
                    }
                }

                var nodeLinkComponent = entityData.Entity.Components.Get <ModelNodeLinkComponent>();
                if (nodeLinkComponent != null)
                {
                    nodeLinkComponent.ValidityCheck();
                    if (!nodeLinkComponent.IsValid)
                    {
                        result.Warning($"The Model Node Link between {entityData.Entity.Name} and {nodeLinkComponent.Target?.Entity.Name} is invalid.");
                        nodeLinkComponent.Target = null;
                    }
                }
            }

            result.BuildSteps = new AssetBuildStep(assetItem);
            result.BuildSteps.Add(Create(targetUrlInStorage, asset, assetItem.Package));
        }
        /// <inheritdoc/>
        public void Check(EntityComponent component, Entity entity, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var nodeLinkComponent = component as ModelNodeLinkComponent;

            nodeLinkComponent.ValidityCheck();
            if (!nodeLinkComponent.IsValid)
            {
                result.Warning($"The Model Node Link between {entity.Name} and {nodeLinkComponent.Target?.Entity.Name} is invalid.");
                nodeLinkComponent.Target = null;
            }
        }
Example #4
0
        protected override void Compile(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var asset = (T)assetItem.Asset;

            foreach (var entityData in asset.Hierarchy.Parts)
            {
                // TODO: How to make this code pluggable?
                var modelComponent  = entityData.Entity.Components.Get <ModelComponent>();
                var spriteComponent = entityData.Entity.Components.Get <SpriteComponent>();

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

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

                    // compute the full path to the source asset.
                    var modelAssetItem = assetItem.Package.Session.FindAsset(modelId);
                    if (modelAssetItem == null)
                    {
                        result.Error($"The entity [{targetUrlInStorage}:{entityData.Entity.Name}] is referencing an unreachable model.");
                        continue;
                    }
                }
                if (spriteComponent != null && spriteComponent.SpriteProvider == null)
                {
                    result.Warning($"The entity [{targetUrlInStorage}:{entityData.Entity.Name}] has a sprite component that does not reference any sprite group.");
                }
            }

            result.BuildSteps = new AssetBuildStep(assetItem)
            {
                Create(targetUrlInStorage, asset)
            };
        }
        private void WriteResult(AssetCompilerResult result, string componentName, string targetUrlInStorage, string entityName, string memberName, MemberRequiredReportType reportType)
        {
            var logMsg = $"The component {componentName} on entity [{targetUrlInStorage}:{entityName}] is missing a value on a required field '{memberName}'.";

            switch (reportType)
            {
            case MemberRequiredReportType.Warning:
                result.Warning(logMsg);
                break;

            case MemberRequiredReportType.Error:
                result.Error(logMsg);
                break;
            }
        }
Example #6
0
        /// <inheritdoc/>
        public void Check(EntityComponent component, Entity entity, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var modelComponent = component as ModelComponent;
            if (modelComponent.Model == null)
            {
                result.Warning($"The entity [{targetUrlInStorage}:{entity.Name}] has a model component that does not reference any model.");
            }
            else
            {
                var modelAttachedReference = AttachedReferenceManager.GetAttachedReference(modelComponent.Model);
                var modelId = modelAttachedReference.Id;

                // compute the full path to the source asset.
                var modelAssetItem = assetItem.Package.Session.FindAsset(modelId);
                if (modelAssetItem == null)
                {
                    result.Error($"The entity [{targetUrlInStorage}:{entity.Name}] is referencing an unreachable model.");
                }
            }
        }