コード例 #1
0
 /// <summary>
 /// Returns the absolute path on the disk of an <see cref="UFile"/> that is relative to the asset location.
 /// </summary>
 /// <param name="assetItem">The asset on which is based the relative path.</param>
 /// <param name="relativePath">The path relative to the asset path that must be converted to an absolute path.</param>
 /// <returns>The absolute path on the disk of the <see cref="relativePath"/> argument.</returns>
 /// <exception cref="ArgumentException">The <see cref="relativePath"/> argument is a null or empty <see cref="UFile"/>.</exception>
 protected static UFile GetAbsolutePath(AssetItem assetItem, UFile relativePath)
 {
     if (string.IsNullOrEmpty(relativePath)) throw new ArgumentException("The relativePath argument is null or empty");
     var assetDirectory = assetItem.FullPath.GetParent();
     var assetSource = UPath.Combine(assetDirectory, relativePath);
     return assetSource;
 }
コード例 #2
0
        public object Load(Stream stream, UFile filePath, ILogger log, out bool aliasOccurred, out Dictionary<YamlAssetPath, OverrideType> overrides)
        {
            aliasOccurred = false;

            var assetFileExtension = filePath.GetFileExtension().ToLowerInvariant();
            var type = AssetRegistry.GetAssetTypeFromFileExtension(assetFileExtension);
            var asset = (SourceCodeAsset)Activator.CreateInstance(type);

            var textAccessor = asset.TextAccessor as SourceCodeAsset.DefaultTextAccessor;
            if (textAccessor != null)
            {
                // Don't load the file if we have the file path
                textAccessor.FilePath = filePath;

                // Set the assets text if it loaded from an in-memory version
                // TODO: Propagate dirtiness?
                if (stream is MemoryStream)
                {
                    var reader = new StreamReader(stream, Encoding.UTF8);
                    textAccessor.Set(reader.ReadToEnd());
                }
            }

            // No override in source code assets
            overrides = new Dictionary<YamlAssetPath, OverrideType>();

            return asset;
        }
コード例 #3
0
ファイル: AssetToImport.cs プロジェクト: h78hy78yhoi8j/xenko
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetToImport"/> class.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <exception cref="System.ArgumentNullException">file</exception>
 internal AssetToImport(UFile file)
 {
     if (file == null) throw new ArgumentNullException("file");
     this.file = file;
     ByImporters = new List<AssetToImportByImporter>();
     Enabled = true;
 }
コード例 #4
0
ファイル: IAssetImporter.cs プロジェクト: Powerino73/paradox
        public static bool IsSupportingFile(this IAssetImporter importer, UFile file)
        {
            if (file == null) throw new ArgumentNullException("file");
            if (file.GetFileExtension() == null) return false;

            return FileUtility.GetFileExtensionsAsSet(importer.SupportedFileExtensions).Contains(file.GetFileExtension());
        }
コード例 #5
0
ファイル: SettingsEntry.cs プロジェクト: h78hy78yhoi8j/xenko
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsEntry"/> class.
 /// </summary>
 /// <param name="profile">The profile this <see cref="SettingsEntry"/>belongs to.</param>
 /// <param name="name">The name associated to this <see cref="SettingsEntry"/>.</param>
 protected SettingsEntry(SettingsProfile profile, UFile name)
 {
     if (profile == null) throw new ArgumentNullException("profile");
     if (name == null) throw new ArgumentNullException("name");
     Profile = profile;
     Name = name;
 }
コード例 #6
0
        public static EntityHierarchyData ImportScene(UFile sourceUrl, EntityGroupAssetBase source, Guid sourceRootEntity)
        {
            if (source == null) throw new ArgumentNullException("source");

            // Extract the scene starting from given root
            var newAsset = ExtractSceneClone(source, sourceRootEntity);

            // Generate entity mapping
            var reverseEntityMapping = new Dictionary<Guid, Guid>();
            foreach (var entityDesign in newAsset.Hierarchy.Entities)
            {
                // Generate new Id
                var newEntityId = Guid.NewGuid();

                // Update mappings
                reverseEntityMapping.Add(entityDesign.Entity.Id, newEntityId);

                // Update entity with new id
                entityDesign.Entity.Id = newEntityId;
            }

            // Rewrite entity references
            // Should we nullify invalid references?
            EntityAnalysis.RemapEntitiesId(newAsset.Hierarchy, reverseEntityMapping);

            return newAsset.Hierarchy;
        }
コード例 #7
0
        public void TestUpdateAssetUrl()
        {
            var projectDir = new UFile(Path.Combine(Environment.CurrentDirectory, "testxk"));
            
            // Create a project with an asset reference a raw file
            var project = new Package { FullPath = projectDir };
            var assetItem = new AssetItem("test", new AssetObjectTest() { Reference =  new AssetReference<AssetObjectTest>(Guid.Empty, "good/location")});
            project.Assets.Add(assetItem);
            var goodAsset = new AssetObjectTest();
            project.Assets.Add(new AssetItem("good/location", goodAsset));

            // Add the project to the session to make sure analysis will run correctly
            var session = new PackageSession(project);

            // Create a session with this project
            var analysis = new PackageAnalysis(project,
                new PackageAnalysisParameters()
                    {
                        IsProcessingAssetReferences = true,
                        ConvertUPathTo = UPathType.Absolute,
                        IsProcessingUPaths = true
                    });
            var result = analysis.Run();
            Assert.IsFalse(result.HasErrors);
            Assert.AreEqual(1, result.Messages.Count);
            Assert.IsTrue(result.Messages[0].ToString().Contains("changed"));

            var asset = (AssetObjectTest)assetItem.Asset;
            Assert.AreEqual(goodAsset.Id, asset.Reference.Id);
            Assert.AreEqual("good/location", asset.Reference.Location);
        }
コード例 #8
0
        protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandContext)
        {
            // This path for effects xml is now part of this tool, but it should be done in a separate exporter?
            using (var inputStream = File.OpenRead(SourcePath))
            using (var outputStream = AssetManager.FileProvider.OpenStream(Location, VirtualFileMode.Create, VirtualFileAccess.Write))
            {
                inputStream.CopyTo(outputStream);

                var objectURL = new ObjectUrl(UrlType.ContentLink, Location);

                if (DisableCompression)
                    commandContext.AddTag(objectURL, DisableCompressionSymbol);
            }

            if (SaveSourcePath)
            {
                // store absolute path to source
                // TODO: the "/path" is hardcoded, used in EffectSystem and ShaderSourceManager. Find a place to share this correctly.
                var pathLocation = new UFile(Location.FullPath + "/path");
                using (var outputStreamPath = AssetManager.FileProvider.OpenStream(pathLocation, VirtualFileMode.Create, VirtualFileAccess.Write))
                {
                    using (var sw = new StreamWriter(outputStreamPath))
                    {
                        sw.Write(SourcePath.FullPath);
                    }
                }
            }

            return Task.FromResult(ResultStatus.Successful);
        }
コード例 #9
0
 public object Load(Stream stream, UFile filePath, ILogger log, out bool aliasOccurred, out Dictionary<YamlAssetPath, OverrideType> overrides)
 {
     PropertyContainer properties;
     var result = AssetYamlSerializer.Default.Deserialize(stream, null, log != null ? new SerializerContextSettings { Logger = log } : null, out aliasOccurred, out properties);
     properties.TryGetValue(AssetObjectSerializerBackend.OverrideDictionaryKey, out overrides);
     return result;
 }
コード例 #10
0
ファイル: SettingsKey.cs プロジェクト: robterrell/paradox
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsKey"/> class.
 /// </summary>
 /// <param name="name">The name of this settings key. Must be unique amongst the application.</param>
 /// <param name="group">The <see cref="SettingsGroup"/> containing this <see cref="SettingsKey"/>.</param>
 /// <param name="defaultValueCallback">A function that returns the default value associated to this settings key.</param>
 protected SettingsKey(UFile name, SettingsGroup group, Func<object> defaultValueCallback)
 {
     Name = name;
     DisplayName = name;
     DefaultObjectValueCallback = defaultValueCallback;
     Group = group;
     Group.RegisterSettingsKey(name, defaultValueCallback(), this);
 }
コード例 #11
0
ファイル: SettingsKey.cs プロジェクト: robterrell/paradox
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsKey"/> class.
 /// </summary>
 /// <param name="name">The name of this settings key. Must be unique amongst the application.</param>
 /// <param name="group">The <see cref="SettingsGroup"/> containing this <see cref="SettingsKey"/>.</param>
 /// <param name="defaultValue">The default value associated to this settings key.</param>
 protected SettingsKey(UFile name, SettingsGroup group, object defaultValue)
 {
     Name = name;
     DisplayName = name;
     DefaultObjectValue = defaultValue;
     Group = group;
     Group.RegisterSettingsKey(name, defaultValue, this);
 }
コード例 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageLoadingAssetFile" /> class.
        /// </summary>
        /// <param name="package">The package this asset will be part of.</param>
        /// <param name="filePath">The relative file path (from default asset folder).</param>
        /// <param name="sourceFolder">The source folder (optional, can be null).</param>
        /// <exception cref="System.ArgumentException">filePath must be relative</exception>
        public PackageLoadingAssetFile(Package package, UFile filePath, UDirectory sourceFolder)
        {
            if (filePath.IsAbsolute)
                throw new ArgumentException("filePath must be relative", filePath);

            SourceFolder = UPath.Combine(package.RootDirectory, sourceFolder ?? package.GetDefaultAssetFolder());
            FilePath = UPath.Combine(SourceFolder, filePath);
        }
コード例 #13
0
ファイル: SettingsKey.cs プロジェクト: h78hy78yhoi8j/xenko
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsKey"/> class.
 /// </summary>
 /// <param name="name">The name of this settings key. Must be unique amongst the application.</param>
 /// <param name="container">The <see cref="SettingsContainer"/> containing this <see cref="SettingsKey"/>.</param>
 /// <param name="defaultValueCallback">A function that returns the default value associated to this settings key.</param>
 protected SettingsKey(UFile name, SettingsContainer container, Func<object> defaultValueCallback)
 {
     Name = name;
     DisplayName = name;
     DefaultObjectValueCallback = defaultValueCallback;
     Container = container;
     Container.RegisterSettingsKey(name, defaultValueCallback(), this);
 }
コード例 #14
0
ファイル: SettingsKey.cs プロジェクト: h78hy78yhoi8j/xenko
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsKey"/> class.
 /// </summary>
 /// <param name="name">The name of this settings key. Must be unique amongst the application.</param>
 /// <param name="container">The <see cref="SettingsContainer"/> containing this <see cref="SettingsKey"/>.</param>
 /// <param name="defaultValue">The default value associated to this settings key.</param>
 protected SettingsKey(UFile name, SettingsContainer container, object defaultValue)
 {
     Name = name;
     DisplayName = name;
     DefaultObjectValue = defaultValue;
     Container = container;
     Container.RegisterSettingsKey(name, defaultValue, this);
 }
コード例 #15
0
        public virtual bool IsSupportingFile(string filePath)
        {
            if (filePath == null) throw new ArgumentNullException("filePath");
            var file = new UFile(filePath);
            if (file.GetFileExtension() == null) return false;

            return FileUtility.GetFileExtensionsAsSet(SupportedFileExtensions).Contains(file.GetFileExtension());
        }
コード例 #16
0
ファイル: ModelAssetImporter.cs プロジェクト: joewan/xenko
        /// <summary>
        /// Imports the model.
        /// </summary>
        /// <param name="localPath">The path of the asset.</param>
        /// <param name="importParameters">The parameters used to import the model.</param>
        /// <returns>A collection of assets.</returns>
        public override IEnumerable<AssetItem> Import(UFile localPath, AssetImporterParameters importParameters)
        {
            var rawAssetReferences = new List<AssetItem>(); // the asset references without subdirectory path

            var entityInfo = GetEntityInfo(localPath, importParameters.Logger);

            //var isImportingEntity = importParameters.IsTypeSelectedForOutput<EntityAsset>();

            var isImportingModel = importParameters.IsTypeSelectedForOutput<ModelAsset>();

            var isImportingMaterial = importParameters.IsTypeSelectedForOutput<MaterialAsset>() ||
                                      isImportingModel;

            var isImportingTexture = importParameters.IsTypeSelectedForOutput<TextureAsset>() ||
                                     isImportingMaterial;

            // 1. Textures
            if (isImportingTexture)
            {
                ImportTextures(entityInfo.TextureDependencies, rawAssetReferences);
            }

            // 2. Skeleton
            AssetItem skeletonAsset = null;
            if (importParameters.IsTypeSelectedForOutput<SkeletonAsset>())
            {
                skeletonAsset = ImportSkeleton(rawAssetReferences, localPath, localPath, entityInfo);
            }

            // 3. Animation
            if (importParameters.IsTypeSelectedForOutput<AnimationAsset>())
            {
                ImportAnimation(rawAssetReferences, localPath, entityInfo.AnimationNodes, isImportingModel, skeletonAsset);
            }

            // 4. Materials
            if (isImportingMaterial)
            {
                ImportMaterials(rawAssetReferences, entityInfo.Materials);
            }

            // 5. Model
            if (isImportingModel)
            {
                var modelItem = ImportModel(rawAssetReferences, localPath, localPath, entityInfo, false, skeletonAsset);

                // 5. Entity (currently disabled)
                //if (isImportingEntity)
                //{
                //    var entityAssetItem = ImportEntity(rawAssetReferences, localPath, modelItem);
                //
                //    // Apply EntityAnalysis 
                //    EntityAnalysis.UpdateEntityReferences(((EntityAsset)entityAssetItem.Asset).Hierarchy);
                //}
            }

            return rawAssetReferences;
        }
コード例 #17
0
ファイル: TextureImporter.cs プロジェクト: releed/paradox
        public override IEnumerable<AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters)
        {
            var asset = new TextureAsset { Source = rawAssetPath };

            // Creates the url to the texture
            var textureUrl = new UFile(rawAssetPath.GetFileName(), null);

            yield return new AssetItem(textureUrl, asset);
        }
コード例 #18
0
 /// <summary>
 /// Finds a name available for a new asset. This method will try to create a name based on an existing name and will append
 /// "_" + (number++) on every try. The new location found is added to the known existing locations.
 /// </summary>
 /// <param name="location">The location.</param>
 /// <param name="newLocation">The new location.</param>
 /// <returns><c>true</c> if there is a new location, <c>false</c> otherwise.</returns>
 public bool RegisterLocation(UFile location, out UFile newLocation)
 {
     newLocation = location;
     if (IsContainingLocation(location))
     {
         newLocation = NamingHelper.ComputeNewName(location, IsContainingLocation);
     }
     ExistingLocations.Add(newLocation);
     return newLocation != location;
 }
コード例 #19
0
        /// <inheritdoc/>
        protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandContext)
        {
            var gameSettings = context.GetGameSettingsAsset();

            // Find default scene URL
            var defaultSceneUrl = gameSettings.DefaultScene != null ? AttachedReferenceManager.GetUrl(gameSettings.DefaultScene) : null;
            if (defaultSceneUrl == null)
                return Task.FromResult(ResultStatus.Successful);

            var baseUrl = new UFile(defaultSceneUrl).GetParent();

            try
            {
                commandContext.Logger.Info($"Trying to compile effects for scene '{defaultSceneUrl}'");

                using (var sceneRenderer = new SceneRenderer(gameSettings))
                {
                    // Effect can be compiled asynchronously (since we don't have any fallback, they will have to be compiled in the same frame anyway)
                    // Also set the file provider to the current transaction
                    ((EffectCompilerCache)sceneRenderer.EffectSystem.Compiler).CompileEffectAsynchronously = true;
                    ((EffectCompilerCache)sceneRenderer.EffectSystem.Compiler).FileProvider = MicrothreadLocalDatabases.DatabaseFileProvider;
                    ((EffectCompilerCache)sceneRenderer.EffectSystem.Compiler).CurrentCache = EffectBytecodeCacheLoadSource.StartupCache;
                    sceneRenderer.EffectSystem.EffectUsed += (effectCompileRequest, result) => compilerResult.BuildSteps.Add(EffectCompileCommand.FromRequest(context, package, baseUrl, effectCompileRequest));

                    sceneRenderer.GameSystems.LoadContent();

                    // Load the scene
                    var scene = sceneRenderer.ContentManager.Load<Scene>(defaultSceneUrl);
                    sceneRenderer.SceneSystem.SceneInstance = new SceneInstance(sceneRenderer.Services, scene, ExecutionMode.EffectCompile);

                    // Disable culling
                    sceneRenderer.SceneSystem.SceneInstance.VisibilityGroups.CollectionChanged += (sender, e) =>
                    {
                        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                        {
                            ((VisibilityGroup)e.Item).DisableCulling = true;
                        }
                    };

                    // Update and draw
                    // This will force effects to be generated and saved in the object database
                    var time = new GameTime();
                    sceneRenderer.GameSystems.Update(time);
                    sceneRenderer.GraphicsContext.ResourceGroupAllocator.Reset(sceneRenderer.GraphicsContext.CommandList);
                    sceneRenderer.GameSystems.Draw(time);
                }
            }
            catch (Exception e)
            {
                commandContext.Logger.Warning($"Could not compile effects for scene '{defaultSceneUrl}': {e.Message + e.StackTrace}", e);
            }

            return Task.FromResult(ResultStatus.Successful);
        }
コード例 #20
0
        private void ChangeFileExtension(IList<PackageLoadingAssetFile> assetFiles, PackageLoadingAssetFile file, string newExtension)
        {
            // Create the new file
            var newFileName = new UFile(file.FilePath.FullPath.Replace(file.FilePath.GetFileExtension(), ".pdxsheet"));
            var newFile = new PackageLoadingAssetFile(newFileName, file.SourceFolder) { AssetContent = file.AssetContent };

            // Add the new file
            assetFiles.Add(newFile);

            // Mark the old file as "To Delete"
            file.Deleted = true;
        }
コード例 #21
0
        public override IEnumerable<AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters)
        {
            var outputAssets = new List<AssetItem>();

            if (!SpriteStudioXmlImport.SanityCheck(rawAssetPath))
            {
                importParameters.Logger.Error("Invalid xml file or some required files are missing.");
                return null;
            }

            //pre-process models
            var nodes = new List<SpriteStudioNode>();
            string modelName;
            if (!SpriteStudioXmlImport.ParseModel(rawAssetPath, nodes, out modelName))
            {
                importParameters.Logger.Error("Failed to parse Sprite Studio model.");
                return null;
            }

            if (importParameters.IsTypeSelectedForOutput<SpriteStudioModelAsset>())
            {
                var model = new SpriteStudioModelAsset { Source = rawAssetPath };
                foreach (var node in nodes)
                {
                    model.NodeNames.Add(node.Name);
                }
                outputAssets.Add(new AssetItem(modelName, model));
            }

            if (importParameters.IsTypeSelectedForOutput<SpriteStudioAnimationAsset>())
            {
                //pre-process anims
                var anims = new List<SpriteStudioAnim>();
                if (!SpriteStudioXmlImport.ParseAnimations(rawAssetPath, anims))
                {
                    importParameters.Logger.Error("Failed to parse Sprite Studio animations.");
                    return null;
                }

                foreach (var studioAnim in anims)
                {
                    var anim = new SpriteStudioAnimationAsset { Source = rawAssetPath, AnimationName = studioAnim.Name };
                    outputAssets.Add(new AssetItem(modelName + "_" + studioAnim.Name, anim));
                }    
            }

            return outputAssets;
        }
コード例 #22
0
ファイル: ModelAssetImporter.cs プロジェクト: cg123/xenko
        /// <summary>
        /// Imports the model.
        /// </summary>
        /// <param name="localPath">The path of the asset.</param>
        /// <param name="importParameters">The parameters used to import the model.</param>
        /// <returns>A collection of assets.</returns>
        public override IEnumerable<AssetItem> Import(UFile localPath, AssetImporterParameters importParameters)
        {
            var rawAssetReferences = new List<AssetItem>(); // the asset references without subdirectory path

            var entityInfo = GetEntityInfo(localPath, importParameters.Logger, importParameters);

            //var isImportingEntity = importParameters.IsTypeSelectedForOutput<PrefabAsset>();

            var isImportingModel = importParameters.IsTypeSelectedForOutput<ModelAsset>();

            var isImportingMaterial = importParameters.IsTypeSelectedForOutput<MaterialAsset>();

            var isImportingTexture = importParameters.IsTypeSelectedForOutput<TextureAsset>();

            // 1. Textures
            if (isImportingTexture)
            {
                ImportTextures(entityInfo.TextureDependencies, rawAssetReferences);
            }

            // 2. Skeleton
            AssetItem skeletonAsset = null;
            if (importParameters.IsTypeSelectedForOutput<SkeletonAsset>())
            {
                skeletonAsset = ImportSkeleton(rawAssetReferences, localPath, localPath, entityInfo);
            }

            // 3. Animation
            if (importParameters.IsTypeSelectedForOutput<AnimationAsset>())
            {
                ImportAnimation(rawAssetReferences, localPath, entityInfo.AnimationNodes, isImportingModel, skeletonAsset);
            }

            // 4. Materials
            if (isImportingMaterial)
            {
                ImportMaterials(rawAssetReferences, entityInfo.Materials);
            }

            // 5. Model
            if (isImportingModel)
            {
                ImportModel(rawAssetReferences, localPath, localPath, entityInfo, false, skeletonAsset);
            }

            return rawAssetReferences;
        }
コード例 #23
0
        public void TestMoveAssetWithUFile()
        {
            var projectDir = new UFile(Path.Combine(Environment.CurrentDirectory, "testxk"));
            var rawAssetPath = new UFile("../image.png");
            var assetPath = new UFile("sub1/sub2/test");

            // Create a project with an asset reference a raw file
            var project = new Package { FullPath = projectDir };
            project.Profiles.Add(new PackageProfile("Shared", new AssetFolder(".")));
            var asset = new AssetObjectTest() { RawAsset = new UFile(rawAssetPath) };
            var assetItem = new AssetItem(assetPath, asset);
            project.Assets.Add(assetItem);

            // Run an asset reference analysis on this project
            var analysis = new PackageAnalysis(project,
                new PackageAnalysisParameters()
                    {
                        ConvertUPathTo = UPathType.Absolute,
                        IsProcessingUPaths = true
                    });
            var result = analysis.Run();
            Assert.IsFalse(result.HasErrors);
            Assert.AreEqual(UPath.Combine(project.RootDirectory, new UFile("sub1/image.png")), asset.RawAsset);

            project.Assets.Remove(assetItem);
            assetItem = new AssetItem("sub1/test", asset);
            project.Assets.Add(assetItem);
            result = analysis.Run();
            Assert.IsFalse(result.HasErrors);
            Assert.AreEqual(UPath.Combine(project.RootDirectory, new UFile("sub1/image.png")), asset.RawAsset);

            project.Assets.Remove(assetItem);
            assetItem = new AssetItem("test", asset);
            project.Assets.Add(assetItem);
            result = analysis.Run();
            Assert.IsFalse(result.HasErrors);
            Assert.AreEqual(UPath.Combine(project.RootDirectory, new UFile("sub1/image.png")), asset.RawAsset);

            analysis.Parameters.ConvertUPathTo = UPathType.Relative;
            result = analysis.Run();
            Assert.IsFalse(result.HasErrors);
            Assert.AreEqual(new UFile("sub1/image.png"), asset.RawAsset);
        }
コード例 #24
0
        /// <summary>
        /// Generate a precompiled sprite font from the current sprite font asset.
        /// </summary>
        /// <param name="asset">The sprite font asset</param>
        /// <param name="sourceAsset">The source sprite font asset item</param>
        /// <param name="texturePath">The path of the source texture</param>
        /// <param name="srgb">Indicate if the generated texture should be srgb</param>
        /// <returns>The precompiled sprite font asset</returns>
        public static PrecompiledSpriteFontAsset GeneratePrecompiledSDFSpriteFont(this SpriteFontAsset asset, AssetItem sourceAsset, string texturePath)
        {
            // TODO create PrecompiledSDFSpriteFontAsset
            var scalableFont = (SignedDistanceFieldSpriteFont)SignedDistanceFieldFontCompiler.Compile(FontDataFactory, asset);

            var referenceToSourceFont = new AssetReference<SpriteFontAsset>(sourceAsset.Id, sourceAsset.Location);
            var glyphs = new List<Glyph>(scalableFont.CharacterToGlyph.Values);
            var textures = scalableFont.Textures;

            var imageType = ImageFileType.Png;
            var textureFileName = new UFile(texturePath).GetFullPathWithoutExtension() + imageType.ToFileExtension();

            if (textures != null && textures.Count > 0)
            {
                // save the texture   TODO support for multi-texture
                using (var stream = File.OpenWrite(textureFileName))
                    scalableFont.Textures[0].GetSerializationData().Save(stream, imageType);
            }

            var precompiledAsset = new PrecompiledSpriteFontAsset
            {
                Glyphs = glyphs,
                Size = asset.FontType.Size,
                Style = asset.FontSource.Style,
                OriginalFont = referenceToSourceFont,
                FontDataFile = textureFileName,
                BaseOffset = scalableFont.BaseOffsetY,
                DefaultLineSpacing = scalableFont.DefaultLineSpacing,
                ExtraSpacing = scalableFont.ExtraSpacing,
                ExtraLineSpacing = scalableFont.ExtraLineSpacing,
                DefaultCharacter = asset.DefaultCharacter,
                FontName = asset.FontSource.GetFontName(),
                IsPremultiplied = asset.FontType.IsPremultiplied,
                IsSrgb = false,
            };

            return precompiledAsset;
        }
コード例 #25
0
        /// <summary>
        /// Generate a precompiled sprite font from the current sprite font asset.
        /// </summary>
        /// <param name="asset">The sprite font asset</param>
        /// <param name="sourceAsset">The source sprite font asset item</param>
        /// <param name="texturePath">The path of the source texture</param>
        /// <param name="srgb">Indicate if the generated texture should be srgb</param>
        /// <returns>The precompiled sprite font asset</returns>
        public static PrecompiledSpriteFontAsset GeneratePrecompiledSpriteFont(this SpriteFontAsset asset, AssetItem sourceAsset, string texturePath, bool srgb)
        {
            var staticFont = (StaticSpriteFont)StaticFontCompiler.Compile(FontDataFactory, asset, srgb);

            var referenceToSourceFont = new AssetReference<SpriteFontAsset>(sourceAsset.Id, sourceAsset.Location);
            var glyphs = new List<Glyph>(staticFont.CharacterToGlyph.Values);
            var textures = staticFont.Textures;
            
            var imageType = ImageFileType.Png;
            var textureFileName = new UFile(texturePath).GetFullPathWithoutExtension() + imageType.ToFileExtension();

            if (textures != null && textures.Count > 0)
            {
                // save the texture   TODO support for multi-texture
                using (var stream = File.OpenWrite(textureFileName))
                    staticFont.Textures[0].GetSerializationData().Save(stream, imageType);
            }

            var precompiledAsset = new PrecompiledSpriteFontAsset
            {
                Glyphs = glyphs,
                Size = asset.Size,
                Style = asset.Style,
                Source = referenceToSourceFont,
                FontDataFile = textureFileName,
                BaseOffset = staticFont.BaseOffsetY,
                DefaultLineSpacing = staticFont.DefaultLineSpacing,
                ExtraSpacing = staticFont.ExtraSpacing,
                ExtraLineSpacing = staticFont.ExtraLineSpacing,
                DefaultCharacter = asset.DefaultCharacter,
                FontName = !string.IsNullOrEmpty(asset.Source) ? (asset.Source.GetFileName() ?? "") : asset.FontName,
                IsPremultiplied = asset.IsPremultiplied,
                IsSrgb = srgb
            };

            return precompiledAsset;
        }
コード例 #26
0
 public SpriteFontAsset()
 {
     DefaultCharacter = ' ';
     Style = FontStyle.Regular;
     CharacterRegions = new List<CharacterRegion>();
     LineGapFactor = 1.0f;
     LineGapBaseLineFactor = 1.0f;
     Source = new UFile("");
     CharacterSet = new UFile("");
 }
コード例 #27
0
 public static UFile Combine([NotNull] UDirectory leftPath, [NotNull] UFile rightPath)
 {
     return(UPath.Combine(leftPath, rightPath));
 }
コード例 #28
0
 /// <inheritdoc/>
 public override EntityInfo GetEntityInfo(UFile localPath, Logger logger)
 {
     var meshConverter = new Importer.FBX.MeshConverter(logger);
     var entityInfo = meshConverter.ExtractEntity(localPath.FullPath);
     return entityInfo;
 }
コード例 #29
0
 /// <summary>
 /// Retrieves Url for a texture given absolute path and sprite index
 /// </summary>
 /// <param name="textureAbsolutePath">Absolute Url of a texture</param>
 /// <param name="spriteIndex">Sprite index</param>
 public static string BuildTextureUrl(UFile textureAbsolutePath, int spriteIndex)
 {
     return textureAbsolutePath + "__IMAGE_TEXTURE__" + spriteIndex;
 }
コード例 #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageLoadingAssetFile"/> class.
 /// </summary>
 /// <param name="filePath">The file path.</param>
 /// <param name="sourceFolder">The source folder.</param>
 public PackageLoadingAssetFile(UFile filePath, UDirectory sourceFolder)
 {
     FilePath = filePath;
     SourceFolder = sourceFolder;
 }
コード例 #31
0
 /// <summary>
 /// Retrieves Url for an atlas texture given absolute path and atlas index
 /// </summary>
 /// <param name="textureAbsolutePath">Absolute Url of an atlas texture</param>
 /// <param name="atlasIndex">Atlas index</param>
 public static string BuildTextureAtlasUrl(UFile textureAbsolutePath, int atlasIndex)
 {
     return textureAbsolutePath + "__ATLAS_TEXTURE__" + atlasIndex;
 }