public void UpdateTransformRecursive(ref WorldSpaceRect parentLocalToWorldSpaceRect, WorldSpaceMask currentMask, Entity entity, float2 scale)
        {
            if (DisabledFromEntity.Exists(entity))
            {
                return;
            }
            var childTransform    = RectTransformFromEntity[entity];
            var childLocalToWorld = RectTransformUtils.CalculateWorldSpaceRect(parentLocalToWorldSpaceRect, scale, childTransform);

            WorldSpaceRectFromEntity[entity] = childLocalToWorld;
            ElementScaleFromEntity[entity]   = new ElementScale()
            {
                Value = scale
            };
            UpdateRectMask(entity, childLocalToWorld, ref currentMask);
            WorldSpaceMaskFromEntity[entity] = currentMask;

            if (RebuildFlagFromEntity.Exists(entity))
            {
                RebuildFlagFromEntity[entity] = new RebuildElementMeshFlag()
                {
                    Rebuild = true
                }
            }
            ;
            if (ChildrenFromEntity.Exists(entity))
            {
                var children = ChildrenFromEntity[entity];
                for (int i = 0; i < children.Length; i++)
                {
                    UpdateTransformRecursive(ref childLocalToWorld, currentMask, children[i].Value, scale);
                }
            }
        }
Example #2
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                NativeArray <SpriteImage>            spriteImages        = chunk.GetNativeArray(SpriteImageType);
                NativeArray <WorldSpaceRect>         worldSpaceRects     = chunk.GetNativeArray(WorldSpaceRectType);
                NativeArray <WorldSpaceMask>         worldSpaceMasks     = chunk.GetNativeArray(WorldSpaceMaskType);
                NativeArray <VertexColorValue>       colorValues         = chunk.GetNativeArray(ColorValueType);
                NativeArray <VertexColorMultiplier>  colorMultipliers    = chunk.GetNativeArray(ColorMultiplierType);
                NativeArray <RebuildElementMeshFlag> rebuildFlagArray    = chunk.GetNativeArray(RebuildElementMeshFlagType);
                BufferAccessor <ControlVertexData>   vertexDataAccessor  = chunk.GetBufferAccessor(VertexDataType);
                BufferAccessor <ControlVertexIndex>  vertexIndexAccessor = chunk.GetBufferAccessor(VertexIndexType);

                for (int i = 0; i < chunk.Count; i++)
                {
                    var assetEntity = spriteImages[i].Asset;
                    if (rebuildFlagArray[i].Rebuild)
                    {
                        var vertices       = vertexDataAccessor[i];
                        var triangles      = vertexIndexAccessor[i];
                        var worldSpaceMask = worldSpaceMasks[i];

                        vertices.Clear();
                        triangles.Clear();

                        var worldSpaceRect = worldSpaceRects[i];
                        if (SpriteDataFromEntity.Exists(assetEntity))
                        {
                            var spriteData = SpriteDataFromEntity[assetEntity];
                            // TODO: Simple sprite (non sliced)
                            SpriteUtility.PopulateSpriteVertices(ref worldSpaceMask, ref vertices, ref triangles, ref worldSpaceRect, ref spriteData, colorValues[i].Value * colorMultipliers[i].Value);
                        }
                        else
                        {
                            var spriteData = SpriteVertexData.Default;
                            SpriteUtility.PopulateSpriteVertices(ref worldSpaceMask, ref vertices, ref triangles, ref worldSpaceRect, ref spriteData, colorValues[i].Value * colorMultipliers[i].Value);
                        }
                        rebuildFlagArray[i] = new RebuildElementMeshFlag()
                        {
                            Rebuild = false
                        };
                    }
                }
            }
Example #3
0
            private void UpdateTransform(ref WorldSpaceRect parentLocalToWorldSpaceRect, WorldSpaceMask currentMask, Entity entity, float2 scale, int jobIdx)
            {
                var    childTransform = RectTransformFromEntity[entity];
                float2 start          = math.lerp(parentLocalToWorldSpaceRect.Min, parentLocalToWorldSpaceRect.Max, math.lerp(childTransform.AnchorMin, childTransform.AnchorMax, childTransform.Pivot)) + childTransform.Position * scale;
                float2 anchorDiff     = childTransform.AnchorMax - childTransform.AnchorMin;
                float2 size           = (parentLocalToWorldSpaceRect.Max - parentLocalToWorldSpaceRect.Min) * anchorDiff + childTransform.SizeDelta * scale;

                float2 min = start - size * childTransform.Pivot;
                float2 max = start + size * (new float2(1.0f, 1.0f) - childTransform.Pivot);

                var childLocalToWorld = new WorldSpaceRect()
                {
                    Min = min,
                    Max = max,
                };

                LocalToWorldFromEntity[entity] = childLocalToWorld;
                ElementScaleType[entity]       = new ElementScale()
                {
                    Value = scale
                };
                UpdateRectMask(entity, childLocalToWorld, ref currentMask);
                WorldSpaceMaskFromEntity[entity] = currentMask;

                if (RebuildFlagType.Exists(entity))
                {
                    RebuildFlagType[entity] = new RebuildElementMeshFlag()
                    {
                        Rebuild = true
                    }
                }
                ;
                if (ChildFromEntity.Exists(entity))
                {
                    var children = ChildFromEntity[entity];
                    for (int i = 0; i < children.Length; i++)
                    {
                        UpdateTransform(ref childLocalToWorld, currentMask, children[i].Value, scale, jobIdx);
                    }
                }
            }
Example #4
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var entities                   = chunk.GetNativeArray(TextEntities);
                var rebuildMeshArray           = chunk.GetNativeArray(RebuildElementMeshFlagArray);
                var vertexBufferAccessor       = chunk.GetBufferAccessor(VertexDataType);
                var indexBufferAccessor        = chunk.GetBufferAccessor(IndexDataType);
                var textBufferAccessor         = chunk.GetBufferAccessor(TextBufferType);
                var worldSpaceRectArray        = chunk.GetNativeArray(WorldSpaceRectType);
                var textRendererArray          = chunk.GetNativeArray(TextRendererType);
                var vertexColorArray           = chunk.GetNativeArray(ColorValueType);
                var vertexColorMultiplierArray = chunk.GetNativeArray(ColorMultiplierType);
                var elementScaleArray          = chunk.GetNativeArray(ElementScaleType);
                var worldSpaceMaskArray        = chunk.GetNativeArray(WorldSpaceMaskType);

                for (int i = 0; i < chunk.Count; i++)
                {
                    if (rebuildMeshArray[i].Rebuild)
                    {
                        var vertices     = vertexBufferAccessor[i];
                        var triangles    = indexBufferAccessor[i];
                        var textBuffer   = textBufferAccessor[i];
                        var rect         = worldSpaceRectArray[i];
                        var fontSettings = textRendererArray[i];
                        var elementScale = elementScaleArray[i];
                        var mask         = worldSpaceMaskArray[i];

                        vertices.Clear();
                        triangles.Clear();

                        float4 color = vertexColorArray[i].Value * vertexColorMultiplierArray[i].Value;

                        PopulateMesh(rect, elementScale, mask, fontSettings, color, ref textBuffer, ref vertices, ref triangles);
                        rebuildMeshArray[i] = new RebuildElementMeshFlag()
                        {
                            Rebuild = false
                        };
                    }
                }
            }