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);
            }
        }
Example #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);
            }
        }
Example #3
0
        protected override void AddComponentIfDataIsNotDefault(Entity entity, IBindingContext context)
        {
            var transform = context.GetUnityComponent <UnityEngine.Transform>(entity);
            var scale     = transform.localScale;

            if (!Mathf.Approximately(scale.x, 1.0f) ||
                !Mathf.Approximately(scale.y, 1.0f) ||
                !Mathf.Approximately(scale.z, 1.0f))
            {
                context.AddComponentData(entity, new NonUniformScale {
                    Value = scale
                });
            }
        }
Example #4
0
        protected override void AddComponentIfDataIsNotDefault(Entity entity, IBindingContext context)
        {
            var transform = context.GetUnityComponent <UnityEngine.Transform>(entity);
            var position  = transform.localPosition;

            if (!Mathf.Approximately(position.x, 0.0f) ||
                !Mathf.Approximately(position.y, 0.0f) ||
                !Mathf.Approximately(position.z, 0.0f))
            {
                context.AddComponentData(entity, new Translation {
                    Value = position
                });
            }
        }
Example #5
0
        protected override void AddComponentIfDataIsNotDefault(Entity entity, IBindingContext context)
        {
            var transform = context.GetUnityComponent <UnityEngine.Transform>(entity);
            var rotation  = transform.localRotation;

            if (!Mathf.Approximately(rotation.x, Identity.value.x) ||
                !Mathf.Approximately(rotation.y, Identity.value.y) ||
                !Mathf.Approximately(rotation.z, Identity.value.z) ||
                !Mathf.Approximately(rotation.w, Identity.value.w))
            {
                context.AddComponentData(entity, new Rotation {
                    Value = rotation
                });
            }
        }
        public void TransferFromUnityComponents(Entity entity, IBindingContext context)
        {
            var transform = context.GetUnityComponent <UnityEngine.Transform>(entity);
            // If the Unity scale isn't uniform, then we upgrade this to a NonUniformScale, and let
            // that binding take over.  We do an explicit == check even on the floating point values,
            // because the only case we want to handle is when the same bit value is really assigned
            // to all of x/y/z.
            var scale = transform.localScale;

            if (scale.x == scale.y &&
                scale.x == scale.z)
            {
                context.SetComponentData(entity, new Scale()
                {
                    Value = scale.x
                });
            }
            else
            {
                context.RemoveComponent <Scale>(entity);
                // depending on the order that the bindings transfer/unload is called,
                // this might have been added already (even if this particular binding is Exclude<NonUniformScale>
                if (context.HasComponent <NonUniformScale>(entity))
                {
                    context.SetComponentData(entity, new NonUniformScale()
                    {
                        Value = scale
                    });
                }
                else
                {
                    context.AddComponentData(entity, new NonUniformScale()
                    {
                        Value = scale
                    });
                }
            }
        }