Example #1
0
        protected override void OnUpdate()
        {
            Entities.ForEach((TMPro.TextMeshPro tmpro) =>
            {
                var textEntity = GetPrimaryEntity(tmpro);

                HorizontalAlignment halign = HorizontalAlignment.Left;
                if (tmpro.alignment.HasFlag(TextAlignmentOptions.Left))
                {
                    halign = HorizontalAlignment.Left;
                }
                else if (tmpro.alignment.HasFlag(TextAlignmentOptions.Center))
                {
                    halign = HorizontalAlignment.Center;
                }
                else if (tmpro.alignment.HasFlag(TextAlignmentOptions.Right))
                {
                    halign = HorizontalAlignment.Right;
                }

                var fontAsset = GetPrimaryEntity(tmpro.font);
                DstEntityManager.AddComponentData(textEntity, new Text.TextRenderer
                {
                    FontMaterial        = fontAsset,
                    MeshColor           = tmpro.color.linear.ToTiny(),
                    Size                = tmpro.fontSize,
                    HorizontalAlignment = halign,
                });

                var text = tmpro.text;
                DstEntityManager.AddBufferFromString <TextRendererString>(textEntity, text);
            });
        }
Example #2
0
        protected override void OnUpdate()
        {
            // UI text conversion
            Entities.ForEach((TextMeshProUGUI displayText) =>
            {
                // We are converting an entity (textEntity) and creating another (eSubText).
                // Why?
                // We want to use the Rectangle Transform system to also position text, rather
                // than introduce something special. So we need a parent element that is the frame
                // of the text (textEntity) and a child element that has a pivet on the text string
                // itself. Systems later will process the child element.

                var textEntity = GetPrimaryEntity(displayText);

                // Sub-text child transform
                SceneSection sceneSection = DstEntityManager.GetSharedComponentData <SceneSection>(textEntity);
                var eSubText = DstEntityManager.CreateEntity();
                DstEntityManager.AddSharedComponentData(eSubText, sceneSection);

                DstEntityManager.AddComponentData(eSubText, new Tiny.UI.RectTransform
                {
                    AnchorMin        = 0.5f,
                    AnchorMax        = 0.5f,
                    SizeDelta        = 1f,
                    AnchoredPosition = 0f,
                    Pivot            = 0.5f
                });

                DstEntityManager.AddComponentData(eSubText, new UIName()
                {
                    Name = displayText.name
                });

                DstEntityManager.AddComponentData(eSubText, new RectParent()
                {
                    Value = textEntity
                });

                DstEntityManager.AddComponentData(eSubText, new Unity.Tiny.Rendering.CameraMask
                {
                    mask = (ulong)(1 << displayText.gameObject.layer)
                });

                DstEntityManager.AddComponent <RectTransformResult>(eSubText);

                var fontAsset = GetPrimaryEntity(displayText.font);
                DstEntityManager.AddComponentData(eSubText, new Tiny.Text.TextRenderer
                {
                    FontMaterial        = fontAsset,
                    MeshColor           = displayText.color.linear.ToTiny(),
                    Size                = displayText.fontSize * 10,
                    HorizontalAlignment = ConvertHorizontalAlignment(displayText.alignment),
                    VerticalAlignment   = ConvertVerticalAlignment(displayText.alignment),
                });

                var text = displayText.text;
                DstEntityManager.AddBufferFromString <TextRendererString>(eSubText, text);
                DstEntityManager.AddComponent <LocalToWorld>(eSubText);
            });
        }
        protected override void OnUpdate()
        {
            Entities.ForEach((TextRenderer displayText) =>
            {
                var textEntity = GetPrimaryEntity(displayText);

                var fontAsset = GetPrimaryEntity(displayText.Font);
                DstEntityManager.AddComponentData(textEntity, new Text.TextRenderer
                {
                    FontMaterial        = fontAsset,
                    MeshColor           = displayText.Color.linear.ToTiny(),
                    Size                = displayText.Size,
                    HorizontalAlignment = displayText.Alignment
                });
                DstEntityManager.AddComponentData(textEntity, new Unity.Tiny.Rendering.CameraMask {
                    mask = (ulong)(1 << displayText.gameObject.layer)
                });

                var text = displayText.Text;
                DstEntityManager.AddBufferFromString <TextRendererString>(textEntity, text);
            });
        }