コード例 #1
0
    void RebuildFonts()
    {
        ImGuiIOPtr io = ImGui.GetIO();

        // Default font
        ImFontAtlasPtr fonts = io.Fonts;

        fonts.Clear();
        using (ImFontConfig config = new ImFontConfig())
        {
            config.SizePixels  = 13.0f * uiScale;   // ImGui default font size is 13 pixels
            config.OversampleH = 1;
            fonts.AddFontDefault(config);
        }

#if !UNITY_ANDROID
        // Icon font
        if (iconFont.Length > 0)
        {
            using (ImFontConfig config = new ImFontConfig())
            {
                config.MergeMode = true;
                if (iconFontMinAdvanceX > 0)
                {
                    config.GlyphMinAdvanceX = iconFontMinAdvanceX;
                    config.GlyphMaxAdvanceX = iconFontMinAdvanceX;
                }
                config.PixelSnapH  = true;
                config.OversampleH = 1;
                ushort rangeMin = ushort.Parse(iconRangeMin, NumberStyles.HexNumber);
                ushort rangeMax = ushort.Parse(iconRangeMax, NumberStyles.HexNumber);
                if (rangeMin != 0 && rangeMax != 0)
                {
                    ushort[] icon_ranges = { rangeMin, rangeMax, 0 };
                    ImGui.AddFontFromFileTTF(fonts, Application.streamingAssetsPath + "/" + iconFont, iconFontPixelSize * uiScale, config, icon_ranges);
                }
            }
        }

        // Custom fonts
        imFonts = new ImFontPtr[customFonts.Length];
        for (int i = 0; i < customFonts.Length; i++)
        {
            using (ImFontConfig config = new ImFontConfig())
            {
                config.OversampleH = 1;
                config.OversampleV = 1;
                imFonts[i]         = fonts.AddFontFromFileTTF(Application.streamingAssetsPath + "/" + customFonts[i], customFontPixelSize * uiScale, config);
            }
        }
#endif

        if (useFreetype)
        {
            // Freetype rasterizer
            ImGui.BuildFontAtlas(fonts, freetype_flags);
        }
        else
        {
            fonts.Build();
        }
        RecreateFontTexture();
    }