From e8241058962202c4695b86ce6d87020d15955838 Mon Sep 17 00:00:00 2001 From: Rofli Sanches Date: Thu, 13 Jan 2022 23:59:22 -0300 Subject: [PATCH 1/3] feat: add imguiptr to font initialization event --- Source/Texture/TextureManager.cs | 8 +++++--- Source/UImGui.cs | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/Texture/TextureManager.cs b/Source/Texture/TextureManager.cs index e30dfa6..34e3445 100644 --- a/Source/Texture/TextureManager.cs +++ b/Source/Texture/TextureManager.cs @@ -6,6 +6,7 @@ using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using UnityEngine; +using UnityEngine.Events; using UTexture = UnityEngine.Texture; namespace UImGui.Texture @@ -101,7 +102,7 @@ private IntPtr RegisterTexture(UTexture texture) return id; } - public void BuildFontAtlas(ImGuiIOPtr io, in FontAtlasConfigAsset settings, UnityEngine.Events.UnityEvent custom) + public void BuildFontAtlas(ImGuiIOPtr io, in FontAtlasConfigAsset settings, UnityEvent custom) { if (io.Fonts.IsBuilt()) { @@ -117,13 +118,14 @@ public void BuildFontAtlas(ImGuiIOPtr io, in FontAtlasConfigAsset settings, Unit { if (custom.GetPersistentEventCount() > 0) { - custom.Invoke(); + custom.Invoke(io); } else { io.Fonts.AddFontDefault(); - io.Fonts.Build(); } + + io.Fonts.Build(); return; } diff --git a/Source/UImGui.cs b/Source/UImGui.cs index cf394f5..8144355 100644 --- a/Source/UImGui.cs +++ b/Source/UImGui.cs @@ -3,9 +3,9 @@ using UImGui.Platform; using UImGui.Renderer; using UnityEngine; +using UnityEngine.Events; using UnityEngine.Rendering; -#if HAS_HDRP -#endif + namespace UImGui { @@ -62,7 +62,7 @@ public class UImGui : MonoBehaviour }; [SerializeField] - private UnityEngine.Events.UnityEvent _fontCustomInitializer; + private UnityEvent _fontCustomInitializer; [SerializeField] private FontAtlasConfigAsset _fontAtlasConfiguration = null; From abb96d244f42d3fa06ba21b7602fb7e813f24a87 Mon Sep 17 00:00:00 2001 From: Rofli Sanches Date: Thu, 13 Jan 2022 23:59:35 -0300 Subject: [PATCH 2/3] doc: add instructions to use custom fonts --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 87f51b8..bda2dbf 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,46 @@ private unsafe int CustomCallback(ImGuiInputTextCallbackData* data) ``` ![image](https://user-images.githubusercontent.com/961971/120383734-a1ad4880-c2fb-11eb-87e1-398d5e7aac97.png) +Custom font + +[Thanks](https://github.com/psydack/uimgui/pull/24) +[Check here for more information](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md) + +- First create a method with ImGuiIOPtr like this +```cs +public void AddJapaneseFont(ImGuiIOPtr io) +{ + // you can put on StreamingAssetsFolder and call from there like: + //string fontPath = $"{Application.streamingAssetsPath}/NotoSansCJKjp - Medium.otf"; + string fontPath = "D:\\Users\\rofli.souza\\Desktop\\NotoSansCJKjp-Medium.otf"; + io.Fonts.AddFontFromFileTTF(fontPath, 18, null, io.Fonts.GetGlyphRangesJapanese()); + + // you can create a configs and do a lot of stuffs + //ImFontConfig fontConfig = default; + //ImFontConfigPtr fontConfigPtr = new ImFontConfigPtr(&fontConfig); + //fontConfigPtr.MergeMode = true; + //io.Fonts.AddFontDefault(fontConfigPtr); + //int[] icons = { 0xf000, 0xf3ff, 0 }; + //fixed (void* iconsPtr = icons) + //{ + // io.Fonts.AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, fontConfigPtr, (System.IntPtr)iconsPtr); + //} +} +``` +- Assign the object that contain these method in UImGui script +![image](https://user-images.githubusercontent.com/961971/149441417-54b319c8-30e7-40dd-aa56-edaede47543d.png) +- Call an awesome Text to text: +```cs +if (ImGui.Begin("ウィンドウテスト")) +{ + ImGui.Text("こんにちは!テスト"); + + ImGui.End(); +} +``` +![image](https://user-images.githubusercontent.com/961971/149443777-38f439f5-5aca-4188-a21b-32274e901382.png) +Yay! + You can [see more samples here](https://pthom.github.io/imgui_manual_online/manual/imgui_manual.html). Using URP @@ -295,7 +335,12 @@ Using URP Using HDRP ------- -- When using the ``High Definition Render Pipeline``, add a custom render pass and select "DearImGuiPass" injected after post processing. +- When using the ``High Definition Render Pipeline``; +- Add a script called Custom Pass Volume anywhere on your scene; +- Add "DearImGuiPass" +- Update Injection Point to before or after post processing. +- Good to go. +Any doubts [see this link](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@7.1/manual/Custom-Pass.html) Using Built in ------- @@ -314,6 +359,8 @@ Issue: Already using ``System.Runtime.CompilerServices.Unsafe.dll`` will cause t Resolution: add ``UIMGUI_REMOVE_UNSAFE_DLL`` on Project Settings > Player > Other Settings > Script define symbols > Apply > Restart Unity Editor. Issue: ImPlot isn't work right. + +Issue: Font atlas crash. There's no fix. Use callback for custom font instead Credits ------- From 9938acd73092bf91dd65553d9bc0bf5491bbdac9 Mon Sep 17 00:00:00 2001 From: Rofli Sanches Date: Fri, 14 Jan 2022 00:00:33 -0300 Subject: [PATCH 3/3] bump version 4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e39a89..5efbc0c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.psydack.uimgui", "displayName": "UImGui", - "version": "4.0.1", + "version": "4.1.0", "description": "A Unity wrapper for ImGui", "unity": "2019.4", "dependencies": {