Esempio n. 1
0
        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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 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);
     }
 }
        public override unsafe byte PostInit(TextConfig *value, IntPtr config, ulong mask, MemoryBinaryWriter extraBytesStream, long extraByteStreamOffset, UIPropertyWriterContext context)
        {
            TMP_FontAsset fontAsset     = null;
            var           fontConfigPtr = UIConfigUtility.GetConfig(mask, UIConfigLayoutTable.FontConfig, config);


            if (fontConfigPtr == IntPtr.Zero)
            {
                return(0);
            }
            FontConfig *fontConfig = ((FontConfig *)fontConfigPtr);
            var         guid       = fontConfig->asset.ToHex();

#if UNITY_EDITOR
            fontAsset = UnityEditor.AssetDatabase.LoadAssetAtPath <TMP_FontAsset>(UnityEditor.AssetDatabase.GUIDToAssetPath(guid));
#else
//var task = Addressables.LoadAssetAsync<TMP_FontAsset>(guid);
//fontAsset = AssetDatabase.LoadAssetAtPath<TMP_FontAsset>(AssetDatabase.GUIDToAssetPath(guid));
#endif
            var index = context.group.GetAtlasIndex(guid);
            if (fontAsset != null && index >= 0)
            {
                value->fontInfo       = new FontInfo(fontAsset);
                value->charInfoOffset = extraBytesStream.Length;
                for (int charIndex = 0; charIndex < value->text.length; charIndex++)
                {
                    UnsafeUtility.CopyPtrToStructure(new IntPtr(((IntPtr)extraBytesStream.Data).ToInt64() + (value->text.offset - extraByteStreamOffset) + (charIndex * 2)).ToPointer(), out char character);
                    var charInfo      = fontAsset.characterLookupTable[character];
                    var charInfoValue = new CharInfo
                    {
                        uvs     = new float4(charInfo.glyph.glyphRect.x / (float)fontAsset.atlasWidth, charInfo.glyph.glyphRect.y / (float)fontAsset.atlasHeight, charInfo.glyph.glyphRect.width / (float)fontAsset.atlasWidth, charInfo.glyph.glyphRect.height / (float)fontAsset.atlasHeight),
                        metrics = charInfo.glyph.metrics,
                        index   = (byte)index,
                        unicode = charInfo.unicode
                    };
                    extraBytesStream.WriteBytes(UnsafeUtility.AddressOf(ref charInfoValue), UnsafeUtility.SizeOf <CharInfo>());
                }
                value->charInfoLength = value->text.length;
                //value->charInfoLength = (int)((extraBytesStream.Length - value->charInfoOffset) / UnsafeUtility.SizeOf<CharInfo>());
                value->charInfoOffset += extraByteStreamOffset;
            }
            return(0);
        }
Esempio n. 5
0
        public static int RenderBoxCount(IntPtr configPtr, NodeInfo *nodeInfo)
        {
            TextConfig *config = (TextConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.TextConfig, configPtr + nodeInfo->configOffset).ToPointer();

            return(config->text.length + 1);
        }
Esempio n. 6
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);
            }
        }