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);
                }
            }
        }
示例#2
0
            public void Execute(ArchetypeChunk chunk, int index, int entityOffset)
            {
                var chunkRectTransform = chunk.GetNativeArray(RectTransformType);
                var entities           = chunk.GetNativeArray(EntityType);
                var chunkChildren      = chunk.GetBufferAccessor(ChildType);
                var canvasSizeArray    = chunk.GetNativeArray(CanvasSizeType);

                NativeArray <CanvasConstantPhysicalSizeScaler> physicalSizeArray = default;
                bool useConstantPhysicalSize = chunk.Has(ConstantPhysicalScaler);

                if (useConstantPhysicalSize)
                {
                    physicalSizeArray = chunk.GetNativeArray(ConstantPhysicalScaler);
                }

                //HierarchyRebuildContext rebuildContext = new HierarchyRebuildContext()
                //{
                //    ChildrenFromEntity = RebuildContext.ChildrenFromEntity,
                //    ElementScaleFromEntity = RebuildContext.ElementScaleFromEntity,
                //    RebuildFlagFromEntity = RebuildFlagFromEntity,
                //    RectMaskFromEntity = RectMaskFromEntity,
                //    RectTransformFromEntity = RectTransformFromEntity,
                //    WorldSpaceMaskFromEntity = WorldSpaceMaskFromEntity,
                //    WorldSpaceRectFromEntity = WorldSpaceRectFromEntity
                //};

                for (int i = 0; i < chunk.Count; i++)
                {
                    float2 scale = new float2(1.0f, 1.0f);
                    if (useConstantPhysicalSize)
                    {
                        scale = Dpi * physicalSizeArray[i].Factor;
                    }
                    var canvasRect = new WorldSpaceRect()
                    {
                        Min = float2.zero,             //chunkRectTransform[i].Position,
                        Max = canvasSizeArray[i].Value //(chunkRectTransform[i].Position + canvasSizeArray[i].Value)
                    };
                    RebuildContext.WorldSpaceRectFromEntity[entities[i]] = canvasRect;

                    var            children           = chunkChildren[i];
                    var            parentLocalToWorld = canvasRect;
                    WorldSpaceMask canvasMask         = new WorldSpaceMask()
                    {
                        Min = canvasRect.Min,
                        Max = canvasRect.Max
                    };
                    for (int j = 0; j < children.Length; j++)
                    {
                        var childTransform = RebuildContext.RectTransformFromEntity[children[j].Value];
                        RectTransformUtils.UpdateTransformRecursive(ref parentLocalToWorld, canvasMask, children[j].Value, scale, ref RebuildContext);
                        //UpdateTransformRecursive(ref parentLocalToWorld, canvasMask, children[j].Value, scale);
                    }
                }
            }