public void TransferFromUnityComponents(Entity entity, IBindingContext context)
        {
            var spriteRenderer = context.GetUnityComponent <UnityEngine.SpriteRenderer>(entity);

            context.SetComponentData(entity, new Sprite2DRenderer
            {
                sprite = s_WhiteSprite != spriteRenderer.sprite ? context.GetEntity(spriteRenderer.sprite) : Entity.Null,
                color  = spriteRenderer.color.Convert()
            });

            if (spriteRenderer.drawMode != UnityEngine.SpriteDrawMode.Simple)
            {
                var optionsData = new Sprite2DRendererOptions()
                {
                    drawMode = Translate(spriteRenderer.drawMode, spriteRenderer.tileMode),
                    size     = spriteRenderer.size
                };

                if (context.HasComponent <Sprite2DRendererOptions>(entity))
                {
                    context.SetComponentData(entity, optionsData);
                }
                else
                {
                    context.AddComponentData(entity, optionsData);
                }
            }
            else
            {
                context.RemoveComponent <Sprite2DRendererOptions>(entity);
            }
        }
Ejemplo n.º 2
0
        public void TransferFromUnityComponents(Entity entity, IBindingContext context)
        {
            var image = context.GetUnityComponent <UnityEngine.UI.Image>(entity);

            context.SetComponentData(entity, new Sprite2DRenderer()
            {
                sprite = context.GetEntity(image.sprite),
                color  = image.color.Convert()
            });

            var rt = context.GetUnityComponent <UnityEngine.RectTransform>(entity);

            var optionsData = new Sprite2DRendererOptions()
            {
                size = rt.rect.size
            };


            if (image.type == UnityEngine.UI.Image.Type.Simple || image.type == UnityEngine.UI.Image.Type.Sliced)
            {
                optionsData.drawMode = DrawMode.Stretch;
            }
            else
            {
                optionsData.drawMode = DrawMode.ContinuousTiling;
            }
            if (context.HasComponent <Sprite2DRendererOptions>(entity))
            {
                context.SetComponentData(entity, optionsData);
            }
            else
            {
                context.AddComponentData(entity, optionsData);
            }
        }