Exemplo n.º 1
0
        public override Entity Import(IAssetImporter ctx, UnityEngine.U2D.SpriteAtlas atlas)
        {
            var entity = ctx.CreateEntity(typeof(SpriteAtlas));

            var sprites = atlas.GetPackedSprites().Select(s => ctx.GetEntity(s)).Where(e => e != Entity.Null).ToArray();
            var buffer  = ctx.GetBuffer <SpriteAtlas>(entity).Reinterpret <Entity>();

            foreach (var sprite in sprites)
            {
                buffer.Add(sprite);
            }

            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);
        }