블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2731)
Unity3D (814)
Script (91)
Extensions (14)
Effect (3)
NGUI (77)
UGUI (8)
Physics (2)
Shader (36)
Math (1)
Design Pattern (2)
Xml (1)
Tips (200)
Link (22)
World (1)
AssetBundle (25)
Mecanim (2)
Plugins (68)
Trouble Shooting (68)
Encrypt (7)
LightMap (4)
Shadow (4)
Editor (8)
Crash Report (3)
Utility (9)
UnityVS (2)
Facebook SDK (2)
iTween (3)
Font (10)
Ad (14)
Photon (2)
IAP (1)
Google (8)
Android (45)
iOS (41)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (57)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (51)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
03-29 07:22

Unity 2021.3.33f1

NGUI 2023.08.01

----

 

NGUI-UILabel의 Effect에서 Shadow와 Outline을 같이 적용하고 싶어서 찾아보고 올려둠.

UILabel에 세 곳에 소스 추가

public class UILabel : UIWidget
{
    ....
    
    [DoNotObfuscateNGUI] public enum Effect
    {
        None,
        Shadow,
        Outline,
        Outline8,
        ShadowAndOutline,	// Add
    }   
    
    ....
    
    /// <summary>
    /// How many quads there are per printed character.
    /// </summary>

    public int quadsPerCharacter
    {
        get
        {
            if (mEffectStyle == Effect.Shadow) return 2;
            else if (mEffectStyle == Effect.Outline) return 5;
            else if (mEffectStyle == Effect.Outline8) return 9;
            else if (mEffectStyle == Effect.ShadowAndOutline) return 9;	// Add
            return 1;
        }
    }

	....
    
    public void Fill (List<Vector3> verts, List<Vector2> uvs, List<Color> cols, List<Vector3> symbolVerts, List<Vector2> symbolUVs, List<Color> symbolCols)
	{
        ...
        // Apply an effect if one was requested
		if (effectStyle != Effect.None)
		{
			int end = verts.Count;
			var symEnd = (symbolVerts != null) ? symbolVerts.Count : 0;

			pos.x = mEffectDistance.x;
			pos.y = mEffectDistance.y;

			ApplyShadow(verts, uvs, cols, offset, end, pos.x, -pos.y);
			if (symbolVerts != null) ApplyShadow(symbolVerts, symbolUVs, symbolCols, symOffset, symEnd, pos.x, -pos.y);

            #region Add ShadowAndOutline
            if (effectStyle == Effect.ShadowAndOutline)
            {
                pos.y /= 2;
                pos.x = pos.y;

                offset = end;
                end = verts.Count;

                ApplyShadow(verts, uvs, cols, offset, end, -pos.x, pos.y);

                offset = end;
                end = verts.Count;

                ApplyShadow(verts, uvs, cols, offset, end, pos.x, pos.y);

                offset = end;
                end = verts.Count;

                ApplyShadow(verts, uvs, cols, offset, end, -pos.x, -pos.y);

                offset = end;
                end = verts.Count;

                ApplyShadow(verts, uvs, cols, offset, end, -pos.x, 0);

                offset = end;
                end = verts.Count;

                ApplyShadow(verts, uvs, cols, offset, end, pos.x, 0);

                offset = end;
                end = verts.Count;

                ApplyShadow(verts, uvs, cols, offset, end, 0, pos.y);

                offset = end;
                end = verts.Count;

                ApplyShadow(verts, uvs, cols, offset, end, 0, -pos.y);
            }
			#endregion

            if ((effectStyle == Effect.Outline) || (effectStyle == Effect.Outline8))
			{        
        ...
    }
	
}

 

 

[출처] https://gamedev.stackexchange.com/questions/151329/all-sides-shadow-outline-in-unity-ngui

 

All sides shadow outline in Unity NGUI

How can I make such exactly the same shadow using NGUI?

gamedev.stackexchange.com

 

반응형
Posted by blueasa
, |

[링크] https://cho22.tistory.com/55

 

[UnityNGUI] ScrollView에 Particle Clipping하기

NGUI 스크롤뷰 내부에 파티클이 붙어있는 아이템을 추가했더니 스크롤시 스크롤뷰 밖에서 파티클이 보이는 현상이 발생하였다. 이 현상 수정을 위해 NGUI Particle Clipping, 유니티 파티클 스크롤뷰,

cho22.tistory.com

 

 

 

 

반응형
Posted by blueasa
, |

Unity 2022.3.10f1

NGUI 2022.08.01

----

[추가2] 2023-10-25

NGUI v2023.07.26에서 아래와 같은 업데이트가 올라왔다.

- FIX: NGUI will now change all imported textures to be uncompressed when creating an atlas, matching how it used to work in older versions of Unity.

이 수정 사항 때문에 NGUI Atlas 압축을 유지해주려던 부분이 작동하지 않고 무조건 Uncompressed로 변경되고 있어서 해당 부분인 아래 소스 부분(NGUIEditorTools.cs : line 538)을 주석 처리 했다.

//-------------------------------------------------
//			  NGUI: Next-Gen UI kit
// Copyright © 2011-2023 Tasharen Entertainment Inc
//-------------------------------------------------

using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;

/// <summary>
/// Tools for the editor
/// </summary>

static public class NGUIEditorTools
{
    ...
    static public bool MakeTextureReadable (string path, bool force)
    {
        if (string.IsNullOrEmpty(path)) return false;
        var ti = AssetImporter.GetAtPath(path) as TextureImporter;
        if (ti == null) return false;

        var settings = new TextureImporterSettings();
        ti.ReadTextureSettings(settings);

        if (force || !settings.readable || settings.npotScale != TextureImporterNPOTScale.None || ti.textureCompression != TextureImporterCompression.Uncompressed)
        {
            settings.readable = true;

            if (NGUISettings.trueColorAtlas)
            {
                var platform = ti.GetDefaultPlatformTextureSettings();
                platform.format = TextureImporterFormat.RGBA32;
            }

            settings.npotScale = TextureImporterNPOTScale.None;
            
            #region NGUI Atlas 압축 관련 처리 [blueasa / 2023-10-25]
            /// NGUI v2023.07.26 에서 강제로 Uncompressed 하는 소스가 추가됨.
            /// 이 부분 때문에 아틀라스 압축이 유지되지 않고 풀리는 문제가 있어서 주석 처리 함
            /// trueColorAtlas 셋팅 될 때만 Uncompressed 강제 하도록 함
            if (NGUISettings.trueColorAtlas)
            {
                ti.textureCompression = TextureImporterCompression.Uncompressed;
            }
            #endregion
            
            ti.SetTextureSettings(settings);

#if UNITY_5_6
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
#else
            ti.SaveAndReimport();
#endif
        }
        return true;
    }
    ...
}

 

----

[추가]

아틀라스 압축을 사용하려면 Atlas Maker의 Truecolor를 끄자.

(켜놓으면 압축상태를 무시하고 무조건 Truecolor로 아틀라스를 묶어낸다.)

Truecolor 체크 해제

----

 

[수정] New Atlas 관련 예외처리 추가(2023-04-12)

 

----

게임 최적화를 위해 Andrio/iOS 둘다 설정에서 Texture compression format을 ASTC로 설정하고 사용하고 있다.

NGUI Atlas도 최적화를 위해 Compression을 High Quality로 사용중인데

여기서 문제가 NGUI의 Atlas를 묶을 때는 Compression이 None(비압축)이 아니면 에러가 발생한다.

 

그래서 Atlas 묶을 때는 Compression을 None으로 풀어서 묶은 다음 원래 Compression인 High Quality로 변경하고 있었는데

불편하기도하고 사용하다 실수가 나오기도 해서 이참에 NGUI Atlas Maker를 수정해서 자동으로 되도록 했다.

 

작동 원리는 아래와 같이 간단하다.

(처음 해보는거라 적용 지점이 어딘지 찾는다고 좀 헤멤)

 

  [작동 원리]

----------------------------------------------------

- Atlas가 압축 된 상태면

  1. Compression 별도로 저장

  2. Compression : None으로 변경

  3. Atlas Make(NGUI 원래 소스)

  4. 별도로 저장했던 Compression을 Atlas에 적용해서 원래 압축 상태로 되돌려 줌

- Atlas가 압축 안된 상태(None)면

  1. 원래 소스만 실행(위에서 3.만 실행)

----------------------------------------------------

 

추가된 소스는 NGUI의 UIAtlasMaker.cs - UpdateTexture() 함수에 두 곳 추가 되었다.

소스 위치를 알기 위해 UpdateTexutre() 함수 전체를 올렸고, blueasa를 찾으면 region 정리해 둔 두 곳이 있다.

 

//-------------------------------------------------
//            NGUI: Next-Gen UI kit
// Copyright © 2011-2020 Tasharen Entertainment Inc
//-------------------------------------------------

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

/// <summary>
/// Atlas maker lets you create atlases from a bunch of small textures. It`s an alternative to using the external Texture Packer.
/// </summary>
public class UIAtlasMaker : EditorWindow
{
	....
    
    /// <summary>
    /// Combine all sprites into a single texture and save it to disk.
    /// </summary>
    
    static public bool UpdateTexture (INGUIAtlas atlas, List<SpriteEntry> sprites)
    {
        // Get the texture for the atlas
        var tex = atlasTexture;
        var oldPath = (tex != null) ? AssetDatabase.GetAssetPath(tex.GetInstanceID()) : "";
        var newPath = NGUIEditorTools.GetSaveableTexturePath(atlas as UnityEngine.Object, atlasTexture);
    
        // Clear the read-only flag in texture file attributes
        if (System.IO.File.Exists(newPath))
        {
            System.IO.FileAttributes newPathAttrs = System.IO.File.GetAttributes(newPath);
            newPathAttrs &= ~System.IO.FileAttributes.ReadOnly;
            System.IO.File.SetAttributes(newPath, newPathAttrs);
        }
    
        bool newTexture = (tex == null || oldPath != newPath);
    
        if (newTexture)
        {
            // Create a new texture for the atlas
            tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
        }
        else
        {
            // Make the atlas readable so we can save it
            tex = NGUIEditorTools.ImportTexture(oldPath, true, false, false);
        }
    
        #region NGUI Atlas 압축 관련 처리 [blueasa / 2023-04-07]
        /// NGUI Atlas가 압축돼 있으면,
        /// 압축 해제한 다음 Atlas 만든 후 원래 압축으로 돌리도록 함
    
        // TextureImporter 가져오기
        string strPath = AssetDatabase.GetAssetPath(tex);
        TextureImporter tiAtlas = AssetImporter.GetAtPath(strPath) as TextureImporter;
        TextureImporterCompression ticTextureCompression_Original = TextureImporterCompression.Uncompressed;
        bool bTextureCompressed = false;
    
        // New Atlas 관련 예외처리(New Atlas는 로직 타지 않도록 수정)
        if (false == newTexture)
        {
            Debug.LogWarningFormat("[Atlas TextureCompression] {0}", tiAtlas.textureCompression);
    
            if (tiAtlas.textureCompression != TextureImporterCompression.Uncompressed)
            {
                // Atlas Texutre 압축 여부
                bTextureCompressed = true;
                // 압축 설정 백업
                ticTextureCompression_Original = tiAtlas.textureCompression;
                // 압축 설정 변경
                tiAtlas.textureCompression = TextureImporterCompression.Uncompressed;
                // 변경 내용 적용
                AssetDatabase.ImportAsset(strPath);
            }
        }
        #endregion
    
        // Pack the sprites into this texture
        if (PackTextures(tex, sprites))
        {
            var bytes = tex.EncodeToPNG();
            System.IO.File.WriteAllBytes(newPath, bytes);
            bytes = null;
        
            // Load the texture we just saved as a Texture2D
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
            tex = NGUIEditorTools.ImportTexture(newPath, false, true, !premultipliedAlpha);
        
            // Update the atlas texture
            if (newTexture)
            {
                if (tex == null)
                {
                    Debug.LogError("Failed to load the created atlas saved as " + newPath);
                    EditorUtility.ClearProgressBar();
                }
                else
                {
                    var mat = spriteMaterial;
        
                    if (mat == null)
                    {
                        var matPath = newPath.Replace(".png", ".mat");
                        var shader = Shader.Find(NGUISettings.atlasPMA ? "Unlit/Premultiplied Colored" : "Unlit/Transparent Colored");
                        mat = new Material(shader);
	    
                        // Save the material
                        AssetDatabase.CreateAsset(mat, matPath);
                        AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
        
                        // Load the material so it`s usable
                        mat = AssetDatabase.LoadAssetAtPath<Material>(matPath);
                        spriteMaterial = mat;
                    }
        
                    mat.mainTexture = tex;
                }
        
                ReleaseSprites(sprites);
        
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
            }
        
            #region NGUI Atlas 압축 관련 처리 [blueasa / 2023-04-07]
            if (true == bTextureCompressed)
            {
                // 압축 설정 복원
                tiAtlas.textureCompression = ticTextureCompression_Original;
                // 변경 내용 적용
                AssetDatabase.ImportAsset(strPath);
            }
            #endregion
        
            return true;
        }
        else
        {
            if (!newTexture) NGUIEditorTools.ImportTexture(oldPath, false, true, !premultipliedAlpha);
    
            //Debug.LogError("Operation canceled: The selected sprites can`t fit into the atlas.\n" +
            //	"Keep large sprites outside the atlas (use UITexture), and/or use multiple atlases instead.");
    
            EditorUtility.DisplayDialog("Operation Canceled", "The selected sprites can`t fit into the atlas.\n" +
                    "Keep large sprites outside the atlas (use UITexture), and/or use multiple atlases instead", "OK");
            return false;
        }
    }
    
    ....
}

 

 

반응형
Posted by blueasa
, |

[링크] https://specialmylife.tistory.com/entry/NGUI-%EC%9C%A0%EC%9A%A9%ED%95%9C-%EB%A7%81%ED%81%AC

 

NGUI 유용한 링크

NGUI 유용한 링크Alpha-based hit detection Nicki's Depth Management system Improved Localization System How to make health bars Action Bar system Packed Font with Outline/Shadow Font using Alpha-tested magnification (Valve's approach) Atlas switching /

specialmylife.tistory.com

 

반응형
Posted by blueasa
, |

Unity 2021.3.14f1

NGUI 2022.06.08

 

NGUI의 UILabel에 있는 Dynamic Font 글자 사용시 가끔 글자가 깨졌다가 돌아오는 현상이 있어서 수정함.

 

UILabel에서 글자가 깨지는 이유는 Dynamic Font Texture 사이즈가 256x256을 기본으로 쓰다가,

텍스쳐 사이즈가 모자라면 512x512로 늘리는데 사이즈가 변경되는 시점에 잠시 글자가 깨졌다가 보이게 된다고 한다.

그래서 사이즈 변경할 필요 없게 사용하는 폰트의 글자를 모두 로드해 버리기로 했다.

(아래 첨부된 txt 파일의 글자를 로드하니 2048x2048이 나온다. 처음부터 로드하고 써버리기로 함.)

 

아래 [참조]링크의 소스를 참조해서 정리해서 아래와 같이 FontManager에 적용했다.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FontManagerSGT : MonoSingleton<FontManagerSGT>
{
    public delegate void OnChangeFontDelegate(eLanguage _eLanguage);
    public static event OnChangeFontDelegate OnChangeFontEvent;

    public NGUIFont m_nguiFontMain_Dynamic;
    public Font m_fontMain_GO;  // Global
    public Font m_fontMain_JA;  // Japan

    private eLanguage m_eLanguage_Prev = eLanguage.None;
    private eLanguage m_eLanguage_Current = eLanguage.None;

    private string m_strReferenceTxt_GO = null;
    private string m_strReferenceTxt_JA = null;
    private Texture m_textureFontMainTexture = null;
    private TextAsset m_textReferenceTxt = null;


    void Start()
    {
        SetDontDestroy();
    }

    void OnEnable()
    {

    }

    void OnDisable()
    {

    }

    public void SetFont(eLanguage _eLanguage)
    {
        // 폰트매니저용 언어로 변경(JA 외는 GO(글로벌)로 변환)
        m_eLanguage_Current = GetLanguageForFont(_eLanguage);

        ChangeFont(m_eLanguage_Current);
        m_eLanguage_Prev = m_eLanguage_Current;
    }

    public eLanguage GetLanguageForFont(eLanguage _eLanguage)
    {
        switch (_eLanguage)
        {
            // Japan
            case eLanguage.JA:
                return eLanguage.JA;

            // Global(Less)
            default:
                return eLanguage.GO;
        }
    }

    void ChangeFont(eLanguage _eLanguage)
    {
        Debug.LogFormat("[eLanguage] [Prev] {0} [Current] {1}", m_eLanguage_Prev, _eLanguage);

        // 같은 폰트면 Pass
        if (m_eLanguage_Prev == _eLanguage)
            return;

        Debug.Assert(null != m_nguiFontMain_Dynamic);
        Debug.Assert(null != m_fontMain_GO);
        Debug.Assert(null != m_fontMain_JA);

        switch (_eLanguage)
        {
            // Japan
            case eLanguage.JA:
                {
                    m_nguiFontMain_Dynamic.dynamicFont = m_fontMain_JA;
                    FixBrokenWord_JA();
                }
                break;

            // Global(Less)
            default:
                {
                    m_nguiFontMain_Dynamic.dynamicFont = m_fontMain_GO;
                    FixBrokenWord_GO();
                }
                break;
        }

        OnChangeFontEvent?.Invoke(_eLanguage);
    }

    void FixBrokenWord_JA()
    {
        if (m_strReferenceTxt_JA == null)
        {
            m_textReferenceTxt = Resources.Load("ReferenceTxt/ja") as TextAsset;
            if (null != m_textReferenceTxt)
            {
                m_strReferenceTxt_JA = m_textReferenceTxt.ToString();
            }
        }

        if (null != m_strReferenceTxt_JA)
        {
            m_fontMain_JA.RequestCharactersInTexture(m_strReferenceTxt_JA);
            m_textureFontMainTexture = m_fontMain_JA.material.mainTexture; // Font 내부 텍스쳐
            Debug.LogWarning(string.Format("[m_strReferenceTxt_JA] texture : {0}x{1}", m_textureFontMainTexture.width, m_textureFontMainTexture.height)); // 텍스쳐 크기
        }
        else
        {
            Debug.LogWarning("m_strReferenceTxt_JA is null");
        }
    }

    void FixBrokenWord_GO()
    {
        if (m_strReferenceTxt_GO == null)
        {
            m_textReferenceTxt = Resources.Load("ReferenceTxt/go") as TextAsset;
            if (null != m_textReferenceTxt)
            {
                m_strReferenceTxt_GO = m_textReferenceTxt.ToString();
            }
        }

        if (null != m_strReferenceTxt_GO)
        {
            m_fontMain_GO.RequestCharactersInTexture(m_strReferenceTxt_GO);
            m_textureFontMainTexture = m_fontMain_GO.material.mainTexture; // Font 내부 텍스쳐
            Debug.LogWarning(string.Format("[m_fontMain_GO] texture : {0}x{1}", m_textureFontMainTexture.width, m_textureFontMainTexture.height)); // 텍스쳐 크기
        }
        else
        {
            Debug.LogWarning("m_strReferenceTxt_GO is null");
        }
    }
}

 

GO(Global)는 JA(일본어)를 제외한 모든 폰트를 합친 글로벌용 폰트이다.

일본어 한자가 중국어(번체)(대만)와 ASCII 코드가 겹치는 문제로 폰트 자체를 분리했다.

 

소스상에서 Resources.Load 하고 있는 go.txt와 ja.txt는 아래 올려둔다.

폰트를 2개로 분리해놔서 해당 폰트 사용 시, 맞는 txt를 로드하기 위해 Load 파일도 2개이다.

 

첨부된 파일은 폰트 병합 할 때 쓰는 참조용 데이터이기 때문에 모두 로드하면 폰트에 있는 모든 글자를 쓰게 되므로 이걸 로드해서 쓰게되면 더이상 텍스쳐가 커질일은 없을거라 예상된다.

 

 

[폰트 텍스쳐 확장을 위한 참조용 txt 파일]

go.txt
0.03MB
ja.txt
0.01MB

 

 

[참조] https://blueasa.tistory.com/2688

 

[펌] Unity 동적 글꼴 텍스트 깨짐 솔루션(Dynamic Font Broken)

Unity의 동적 글꼴을 사용하여 텍스트를 그릴 때 두 개의 UI 인터페이스가 열리면 그 뒤에 있는 텍스트가 깨집니다(완전히 엉망이 됨). 내가 사용하는 UI 플러그인은 Daikon Forge입니다. 라벨 업데이

blueasa.tistory.com

[참조2] https://blueasa.tistory.com/2664

 

[펌] NGUI - Dynamic Font 글자 깨짐? 사라짐? 현상

게임도중 핸드폰에서 Home 키를 눌러 배경화면으로 이동 후 Server와 끊기기를 기다리고 다시 Server와 리커넥팅 되도록 해서 팝업 떴는데.. Font가 깨졌다. 뭐지.. .... UILabel 에서 DynamicFont 가 이상한

blueasa.tistory.com

 

반응형
Posted by blueasa
, |

프로젝트는 NGUI를 사용하며 최근에 로딩 인터페이스의 프롬프트 텍스트가 깨지는 버그가 발생했습니다.


다음 기사를 참조했습니다.

http://blog.csdn.net/langresser_king/article/details/22095235

이 문제가 발생하는 이유를 먼저 이해합시다.



이해해야 할 것은 NGUI의 UILabel은 Unity에서 제공하는 글꼴을 글꼴의 입력으로 사용한다는 것입니다.

Unity는 글꼴 생성에 대해 매우 경제적이며 이는 정상적인 엔진이며 엔진은 이와 같아야 합니다.



(1) Loading 인터페이스의 UILabel에 세 단어 로딩을 표시하면 Unity가 이 세 단어의 텍스처를 생성하고 128x128의 FontTexture가 충분해야 합니다. 그런 다음 UILabel은 글꼴에 따라 각 단어의 그래픽을 가져옵니다.



(2) 그런 다음 다른 인터페이스를 열고 이 인터페이스에 많은 문자가 있을 때 128x128 FontTexture가 충분하지 않으면 Unity는 새 FontTexture를 생성하고 콜백을 발생시킵니다.

(3) 그런 다음 NGUI의 UILabel에서 이 콜백을 처리하고 모든 UILabel을 트래버스하고 UILabel의 모든 내용을 Font에 푸시하여 FontTexture에 대한 새 텍스트 그래픽을 생성합니다.

static BetterList<UILabel> mList = new BetterList<UILabel>();
protected override void OnInit ()
{
    base.OnInit();
    mList.Add(this);
    SetActiveFont(trueTypeFont);
}

 

//每次新建一个UILabel,都会读取UILabel上面的内容,在FontTexture上添加一块字体纹理。当FontTexture超过了原来的大小时,就会抛弃原来的FontTexture,用一个新的FontTexture,然后遍历所有的UILabel,往新的FontTexture上添加字体纹理。
static void OnFontTextureChanged ()
{
    for (int i = 0; i < mList.size; ++i)
    {
        UILabel lbl = mList[i];
 
        if (lbl != null)
        {
            Font fnt = lbl.trueTypeFont;
 
            if (fnt != null)
            {
                fnt.RequestCharactersInTexture(lbl.mText, lbl.mPrintedSize, lbl.mFontStyle);
            }
        }
    }
 
    //这段代码让UILabel重新读取UV 重新渲染,下一帧文字就是正常的了
    for (int i = 0; i < mList.size; ++i)
    {
        UILabel lbl = mList[i];
 
        if (lbl != null)
        {
            Font fnt = lbl.trueTypeFont;
 
            if (fnt != null)
            {
                lbl.RemoveFromPanel();
                lbl.CreatePanel();
            }
        }
    }
}


(4) 마지막으로 UILabel이 다시 렌더링됩니다.

깨진 글꼴은 (2)에서 나타납니다 UILabel이 이미 렌더링 중일 때 Unity는 새 FontTexture를 생성하므로 현재 프레임에 표시되는 그래픽에 문제가 있을 것입니다.

해결책은 게임의 모든 캐릭터를 포함하여 처음에 글꼴에 충분한 텍스트를 제공하여 향후 게임을 푸시할 필요가 없고 FontTexture를 영원히 사용할 수 있도록 하는 것입니다.

UILabel에 기능 추가

    private static void DynamicFontBrokenFix(Font fnt)
    {
        if(fnt==null)
        {
            return;
        }
 
        if(fnt.characterInfo.Length<500)
        {
            string tmpStr = Resources.Load<TextAsset>("DynamicFontBrokenFix").text;
            fnt.RequestCharactersInTexture(tmpStr, 32);
        }
    }


그런 다음 글꼴을 설정할 때 호출

protected void SetActiveFont (Font fnt)
{
    if (mActiveTTF != fnt)
    {
        if (mActiveTTF != null)
        {
            int usage;
 
            if (mFontUsage.TryGetValue(mActiveTTF, out usage))
            {
                usage = Mathf.Max(0, --usage);
 
                if (usage == 0)
                {
                    mActiveTTF.textureRebuildCallback = null;
                    mFontUsage.Remove(mActiveTTF);
                }
                else
                {
                    mFontUsage[mActiveTTF] = usage;
                }
            }
			else
            {
            	mActiveTTF.textureRebuildCallback = null;
            }
		}
 
		mActiveTTF = fnt;
        DynamicFontBrokenFix(mActiveTTF);
 
		if (mActiveTTF != null)
		{
			int usage = 0;
 
			// Font hasn't been used yet? Register a change delegate callback
			if (!mFontUsage.TryGetValue(mActiveTTF, out usage))
				mActiveTTF.textureRebuildCallback = OnFontTextureChanged;
#if UNITY_FLASH
			mFontUsage[mActiveTTF] = usage + 1;
#else
			mFontUsage[mActiveTTF] = ++usage;
#endif
		}
	}
}


DynamicFontBrokenFix는 게임의 모든 문자를 저장하는 텍스트입니다.
http://blog.csdn.net/huutu http://www.liveslives.com에서 전송됨

FontTexture가 여러 번 생성되는 것을 방지하기 위한 최적화 지점이기도 합니다.

 

[출처] https://blog.csdn.net/huutu/article/details/61923191

 

NGUI UILabel 文字破碎__Captain的博客-CSDN博客

项目使用NGUI,最近碰到 Loading界面的提示文字破碎的Bug。 参考了以下文章 http://blog.csdn.net/langresser_king/article/details/22095235 转自http://blog.csdn.net/huutu http://www.liveslives.com 下面先来了解一下为什么会

blog.csdn.net

 

반응형
Posted by blueasa
, |

Unity의 동적 글꼴을 사용하여 텍스트를 그릴 때 두 개의 UI 인터페이스가 열리면 그 뒤에 있는 텍스트가 깨집니다(완전히 엉망이 됨). 내가 사용하는 UI 플러그인은 Daikon Forge입니다. 라벨 업데이트 메커니즘으로 인해 최종 성능이 깨진 텍스트 표시보다 나쁠 수 있습니다. 텍스트 컨트롤이 계속 새로 고쳐지고 열릴 새 인터페이스가 표시되지 않을 가능성이 큽니다.

         이것은 근본적으로 Unity의 동적 글꼴 구현이 충분히 똑똑하지 않다는 사실 때문입니다. 이론적으로 NGUI에도 이러한 문제가 있습니다. 동적 글꼴을 사용하고 많은 텍스트를 렌더링하는 한.

         NGUI와 Daikon Forge는 동적 글꼴인 텍스트를 그릴 때 내부적으로 Unity의 글꼴을 사용합니다. RequestCharactersInTexture 함수를 사용하여 글꼴에 텍스트 정보 업데이트를 요청한 다음 GetCharacterInfo를 사용하여 렌더링할 텍스트 정보를 가져옵니다. GetCharacterInfo를 호출할 때 RequestCharactersInTexture를 통해 모든 텍스트가 요청되었는지 확인하십시오.

         요청 시점에 Font 내부에 유지되는 텍스처가 충분하지 않으면 textureRebuildCallback의 콜백이 트리거되어 Font를 사용하는 외부 객체에 내부 텍스처가 업데이트되었고 외부 객체를 새로 고쳐야 함을 알립니다.

        Unity 글꼴의 기본 텍스처 크기는 256x256이며 순수 영어 글꼴의 경우에는 충분합니다. 하지만 한자나 일본어 같은 동양글꼴은 전혀 부족하다. 앞에서 언급한 두 플러그인은 텍스트를 그릴 때 단락을 요청하는 데 사용되며, Unity의 새로 고침 콜백이 트리거되면 모든 텍스트 컨트롤이 새로 고쳐집니다. 이렇게 하면 글꼴이 쉽게 깨질 수 있습니다. 정상적인 상황에서는 한 번에 많은 텍스트를 요청하지 않으며 사용된 텍스처는 256x256을 초과하지 않으며 Unity는 텍스처 크기를 자동으로 확장하지 않습니다. 그리고 콜백 함수에서 글꼴을 다시 새로 고칠 때 텍스처가 충분하지 않아 다른 새로 고침 콜백을 트리거하기 쉽습니다. 따라서 중단되고 지속적으로 새로 고쳐지는 상황을 표시하기 위해 텍스트 컨트롤이 전송됩니다.

        문제의 원인을 알면 해결책이 나옵니다. 충분한 텍스트를 요청하는 한 Unity는 내부적으로 텍스처 크기를 자동으로 확장하므로 지속적인 새로 고침 상황을 피할 수 있습니다. 한자 2000자 텍스트를 준비했는데, 텍스트 정보 요청 후 내부 텍스쳐를 기본적으로 게임에 충분한 크기인 1024x1024 크기로 확장했습니다. 어느 날 이것이 충분하지 않다고 생각되면 한자를 더 준비하고 질감을 2048x1024로 확장하십시오.

 

static string chineseTxt = null;
public UnityEngine.Font baseFont;

public void FixBrokenWord()
{
    if (chineseTxt == null) 
    {
        TextAsset txt = Resources.Load("config/chinese") as TextAsset;
        chineseTxt = txt.ToString();
    }

    baseFont.RequestCharactersInTexture(chineseTxt);
    Texture texture = baseFont.material.mainTexture; // Font的内部纹理
    Debug.Log(string.Format("texture:{0} {1}", texture.width, texture.height)); // 纹理大小
}


그 중 baseFont는 NGUI나 Daikon Forge의 텍스트 렌더링 컨트롤에 사용되는 UnityEngine.Font입니다.baseFont를 초기화할 때 FixBrokenWord 함수를 호출합니다(한 번만 호출하면 됨). 일반적으로 사용되는 한자 목록이 포함된 텍스트를 읽은 다음(인터넷에서 일반적으로 사용되는 한자 목록에서 복사하기만 하면 됨) 이 텍스트의 정보를 요청하면 내부 텍스처가 자동으로 확장됩니다.

 

[출처] https://blog.csdn.net/e295166319/article/details/54861275

 

Unity动态字体文字破碎的解决方法(Dynamic Font Broken)_起个名字真的好难啊的博客-CSDN博客

 使用Unity的动态字体绘制文字的时候,打开两个ui界面的时候,后面的文字会显示破碎(完全乱掉)。我使用的ui插件是Daikon Forge,由于其label的更新机制问题,最终表现的结果可能比一个文本显

blog.csdn.net

 

반응형
Posted by blueasa
, |

게임도중 핸드폰에서 Home 키를 눌러 배경화면으로 이동 후 Server와 끊기기를 기다리고 다시 Server와 리커넥팅 되도록 해서 팝업 떴는데.. Font가 깨졌다. 뭐지..

 

....

 

UILabel 에서 DynamicFont 가 이상한 것 같다는 사수님의 말을 듣고 구글링하고 임시 해결방안으로 Font 스크립트에 접근해 미리(반강제?) 쓸 텍스트스트링을 넣어줌으로 해결을 하였다!! 코드는 대충 이렇다! 

 

Font fc_Font_KR = GameObjectUtil.FindChildComponentByName<UILabel>(MainUIManager.Instance.uiMsgBox.transform, "Txt.Desc").trueTypeFont;//(MainUIManager.Instance.uiMsgBox.transform, "Txt.Desc");

fc_Font_KR.RequestCharactersInTexture(Utility.GetStringFromTBL(250091), 16, FontStyle.Normal);

 

주요 함수는 Font.RequestCharactersInTexture(string str, size, FontStyle); 

 

함수 공부는 개인적으로.. 는..

 

구글링을 하던중 .. 좋은 지식 공유

 

https://www.facebook.com/be2ls/posts/644653395565677

 

밑에는 내용 !

-------------------------------------------------------------------------------------------------------------

 

* 유니티에서 Dynamic Font의 글자 사라짐 문제 대응 방법

유니티에서 지원하는 Dynamic Font는 상당히 편리하다.
기존에 한글 폰트를 화면에 표시하려면,
한글 유니코드에 해당하는 모든 글자를 폰트 텍스쳐에 담아놓고
써야해서, 메모리 낭비가 컸고, 글자 크기도 크게 하기가 힘들었다.

반면 Dynamic Font는 그때 그때 사용하는 글자들만 폰트 텍스쳐에 그려두고 사용하기 때문에
메모리 낭비가 적고, 폰트를 크게 표시할 수 있다는 장점이 있다.

하지만, 유니티 자체의 버그인지 특정 폰의 문제인지 몇몇 폰에서 플레이를 하다보면,
글자들이 깨지거나, 일부 글자가 아예 표시되지 않는 버그가 발견되고 있고,
현재까지 배포된 유니티 버전에서는 아직 해결되지 않은 것으로 보인다.

해결 방법을 구글링 해보았지만, 아직 완벽한 해결책은 없는 것 같아서
직접 여러가지 실험을 해보고 대응 방법을 찾아보았다.

1. Dynamic Font의 텍스쳐 관리 방식

맨 처음 게임이 실행되면 기본 폰트 텍스쳐 크기는 256*256이다.
여기에 글자들이 추가되면서 글자를 추가할 공간이 없을 때
256*256이 256*512, 512*512, 그 다음에는 512*1024 이런식으로 텍스쳐 크기가 증가한다.

폰트 텍스쳐에 새로운 글자가 추가되었는데 더이상 추가할 수 있는 공간이 없을 때, 
폰트 텍스쳐가 재정렬되는데, 이 경우 크기가 변경될 수도 있고, 변하지 않을 때도 있다.
더 이상 글자를 추가할 공간이 없을 때, 사용하지 않는 글자들을 정리하기 때문에
정리를 하고 나서 공간이 남는 경우에는 크기가 그대로 유지 된다.
나름 합리적으로 폰트 텍스쳐를 관리하고 있는 것인데,
문제는 특정 폰에서 이 순간에 글자가 사라지는 것이다.

실험을 해본 결과 문제가 되는 폰에서는 폰트 텍스쳐가 리셋되는 순간 크기의 변화가 있으면
정상적으로 표시가 되는데, 사이즈의 변화가 없으면 일부 글자가 표시되지 않는 문제가 발생하고 있었다.

2. 대응 방법

대응방법은 아름답지는 않지만, 단순한 편이다. 
폰트 텍스쳐가 리셋되는 순간 만약 폰트 텍스쳐의 크기가 변경되지 않았다면,
변경될 때까지 폰트 텍스쳐에 존재하지 않는 글자를 계속 추가해주는 것이다.
코딩은 대략 다음과 같다.

1) 유니티의 Font에는 Font.textureRebuildCallback이라는 콜백함수를 등록할 수 있다.
게임 시작 시점에 콜백 함수에 특정 함수를 지정해두면, 폰트 텍스쳐의 리셋 시점에 해당 함수가 
호출된다. 
ex: this.font.textureRebuildCallback = this.SizeChanged;

2) 시작 시점의 폰트 텍스쳐의 크기를 변수로 저장해둔다.

ex: 
this.fontWidth = this.font.material.mainTexture.width;
this.fontHeight = this.font.material.mainTexture.height;

3) 문제는 폰트 텍스쳐 크기가 변하지 않는 경우이기 때문에, 
콜백함수 안에 폰트 텍스쳐의 크기가 기존 크기와 같은지를 체크한다.

ex: 
if (this.font.material.mainTexture.width == this.fontWidth && this.font.material.mainTexture.height == this.fontHeight)
{
...

4) 기존 사이즈와 똑같으면, 한글을 맨처음부터 한글자씩 집어넣는다.
맨 처음 '가'를 font.GetCharacterInfo를 이용해서, 폰트 텍스쳐에 '가' 글자가 들어있는지 확인해서,
들어있지 않다면 font.RequestCharactersInTexture함수를 이용해서, '가'를 추가해준다.
처음에는 5글자 정도를 추가하고, Invoke함수 등을 이용해서 잠시 기다린다.
만약, 추가한 5글자로 인해서, 크기가 커진다면 다시 콜백함수가 호출될 것이고, 그렇다면 글자들이 제대로 보일 것이므로, 
해당 루틴을 끝낸다.
하지만, 커지지 않았다면, 다시 10글자 정도를 추가하고, 그래도 안되면 15글자로 늘리는 방식이다.
이런 루틴을 반복하다보면 어느 순간 폰트 텍스쳐의 크기가 커진다.
(폰트 사이즈가 너무 작고, 폰트 텍스쳐 크기가 굉장히 커서 모든 한글 글자를 포함할 경우라면 무한루프가 될 수도 있을거 같다.)

한글을 자동으로 하나씩 추가하려면, 
아래와 같은 코드를 이용해서, 초중종성의 값을 증가시켜가면 된다.

ushort mUniCodeKoreanBase = 0xAC00;
int iUniCode = mUniCodeKoreanBase + (curFirst * 21 + curMiddle) * 28 + curEnd;
char temp = System.Convert.ToChar(iUniCode);

3. 결론

문제가 있던 폰에서 테스트해 본 결과, 폰트 텍스쳐의 크기가 리셋되는 순간 잠깐 동안 일부 글자가 안보이다가,
곧바로 글자들이 제대로 복구되었다.
아주 깔끔한 해결책은 아니지만, 이정도면 충분히 쓸만하지 않을까 싶다.

어서 빨리 유니티에서 완벽한 패치가 나오면 좋겠다.

-------------------------------------------------------------------------------------------------------------

 

잉`s 블로그 : 네이버 블로그

I.. N.. G..

blog.naver.com

 

반응형
Posted by blueasa
, |

- ParticleSystem, Spine, TMP 등 Renderer를 가진 오브젝트들을 NGUI 위에 올리고 Depth를 맞추기 위한 소스

  (NGUI Widget의 Depth 제어 부분을 Renderer를 가진 오브젝트에서도 셋팅되도록 함)

- 출처에서는 ParticleSystem용으로 이름을 지어놨는데 어차피 Renderer를 가지고 있는 것들은 다 되는거라 이름 변경함

 

NGUIRendererWidget.cs
0.00MB

 

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[AddComponentMenu("NGUI/UI/NGUI Renderer Widget")]
public class NGUIRendererWidget : UIWidget
{
    protected Renderer m_Renderer;
    protected Material m_Mat;

    public override Material material
    {
        get
        {
            return m_Mat;
        }

        set
        {
            if (m_Mat != value)
            {
                RemoveFromPanel();
                m_Mat = value;
                MarkAsChanged();
            }
        }
    }

    protected override void OnEnable()
    {
        Init();
        base.OnEnable();
    }

    protected void Init()
    {
        if (null == m_Renderer)
        {
            m_Renderer = GetComponent<Renderer>();
        }

        if (null == m_Renderer)
        {
            return;
        }

        if (null == material)
        {
            if (false == Application.isPlaying)
            {
                material = m_Renderer.sharedMaterial;
                m_Renderer.sharedMaterial = material;
            }
            else
            {
                material = m_Renderer.material;
                m_Renderer.material = material;
            }
        }
    }

    private void OnWillRenderObject()
    {
        if (null != drawCall && drawCall.finalRenderQueue != material.renderQueue)
        {
            material.renderQueue = drawCall.finalRenderQueue;
        }

        if (Application.isPlaying == true && m_Renderer.material != material)
        {
            m_Renderer.material = material;
        }
    }

    public override void OnFill(List<Vector3> verts, List<Vector2> uvs, List<Color> cols)
    {
        for (int i = 0; i < 4; i++)
        {
            verts.Add(Vector3.zero);
            uvs.Add(Vector2.zero);
            cols.Add(color);
        }
    }
}

 

[출처] https://tenlie10.tistory.com/169

 

[Unity | 유니티] NGUI와 ParticleSystem간 Depth 조정

ParticleSystem에 해당 스크립트를 추가하고 타 NGUI 컴포넌트처럼 Depth값을 조정하면 된다. UIParticleWidget.cs 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33..

tenlie10.tistory.com

 

반응형
Posted by blueasa
, |

[NGUI 2020.2.2 사용 중..]

 

NGUI에서 UI가 가릴 때 Game 내 일반 오브젝트에 영향을 안주게 막기 위해서

예전에는 UICamea.hoveredObject를 사용했는데, 이번에 사용해보니 값이 이상하다.

그래서 좀 찾아보니 UICamea.IsOverUI가 있다.

참조 링크의 내용에는 문제가 있는 것처럼 말하긴 하는데 빌드해서 봐도 별다른 문제점은 없어보여서 일단 쓰기로 함.

 

[참조] http://www.tasharen.com/forum/index.php?topic=13282.0

 

UICamea.hoveredObject, UICamera.fallThrough, IsOver UI Problem.

When 3D Object and NGUI Object located same position on viewPort, "if(UICamera.hoveredObject != null)" code only touched NGUI Object. This code is no problem NGUI 3.0.2 version, Editor and Mobile too. But, latest version "UICamera.hoveredObject" is pointed

www.tasharen.com

[다른방식] https://blueasa.tistory.com/2549

 

[펌] NGUI와 일반 오브젝트 구분 피킹법

NGUI 를 사용하면서 GUI에 가린 오브젝트들이 GUI와 같이 클릭되는 현상을 게임 제작하면 많이들 보게됩니다. 그럴때는 아래 소스에서 작동하는 녀석으로 쓰면됩니다. if (UICamera.Raycast (Input.mousePosit

blueasa.tistory.com

 

반응형
Posted by blueasa
, |