Esempio n. 1
0
        public override Entity Import(IAssetImporter ctx, UnityEngine.Video.VideoClip clip)
        {
            var entityVideo = ctx.CreateEntity(typeof(Unity.Tiny.Video.VideoClip), typeof(Unity.Tiny.Video.VideoClipLoadFromFile));

            ctx.AddBufferFromString <Unity.Tiny.Video.VideoClipLoadFromFileName>(entityVideo, "Data/" + clip.GetGuid().ToString("N"));
            return(entityVideo);
        }
Esempio n. 2
0
        public override Entity Import(IAssetImporter ctx, UnityEngine.AudioClip audioClip)
        {
            var entity = ctx.CreateEntity(typeof(AudioClip), typeof(AudioClipLoadFromFile), typeof(AudioClipLoadFromFileAudioFile));

            ctx.SetBufferFromString <AudioClipLoadFromFileAudioFile>(entity, "Data/" + audioClip.GetGuid().ToString("N"));
            return(entity);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }