Exemplo n.º 1
0
        public override Entity Import(IAssetImporter ctx, UnityEngine.Texture2D texture)
        {
            var entity = ctx.CreateEntity(typeof(Image2D), typeof(Image2DLoadFromFile), typeof(Image2DLoadFromFileImageFile));

            ctx.SetComponentData(entity, new Image2D()
            {
                disableSmoothing = texture.filterMode == UnityEngine.FilterMode.Point,
                imagePixelSize   = new Mathematics.float2(texture.width, texture.height),
                hasAlpha         = Texture2DAsset.HasAlpha(texture)
            });

            ctx.SetBufferFromString <Image2DLoadFromFileImageFile>(entity, "Data/" + texture.GetGuid().ToString("N"));

            return(entity);
        }
Exemplo n.º 2
0
        public override Entity Import(IAssetImporter ctx, TMP_FontAsset font)
        {
            var entity = ctx.CreateEntity(typeof(BitmapFont), typeof(CharacterInfoBuffer));

            ctx.SetComponentData(entity, new BitmapFont()
            {
                textureAtlas = ctx.GetEntity(font.atlasTexture),
                size         = font.creationSettings.pointSize,
                ascent       = font.faceInfo.ascentLine,
                descent      = font.faceInfo.descentLine
            });

            var buffer = ctx.GetBuffer <CharacterInfoBuffer>(entity).Reinterpret <CharacterInfo>();

            foreach (var lookup in font.characterLookupTable)
            {
                var glyph  = lookup.Value;
                var rect   = glyph.glyph.glyphRect;
                var region = new Rect(
                    (float)rect.x / font.atlasTexture.width,
                    (float)rect.y / font.atlasTexture.height,
                    (float)rect.width / font.atlasTexture.width,
                    (float)rect.height / font.atlasTexture.height);

                buffer.Add(new CharacterInfo
                {
                    value           = lookup.Key,
                    advance         = glyph.glyph.metrics.horizontalAdvance,
                    bearingX        = glyph.glyph.metrics.horizontalBearingX,
                    bearingY        = glyph.glyph.metrics.horizontalBearingY,
                    width           = glyph.glyph.metrics.width,
                    height          = glyph.glyph.metrics.height,
                    characterRegion = region
                });
            }

            return(entity);
        }
Exemplo n.º 3
0
        public override Entity Import(IAssetImporter ctx, UnityEngine.Sprite sprite)
        {
            var entity = ctx.CreateEntity(typeof(Sprite2D));

            var texture = SpriteAsset.GetSpriteTexture(sprite);
            var rect    = SpriteAsset.GetSpriteTextureRect(sprite);
            var offset  = SpriteAsset.GetSpriteTextureRectOffset(sprite);
            var pivot   = sprite.pivot;
            var border  = sprite.border;

            ctx.SetComponentData(entity, new Sprite2D()
            {
                image       = ctx.GetEntity(texture),
                imageRegion = new Rect(
                    rect.x / texture.width,
                    rect.y / texture.height,
                    rect.width / texture.width,
                    rect.height / texture.height),
                pivot = new float2(
                    (pivot.x - offset.x) / rect.width,
                    (pivot.y - offset.y) / rect.height),
                pixelsToWorldUnits = 1f / sprite.pixelsPerUnit
            });

            if (border != UnityEngine.Vector4.zero)
            {
                ctx.AddComponentData(entity, new Sprite2DBorder()
                {
                    bottomLeft = new float2(
                        border.x / rect.width,
                        border.y / rect.height),
                    topRight = new float2(
                        (rect.width - border.z) / rect.width,
                        (rect.height - border.w) / rect.height)
                });
            }
            return(entity);
        }