public static void WriteCharRenderBoxes(UIPassState *state, IntPtr config, BackgroundConfig *backgroundConfig, BorderConfig *borderConfig, FontConfig *fontConfig, TextConfig *textConfig, UIVertexData *vertexPtr, UIContextData *context) { var height = fontConfig->size.Normalize(*context); var fontSizeScale = (height / textConfig->fontInfo.lineHeight) * textConfig->fontInfo.scale; float offsetX = state->globalBox.x; float offsetY = state->globalBox.y; var nullBg = new float3(float.NaN, float.NaN, float.NaN); float width = 0f; for (int i = 1; i < textConfig->text.length + 1; i++) { var charInfo = textConfig->GetCharInfo(config, i - 1); UnsafeUtility.WriteArrayElement(vertexPtr, i * 4, new UIVertexData { position = new float3(offsetX + (charInfo.metrics.horizontalBearingX * fontSizeScale), offsetY + (-textConfig->fontInfo.descentLine * fontSizeScale) + ((charInfo.metrics.horizontalBearingY - charInfo.metrics.height) * fontSizeScale), -0.002f), normals = new float3(0, 0, -1), background = nullBg, foreground = new float3(charInfo.uvs.x, charInfo.uvs.y, charInfo.index), color = fontConfig->color }); UnsafeUtility.WriteArrayElement(vertexPtr, (i * 4) + 1, new UIVertexData { position = new float3(offsetX + ((charInfo.metrics.horizontalBearingX + charInfo.metrics.width) * fontSizeScale), offsetY + (-textConfig->fontInfo.descentLine * fontSizeScale) + ((charInfo.metrics.horizontalBearingY - charInfo.metrics.height) * fontSizeScale), -0.002f), normals = new float3(0, 0, -1), background = nullBg, foreground = new float3(charInfo.uvs.x + charInfo.uvs.z, charInfo.uvs.y, charInfo.index), color = fontConfig->color }); UnsafeUtility.WriteArrayElement(vertexPtr, (i * 4) + 2, new UIVertexData { position = new float3(offsetX + (charInfo.metrics.horizontalBearingX * fontSizeScale), offsetY + (-textConfig->fontInfo.descentLine * fontSizeScale) + ((charInfo.metrics.horizontalBearingY - charInfo.metrics.height) * fontSizeScale) + (charInfo.metrics.height * fontSizeScale), -0.002f), normals = new float3(0, 0, -1), background = nullBg, foreground = new float3(charInfo.uvs.x, charInfo.uvs.y + charInfo.uvs.w, charInfo.index), color = fontConfig->color }); UnsafeUtility.WriteArrayElement(vertexPtr, (i * 4) + 3, new UIVertexData { position = new float3(offsetX + ((charInfo.metrics.horizontalBearingX + charInfo.metrics.width) * fontSizeScale), offsetY + (-textConfig->fontInfo.descentLine * fontSizeScale) + ((charInfo.metrics.horizontalBearingY - charInfo.metrics.height) * fontSizeScale) + (charInfo.metrics.height * fontSizeScale), -0.002f), normals = new float3(0, 0, -1), background = nullBg, foreground = new float3(charInfo.uvs.x + charInfo.uvs.z, charInfo.uvs.y + charInfo.uvs.w, charInfo.index), color = fontConfig->color }); offsetX += (charInfo.metrics.horizontalBearingX + charInfo.metrics.horizontalAdvance) * fontSizeScale; width += (charInfo.metrics.horizontalBearingX + charInfo.metrics.horizontalAdvance) * fontSizeScale; } //Write BG Box based on box defined by chars UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 0, new UIVertexData { background = new float3(backgroundConfig->image.value.x, backgroundConfig->image.value.y - backgroundConfig->image.value.w, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x, state->globalBox.y, -0.001f), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.top.Normalize(*context), borderConfig->width.left.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.left.Normalize(*context), borderConfig->width.top.Normalize(*context))), borderConfig->radius.topLeft.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 1, new UIVertexData { background = new float3(backgroundConfig->image.value.x + backgroundConfig->image.value.z, backgroundConfig->image.value.y - backgroundConfig->image.value.w, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x + width, state->globalBox.y, -0.001f), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.top.Normalize(*context), borderConfig->width.right.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.right.Normalize(*context), borderConfig->width.top.Normalize(*context))), borderConfig->radius.topRight.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 2, new UIVertexData { background = new float3(backgroundConfig->image.value.x, backgroundConfig->image.value.y, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x, state->globalBox.y + height, -0.001f), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.bottom.Normalize(*context), borderConfig->width.left.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.left.Normalize(*context), borderConfig->width.bottom.Normalize(*context))), borderConfig->radius.bottomLeft.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 3, new UIVertexData { background = new float3(backgroundConfig->image.value.x + backgroundConfig->image.value.z, backgroundConfig->image.value.y, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x + width, state->globalBox.y + height, -0.001f), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.bottom.Normalize(*context), borderConfig->width.right.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.right.Normalize(*context), borderConfig->width.bottom.Normalize(*context))), borderConfig->radius.bottomRight.Normalize(*context)), }); }
private static void SizeText(UIPassState *selfPtr, IntPtr configSource, TextConfig *textConfig, FontConfig *fontConfig, UIContextData *context) { var totalWidth = 0f; var height = fontConfig->size.Normalize(*context); var fontSizeScale = (height / textConfig->fontInfo.lineHeight) * textConfig->fontInfo.scale; for (int i = 0; i < textConfig->text.length; i++) { var charInfo = textConfig->GetCharInfo(configSource, i); totalWidth += (charInfo.metrics.horizontalBearingX + charInfo.metrics.horizontalAdvance) * fontSizeScale; } selfPtr->size = new float2(totalWidth + selfPtr->localBox.x + selfPtr->localBox.z, height + selfPtr->localBox.y + selfPtr->localBox.w); }
public static void WriteRenderBox(UIPassState *state, BackgroundConfig *backgroundConfig, BorderConfig *borderConfig, UIVertexData *vertexPtr, UIContextData *context) { UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 0, new UIVertexData { background = new float3(backgroundConfig->image.value.x, backgroundConfig->image.value.y - backgroundConfig->image.value.w, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x, state->globalBox.y, 0), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.top.Normalize(*context), borderConfig->width.left.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.left.Normalize(*context), borderConfig->width.top.Normalize(*context))), borderConfig->radius.topLeft.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 1, new UIVertexData { background = new float3(backgroundConfig->image.value.x + backgroundConfig->image.value.z, backgroundConfig->image.value.y - backgroundConfig->image.value.w, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x + state->size.x, state->globalBox.y, 0), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.top.Normalize(*context), borderConfig->width.right.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.right.Normalize(*context), borderConfig->width.top.Normalize(*context))), borderConfig->radius.topRight.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 2, new UIVertexData { background = new float3(backgroundConfig->image.value.x, backgroundConfig->image.value.y, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x, state->globalBox.y + state->size.y, 0), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.bottom.Normalize(*context), borderConfig->width.left.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.left.Normalize(*context), borderConfig->width.bottom.Normalize(*context))), borderConfig->radius.bottomLeft.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 3, new UIVertexData { background = new float3(backgroundConfig->image.value.x + backgroundConfig->image.value.z, backgroundConfig->image.value.y, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x + state->size.x, state->globalBox.y + state->size.y, 0), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.bottom.Normalize(*context), borderConfig->width.right.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.right.Normalize(*context), borderConfig->width.bottom.Normalize(*context))), borderConfig->radius.bottomRight.Normalize(*context)), }); }
public static void Render(IntPtr configPtr, NodeInfo *nodeInfo, UIPassState *statePtr, UIVertexData *vertexDataPtr, UIContextData *context) { IntPtr configSource = configPtr + nodeInfo->configOffset; TextConfig * textConfig = (TextConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.TextConfig, configSource).ToPointer(); BackgroundConfig *backgroundConfig = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer(); FontConfig * fontConfig = (FontConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.FontConfig, configSource).ToPointer(); BorderConfig * borderConfig = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer(); UIRenderBoxWriters.WriteCharRenderBoxes(statePtr, configPtr + nodeInfo->nodeOffset, backgroundConfig, borderConfig, fontConfig, textConfig, vertexDataPtr, context); }
public static void Layout(int childIndex, IntPtr configPtr, NodeInfo *nodeInfo, IntPtr statePtr, UIContextData *context) { if (childIndex < 0) { UIPassState * selfPtr = (UIPassState *)(statePtr + (UnsafeUtility.SizeOf <UIPassState>() * nodeInfo->index)).ToPointer(); IntPtr configSource = configPtr + nodeInfo->configOffset; TextConfig * textConfig = (TextConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.TextConfig, configSource).ToPointer(); BackgroundConfig *backgroundConfig = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer(); FontConfig * fontConfig = (FontConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.FontConfig, configSource).ToPointer(); BorderConfig * borderConfig = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer(); SizeText(selfPtr, configPtr + nodeInfo->nodeOffset, textConfig, fontConfig, context); } }
private void Render(NativeArray <UIVertexData> vertices, UIContextData *context, ref MeshData meshData, UIGraphData graph, NativeArray <NodeInfo> layout, GraphInfo graphInfo, NativeArray <UIPassState> stateLayout) { var indices = meshData.GetIndexData <ushort>(); var subMeshes = new NativeArray <SubMeshInfo>(graphInfo.subMeshCount, Allocator.Temp); int submeshIndex = 0; int renderIndex = 0; float4 bounds = float4.zero; RenderMesh(0, -1, 0, vertices, context, indices, graph, graphInfo, layout, stateLayout, subMeshes, true, true, true, ref submeshIndex, ref renderIndex, ref bounds); float4 totalBounds = bounds; int submesh0RenderIndexCount = renderIndex; for (int i = 0; i < subMeshes.Length; i++) { SubMeshInfo current = subMeshes[i]; var initialRenderIndex = renderIndex; RenderMesh(current.nodeIndex, -1, current.nodeIndex, vertices, context, indices, graph, graphInfo, layout, stateLayout, subMeshes, true, false, false, ref submeshIndex, ref renderIndex, ref bounds); totalBounds = new float4(math.min(totalBounds.x, bounds.x), math.min(totalBounds.y, bounds.y), math.max(totalBounds.z, bounds.z), math.max(totalBounds.w, bounds.w)); current.meshIndexStart = initialRenderIndex * 6; current.meshIndexCount = (renderIndex - initialRenderIndex) * 6; current.bounds = bounds; subMeshes[i] = current; for (int j = 0; j < (renderIndex - initialRenderIndex); j++) { for (int k = 0; k < 4; k++) { UIVertexData vertex = vertices[(initialRenderIndex + j) * 4 + k]; vertex.position.z -= 0.001f * (i + 1); vertices[(initialRenderIndex + j) * 4 + k] = vertex; } } } //Center Mesh float3 totalSize = new float3(math.abs(totalBounds.z - totalBounds.x), math.abs(totalBounds.y - totalBounds.w), 0f); var adjust = new float3(totalSize.x / 2f, totalSize.y / 2f, 0); for (int i = 0; i < vertices.Length; i++) { UIVertexData vertex = vertices[i]; vertex.position -= adjust; vertices[i] = vertex; } for (int i = 0; i < subMeshes.Length; i++) { SubMeshInfo current = subMeshes[i]; var size = new float3(math.abs(current.bounds.z - current.bounds.x), math.abs(current.bounds.y - current.bounds.w), 0.00001f); meshData.SetSubMesh(meshData.subMeshCount - (i + 1), new UnityEngine.Rendering.SubMeshDescriptor(current.meshIndexStart, current.meshIndexCount) { //bounds = new Bounds(new float3(current.bounds.x + (size.x / 2f), bounds.y + (size.y / 2f), 0f) - adjust, size), bounds = new Bounds(float3.zero, size), firstVertex = (current.meshIndexStart / 6) * 4, vertexCount = (current.meshIndexCount / 6) * 4 } //,MeshUpdateFlags.DontRecalculateBounds | MeshUpdateFlags.DontValidateIndices ); } meshData.SetSubMesh(0, new UnityEngine.Rendering.SubMeshDescriptor(0, submesh0RenderIndexCount * 6) { bounds = new Bounds(float3.zero, new float3(totalSize.x, totalSize.y, 0.00001f)), firstVertex = 0, vertexCount = submesh0RenderIndexCount * 4 } //,MeshUpdateFlags.DontRecalculateBounds | MeshUpdateFlags.DontValidateIndices ); subMeshes.Dispose(); }
private void Layout(int index, UIGraphData graph, NativeArray <NodeInfo> configLayout, NativeArray <UIPassState> stateLayout, UIContextData *context) { if (!graph.TryGetConfigBlock(index, UIConfigLayoutTable.DisplayConfig, out IntPtr displayConfig) || (((DisplayConfig *)displayConfig.ToPointer())->display == VisibilityStyle.Visible)) { var nodeInfo = configLayout[index]; var headerConfig = (HeaderConfig *)(graph.value + nodeInfo.nodeOffset).ToPointer(); var configSource = graph.value + nodeInfo.configOffset; var state = (UIPassState *)(((IntPtr)stateLayout.GetUnsafePtr()) + (UnsafeUtility.SizeOf <UIPassState>() * index)).ToPointer(); IntPtr boxConfig; bool hasBoxConfig = graph.TryGetConfigBlock(index, UIConfigLayoutTable.BoxModelConfig, out boxConfig); if (hasBoxConfig) { BoxModelConfig *boxConfigPtr = (BoxModelConfig *)boxConfig.ToPointer(); state->localBox += boxConfigPtr->margin.Normalize(*context); state->inner = boxConfigPtr->padding.Normalize(*context); } FunctionPointer <UILayoutPass> layout = headerConfig->schemaIndex >= 0 ? schema.Value.elements[headerConfig->schemaIndex].layout : default; for (int childIndex = 0; childIndex < headerConfig->childCount; childIndex++) { if (layout.IsCreated) { layout.Invoke( childIndex, graph.value, (NodeInfo *)UnsafeUtility.AddressOf(ref nodeInfo), (IntPtr)stateLayout.GetUnsafePtr(), context ); } Layout(UnsafeUtility.ReadArrayElement <int>((graph.value + nodeInfo.childrenOffset).ToPointer(), childIndex), graph, configLayout, stateLayout, context); } if (layout.IsCreated) { layout.Invoke( -1, graph.value, (NodeInfo *)UnsafeUtility.AddressOf(ref nodeInfo), (IntPtr)stateLayout.GetUnsafePtr(), context ); } if (graph.TryGetConfigBlock(index, UIConfigLayoutTable.SizeConfig, out IntPtr sizeConfig)) { var sizeConfigPtr = ((SizeConfig *)sizeConfig.ToPointer()); state->size = new float2( math.clamp(state->size.x, sizeConfigPtr->minWidth.Normalize(*context), sizeConfigPtr->maxWidth.Normalize(*context)), math.clamp(state->size.y, sizeConfigPtr->minHeight.Normalize(*context), sizeConfigPtr->maxHeight.Normalize(*context))); } if (hasBoxConfig) { state->size += new float2(state->inner.x + state->inner.z, state->inner.y + state->inner.w); } } }
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); } }
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); } }
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); }