Exemplo n.º 1
0
        public static IntPtr GetNodeConfigPointer(this UIGraphData self, int index)
        {
            HeaderConfig *header     = (HeaderConfig *)(GetNodePointer(self, index) + sizeof(int)).ToPointer();
            var           childCount = header->childCount;

            return(((IntPtr)header) + UnsafeUtility.SizeOf <HeaderConfig>() + (sizeof(int) * childCount));
        }
Exemplo n.º 2
0
        public static IntPtr GetConfigBlock(this UIGraphData self, int index, byte config)
        {
            HeaderConfig *header     = (HeaderConfig *)(GetNodePointer(self, index) + sizeof(int)).ToPointer();
            var           childCount = header->childCount;
            var           offset     = UIConfigUtility.GetOffset(header->configurationMask, config);

            return(((IntPtr)header) + UnsafeUtility.SizeOf <HeaderConfig>() + (sizeof(int) * childCount) + offset);
        }
Exemplo n.º 3
0
        public static void Render(IntPtr configPtr, NodeInfo *nodeInfo, UIPassState *statePtr, UIVertexData *vertexDataPtr, UIContextData *context)
        {
            IntPtr            configSource           = configPtr + nodeInfo->configOffset;
            BoxModelConfig *  boxConfig              = (BoxModelConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxModelConfig, configSource).ToPointer();
            BackgroundConfig *backgroundConfig       = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer();
            BorderConfig *    borderConfig           = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer();
            SizeConfig *      sizeConfig             = (SizeConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.SizeConfig, configSource).ToPointer();
            BoxLayoutConfig * sequentialLayoutConfig = (BoxLayoutConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxLayoutConfig, configSource).ToPointer();
            HeaderConfig *    headerConfig           = (HeaderConfig *)(configPtr + nodeInfo->nodeOffset);

            UIRenderBoxWriters.WriteRenderBox(statePtr, backgroundConfig, borderConfig, vertexDataPtr, context);
        }
Exemplo n.º 4
0
        public static bool HasConfigBlock(this UIGraphData self, int index, byte config)
        {
            HeaderConfig *header     = (HeaderConfig *)(GetNodePointer(self, index) + sizeof(int)).ToPointer();
            var           childCount = header->childCount;
            var           offset     = UIConfigUtility.GetOffset(header->configurationMask, config);

            if (offset < 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 5
0
        public static bool TryGetConfigBlock(this UIGraphData self, int index, byte config, out IntPtr result)
        {
            HeaderConfig *header     = (HeaderConfig *)(GetNodePointer(self, index) + sizeof(int)).ToPointer();
            var           childCount = header->childCount;
            var           offset     = UIConfigUtility.GetOffset(header->configurationMask, config);

            if (offset < 0)
            {
                result = IntPtr.Zero;
                return(false);
            }
            else
            {
                result = ((IntPtr)header) + UnsafeUtility.SizeOf <HeaderConfig>() + (sizeof(int) * childCount) + offset;
                return(true);
            }
        }
Exemplo n.º 6
0
        private void RenderMesh(
            int startIndex,
            int parentIndex,
            int currentIndex,
            NativeArray <UIVertexData> vertexData,
            UIContextData *context,
            NativeArray <ushort> indices,
            UIGraphData graph,
            GraphInfo graphInfo,
            NativeArray <NodeInfo> nodeInfo,
            NativeArray <UIPassState> stateLayout,
            NativeArray <SubMeshInfo> subMeshes,
            bool renderNow,
            bool updateSubmeshCount,
            bool accumulate,
            ref int subMeshIndex,
            ref int renderIndex,
            ref float4 bounds

            )
        {
            var           info         = nodeInfo[currentIndex];
            HeaderConfig *headerConfig = (HeaderConfig *)(graph.value + info.nodeOffset).ToPointer();
            var           state        = stateLayout[currentIndex];

            if (accumulate)
            {
                state.globalBox += state.localBox;
                if (parentIndex >= 0)
                {
                    state.globalBox += stateLayout[parentIndex].inner;
                }
                stateLayout[currentIndex] = state;
            }
            if (headerConfig->IsDedicatedNode)
            {
                if (updateSubmeshCount)
                {
                    subMeshes[subMeshIndex] = new SubMeshInfo(++subMeshIndex, currentIndex);
                }
                renderNow = currentIndex == startIndex;
            }
            if (renderNow)
            {
                bool display = true;
                bool visible = true;
                if (graph.TryGetConfigBlock(currentIndex, UIConfigLayoutTable.DisplayConfig, out IntPtr displayConfig))
                {
                    var dc = ((DisplayConfig *)displayConfig.ToPointer());
                    display = dc->display == VisibilityStyle.Visible;
                    visible = dc->visible == VisibilityStyle.Visible;
                }
                if (display)
                {
                    FunctionPointer <UIRenderPass> render = headerConfig->schemaIndex >= 0 ? schema.Value.elements[headerConfig->schemaIndex].render : default;
                    if (render.IsCreated)
                    {
                        render.Invoke(
                            graph.value,
                            (NodeInfo *)UnsafeUtility.AddressOf(ref info),
                            (UIPassState *)UnsafeUtility.AddressOf(ref state),
                            (UIVertexData *)(((IntPtr)vertexData.GetUnsafePtr()) + (renderIndex * UnsafeUtility.SizeOf <UIVertexData>() * 4)).ToPointer(),
                            context
                            );
                    }
                    for (int j = 0; j < info.renderBoxCount; j++)
                    {
                        indices[(renderIndex + j) * 6]       = (ushort)((renderIndex + j) * 4);
                        indices[((renderIndex + j) * 6) + 1] = (ushort)(((renderIndex + j) * 4) + 2);
                        indices[((renderIndex + j) * 6) + 2] = (ushort)(((renderIndex + j) * 4) + 1);
                        indices[((renderIndex + j) * 6) + 3] = (ushort)(((renderIndex + j) * 4) + 2);
                        indices[((renderIndex + j) * 6) + 4] = (ushort)(((renderIndex + j) * 4) + 3);
                        indices[((renderIndex + j) * 6) + 5] = (ushort)(((renderIndex + j) * 4) + 1);
                        UpdateBounds(vertexData, (renderIndex + j) * 4, ref bounds);
                    }
                }
                if (!display || !visible)
                {
                    UnsafeUtility.MemClear((((IntPtr)vertexData.GetUnsafePtr()) + (renderIndex * UnsafeUtility.SizeOf <UIVertexData>() * 4)).ToPointer(), UnsafeUtility.SizeOf <UIVertexData>() * info.renderBoxCount * 4);
                    UnsafeUtility.MemClear((((IntPtr)indices.GetUnsafePtr()) + (renderIndex * UnsafeUtility.SizeOf <ushort>() * 6)).ToPointer(), UnsafeUtility.SizeOf <ushort>() * info.renderBoxCount * 6);
                }
                renderIndex += info.renderBoxCount;
            }
            for (int i = 0; i < headerConfig->childCount; i++)
            {
                RenderMesh(startIndex, currentIndex, UnsafeUtility.ReadArrayElement <int>((graph.value + info.childrenOffset).ToPointer(), i), vertexData, context, indices, graph, graphInfo, nodeInfo, stateLayout, subMeshes, renderNow, updateSubmeshCount, accumulate, ref subMeshIndex, ref renderIndex, ref bounds);
            }
        }
Exemplo n.º 7
0
        public static void Layout(int childIndex, IntPtr configPtr, NodeInfo *nodeInfo, IntPtr statePtr, UIContextData *context)
        {
            if (childIndex < 0)
            {
                UIPassState *     selfPtr          = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * nodeInfo->index)).ToPointer();
                IntPtr            configSource     = configPtr + nodeInfo->configOffset;
                BoxModelConfig *  boxConfig        = (BoxModelConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxModelConfig, configSource).ToPointer();
                BackgroundConfig *backgroundConfig = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer();
                BorderConfig *    borderConfig     = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer();
                SizeConfig *      sizeConfig       = (SizeConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.SizeConfig, configSource).ToPointer();

                BoxLayoutConfig *boxLayoutConfig = (BoxLayoutConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxLayoutConfig, configSource).ToPointer();
                HeaderConfig *   headerConfig    = (HeaderConfig *)(configPtr + nodeInfo->nodeOffset);
                float            height          = 0f;
                float            width           = 0f;
                float2           childrenSize    = default;
                int4             multiplier      = default;
                //float4 padding = boxConfig->padding.Normalize(*context);
                float4 constraints = new float4(
                    sizeConfig->minWidth.Normalize(*context), sizeConfig->maxWidth.Normalize(*context),
                    sizeConfig->minHeight.Normalize(*context), sizeConfig->maxHeight.Normalize(*context)
                    );
                var spacing = boxLayoutConfig->spacing.Normalize(*context);
                switch (boxLayoutConfig->direction)
                {
                case Direction.Left:
                    for (int i = 0; i < headerConfig->childCount; i++)
                    {
                        var childState = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), headerConfig->childCount - 1 - i))).ToPointer();
                        LayoutHorizontal(childState, ref width, ref height);
                        if (i + 1 < headerConfig->childCount)
                        {
                            width += spacing;
                        }
                    }
                    multiplier = new int4(1, 0, 0, 1);
                    break;

                case Direction.Right:
                    for (int i = 0; i < headerConfig->childCount; i++)
                    {
                        var childState = (UIPassState *)(statePtr + (UnsafeUtility.SizeOf <UIPassState>() * (UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), i)))).ToPointer();
                        LayoutHorizontal(childState, ref width, ref height);
                        if (i + 1 < headerConfig->childCount)
                        {
                            width += spacing;
                        }
                    }
                    multiplier = new int4(1, 0, 0, 1);
                    break;

                case Direction.Up:
                    for (int i = 0; i < headerConfig->childCount; i++)
                    {
                        var childState = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), i))).ToPointer();
                        LayoutVertical(childState, ref height, ref width);
                        if (i + 1 < headerConfig->childCount)
                        {
                            height += spacing;
                        }
                    }
                    multiplier = new int4(0, 1, 1, 0);
                    break;

                case Direction.Down:
                    for (int i = 0; i < headerConfig->childCount; i++)
                    {
                        var childState = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), headerConfig->childCount - 1 - i))).ToPointer();
                        LayoutVertical(childState, ref height, ref width);
                        if (i + 1 < headerConfig->childCount)
                        {
                            height += spacing;
                        }
                    }
                    multiplier = new int4(0, 1, 1, 0);
                    break;
                }
                childrenSize  = new float2(width, height);
                selfPtr->size = new float2(
                    math.clamp(childrenSize.x, constraints.x, constraints.y),
                    math.clamp(childrenSize.y, constraints.z, constraints.w)
                    );;
                UIJobUtility.AdjustPosition(childrenSize, constraints, boxLayoutConfig, selfPtr, statePtr, headerConfig->childCount, (configPtr + nodeInfo->childrenOffset).ToPointer(), multiplier);

                //Debug.Log(selfPtr->size);
            }
        }