Esempio n. 1
0
        public virtual void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var text2DRenderer = context.GetComponentData <Text2DRenderer>(entity);
            var text2DStyle    = context.GetComponentData <Text2DStyle>(entity);

            var text = context.GetUnityComponent <TText>(entity);

            if (context.HasComponent <TextString>(entity))
            {
                var textString = context.GetBufferRO <TextString>(entity).Reinterpret <char>().AsString();
                text.text = textString;
            }
            else
            {
                text.text = string.Empty;
            }

            text.fontStyle   = FontStyles.Normal;
            text.lineSpacing = 1;
            text.richText    = false;
            text.alignment   = Fonts.GetTextAlignmentFromPivot(text2DRenderer.pivot);
            var c = text2DStyle.color;

            text.color              = new Color(c.r, c.g, c.b, c.a);;
            text.fontSize           = text2DStyle.size * SizeFactor;
            text.isOrthographic     = true;
            text.enableWordWrapping = false;

            Transfer(entity, text, context);
        }
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            try
            {
                var spriteRenderer   = context.GetUnityComponent <UnityEngine.SpriteRenderer>(entity);
                var sprite2DRenderer = context.GetComponentData <Sprite2DRenderer>(entity);
                var sprite           = context.GetUnityObject <UnityEngine.Sprite>(sprite2DRenderer.sprite);

                var block = new UnityEngine.MaterialPropertyBlock();
                spriteRenderer.GetPropertyBlock(block);
                block.Clear();

                spriteRenderer.color = sprite2DRenderer.color.Convert();
                block.SetColor("_Color", sprite2DRenderer.color.Convert());

                if (sprite)
                {
                    spriteRenderer.sprite = sprite;
                    var blending = sprite2DRenderer.blending;
                    if (k_BlendModes.TryGetValue(blending, out var blendMode))
                    {
                        spriteRenderer.sharedMaterial.SetFloat("_SrcMode", blendMode.x);
                        spriteRenderer.sharedMaterial.SetFloat("_DstMode", blendMode.y);
                    }
                    else
                    {
                        UnityEngine.Debug.Log($"Tiny: Unknown blending mode, of value '{blending}'");
                    }

                    block.SetTexture("_MainTex", sprite.texture);
                }
                else
                {
                    spriteRenderer.sprite = s_WhiteSprite;
                    if (!context.HasComponent <Sprite2DRendererOptions>(entity))
                    {
                        spriteRenderer.size = UnityEngine.Vector2.one;
                    }
                }

                spriteRenderer.SetPropertyBlock(block);

                if (context.HasComponent <Sprite2DRendererOptions>(entity))
                {
                    var options = context.GetComponentData <Sprite2DRendererOptions>(entity);
                    SetDrawMode(spriteRenderer, options.drawMode);
                    spriteRenderer.size = options.size;
                }
                else
                {
                    spriteRenderer.drawMode = UnityEngine.SpriteDrawMode.Simple;
                }
            }
            finally
            {
                UnityEditor.SceneView.RepaintAll();
            }
        }
Esempio n. 3
0
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var image = context.GetUnityComponent <UnityEngine.UI.Image>(entity);

            var sprite2DRenderer = context.GetComponentData <Sprite2DRenderer>(entity);

            image.sprite = context.GetUnityObject <UnityEngine.Sprite>(sprite2DRenderer.sprite);
            image.color  = sprite2DRenderer.color.Convert();

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

            if (null != rt && rt)
            {
                if (context.HasComponent <Sprite2DRendererOptions>(entity))
                {
                    var tinyOptions = context.GetComponentData <Sprite2DRendererOptions>(entity);
                    tinyOptions.size = rt.rect.size;
                    var drawMode = tinyOptions.drawMode;
                    switch (drawMode)
                    {
                    case DrawMode.Stretch:
                    {
                        image.type = UnityEngine.UI.Image.Type.Sliced;
                        break;
                    }

                    case DrawMode.AdaptiveTiling:
                    case DrawMode.ContinuousTiling:
                    {
                        image.type = UnityEngine.UI.Image.Type.Tiled;
                        break;
                    }
                    }
                }
            }

            if (k_BlendModes.TryGetValue(sprite2DRenderer.blending, out var blendMode))
            {
                var mat = image.material;
                mat.SetFloat("_SrcMode", blendMode.x);
                mat.SetFloat("_DstMode", blendMode.y);
                mat.SetColor("_Color", image.color);
            }
            else
            {
                UnityEngine.Debug.Log($"Tiny: Unknown blending mode, of value '{sprite2DRenderer.blending}'");
            }
        }
Esempio n. 4
0
        protected override void Transfer(Entity entity, TText text, IBindingContext context)
        {
            var textMesh = context.GetUnityComponent <TText>(entity);
            var text2DStyleNativeFont = context.GetComponentData <Text2DStyleNativeFont>(entity);
            var nativeFont            = context.GetComponentData <NativeFont>(entity);

            var italic = text2DStyleNativeFont.italic;

            if (italic)
            {
                textMesh.fontStyle = FontStyles.Italic;
            }
            else
            {
                textMesh.fontStyle = FontStyles.Normal;
            }

            switch (nativeFont.name)
            {
            case FontName.SansSerif:
                textMesh.font = Fonts.GetSansSerifFont(italic);
                break;

            case FontName.Serif:
                textMesh.font = Fonts.GetSerifFont(italic);
                break;

            case FontName.Monospace:
                textMesh.font = Fonts.GetMonoSpaceFont(italic);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            //For the weight, let's update the dilate shader property, it should be present for font asset using a SDF Text mesh pro shader
            Material mat = textMesh.fontMaterial;
            float    nativeFontWeight = Mathf.Clamp((float)text2DStyleNativeFont.weight, 400.0f, 700.0f);

            if (mat.HasProperty("_FaceDilate"))
            {
                //400 is regular(min) and 700 bold(max). font.boldStyle is the initial dilatation used when creating the font
                float value = (nativeFontWeight - 400) * textMesh.font.boldStyle / 700.0f;
                value = Mathf.Clamp(value, 0.0f, 1.0f);
                mat.SetFloat("_FaceDilate", value);
                textMesh.fontMaterial = mat;
            }
        }
Esempio n. 5
0
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var transform = context.GetUnityComponent <UnityEngine.Transform>(entity);
            var v         = context.GetComponentData <Scale>(entity).Value;

            transform.localScale = new UnityEngine.Vector3(v, v, v);
        }
Esempio n. 6
0
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var spriteRenderer = context.GetComponentData <Sprite2DRenderer>(entity);
            var behaviour      = context.GetUnityComponent <Unity.Tiny.Sprite2DRendererHitBox2D>(entity);

            behaviour.Sprite = context.GetUnityObject <UnityEngine.Sprite>(spriteRenderer.sprite);
        }
Esempio n. 7
0
 protected override void Transfer(Entity entity, TextMeshProUGUI text, IBindingContext context)
 {
     base.Transfer(entity, text, context);
     try
     {
         if (context.HasComponent <Text2DAutoFit>(entity))
         {
             var autoFit = context.GetComponentData <Text2DAutoFit>(entity);
             text.enableAutoSizing   = true;
             text.fontSizeMin        = autoFit.minSize * SizeFactor;
             text.fontSizeMax        = autoFit.maxSize * SizeFactor;
             text.enableWordWrapping = false;
         }
         else
         {
             text.enableAutoSizing   = false;
             text.enableWordWrapping = false;
         }
     }
     finally
     {
         Canvas.ForceUpdateCanvases();
         LayoutRebuilder.ForceRebuildLayoutImmediate(context.GetUnityComponent <RectTransform>(entity).root as RectTransform);
     }
 }
Esempio n. 8
0
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var group     = context.GetUnityComponent <UnityEngine.Rendering.SortingGroup>(entity);
            var tinyLayer = context.GetComponentData <LayerSorting>(entity);

            group.sortingLayerID = tinyLayer.id;
            group.sortingOrder   = tinyLayer.order;
            UnityEditor.EditorUtility.SetDirty(group);
        }
Esempio n. 9
0
        public virtual void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var canvas    = context.GetUnityComponent <UnityEngine.Canvas>(entity);
            var tinyLayer = context.GetComponentData <LayerSorting>(entity);

            canvas.overrideSorting = true;
            canvas.sortingLayerID  = tinyLayer.layer;
            canvas.sortingOrder    = tinyLayer.order;
            UnityEditor.EditorUtility.SetDirty(canvas);
        }
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var rectTransform     = context.GetUnityComponent <UnityEngine.RectTransform>(entity);
            var tinyRectTransform = context.GetComponentData <RectTransform>(entity);

            rectTransform.anchoredPosition = tinyRectTransform.anchoredPosition;
            rectTransform.anchorMin        = tinyRectTransform.anchorMin;
            rectTransform.anchorMax        = tinyRectTransform.anchorMax;
            rectTransform.sizeDelta        = tinyRectTransform.sizeDelta;
            rectTransform.pivot            = tinyRectTransform.pivot;
        }
Esempio n. 11
0
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var camera   = context.GetUnityComponent <UnityEngine.Camera>(entity);
            var camera2D = context.GetComponentData <Camera2D>(entity);

            SetUnsupportedFields(camera);
            camera.clearFlags       = camera2D.clearFlags.Convert();
            camera.backgroundColor  = camera2D.backgroundColor.Convert();
            camera.orthographicSize = camera2D.halfVerticalSize;

            // TODO: map culling mask..
            //camera.cullingMask = tinyCamera.layerMask;
            camera.rect  = camera2D.rect.Convert();
            camera.depth = camera2D.depth;

            if (context.HasComponent <Camera2DClippingPlanes>(entity))
            {
                var clippingPlanes = context.GetComponentData <Camera2DClippingPlanes>(entity);
                camera.nearClipPlane = clippingPlanes.near;
                camera.farClipPlane  = clippingPlanes.far;
            }
            else
            {
                camera.nearClipPlane = -100000.0f;
                camera.farClipPlane  = 100000.0f;
            }

            if (context.HasComponent <Camera2DAxisSort>(entity))
            {
                var axisSort = context.GetComponentData <Camera2DAxisSort>(entity);
                camera.transparencySortMode = UnityEngine.TransparencySortMode.CustomAxis;
                camera.transparencySortAxis = axisSort.axis;
            }
            else
            {
                camera.transparencySortMode = UnityEngine.TransparencySortMode.Default;
            }
        }
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var renderer = context.GetUnityComponent <UnityEngine.Renderer>(entity);

            if (!renderer || null == renderer)
            {
                return;
            }
            var layer = context.GetComponentData <LayerSorting>(entity);

            renderer.sortingLayerID = layer.id;
            renderer.sortingOrder   = layer.order;
            UnityEditor.EditorUtility.SetDirty(renderer);
        }
Esempio n. 13
0
        public void UnloadBinding(Entity entity, IBindingContext context)
        {
            var transform = context.GetUnityComponent <UnityEngine.Transform>(entity);

            // If this binding is being unloaded, but the entity has a NonUniformScale (because it
            // was swapped at some point), set the right value.
            if (context.HasComponent <NonUniformScale>(entity))
            {
                transform.localScale = context.GetComponentData <NonUniformScale>(entity).Value;
            }
            else
            {
                transform.localScale = UnityEngine.Vector3.one;
            }
        }
Esempio n. 14
0
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var canvas   = context.GetUnityComponent <UnityEngine.Canvas>(entity);
            var uiCanvas = context.GetComponentData <UICanvas>(entity);

            canvas.worldCamera = context.GetUnityComponent <UnityEngine.Camera>(uiCanvas.camera);

            var scaler = context.GetUnityComponent <UnityEngine.UI.CanvasScaler>(entity);

            scaler.referenceResolution = uiCanvas.referenceResolution;
            scaler.matchWidthOrHeight  = uiCanvas.matchWidthOrHeight;
            scaler.uiScaleMode         = uiCanvas.uiScaleMode.Convert();

            SetUnsupportedFields(canvas, scaler);
            UnityEngine.UI.LayoutRebuilder.MarkLayoutForRebuild(canvas.transform as UnityEngine.RectTransform);
        }
Esempio n. 15
0
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var transform = context.GetUnityComponent <UnityEngine.Transform>(entity);

            transform.localRotation = context.GetComponentData <Rotation>(entity).Value;
        }
Esempio n. 16
0
        protected override void Transfer(Entity entity, TText text, IBindingContext context)
        {
            var text2DStyleBitmapFont = context.GetComponentData <Text2DStyleBitmapFont>(entity);

            text.font = context.GetUnityObject <TMP_FontAsset>(text2DStyleBitmapFont.font);
        }
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var transform = context.GetUnityComponent <UnityEngine.Transform>(entity);

            transform.localScale = context.GetComponentData <NonUniformScale>(entity).Value;
        }
Esempio n. 18
0
        public void TransferToUnityComponents(Entity entity, IBindingContext context)
        {
            var hitbox = context.GetComponentData <RectHitBox2D>(entity);

            context.GetUnityComponent <Unity.Tiny.RectHitBox2D>(entity).Box = hitbox.box.Convert();
        }