void Init() { if (m_atlas == null && m_fontAsset != null) { m_fontName = m_fontAsset.name; var fontFile = Path.Combine(Application.persistentDataPath, Path.Combine("Font", m_fontAsset.name)); var fileInfo = new FileInfo(fontFile); if (!fileInfo.Exists || fileInfo.Length != m_fontAsset.bytes.Length) { Directory.CreateDirectory(fileInfo.DirectoryName); File.WriteAllBytes(fontFile, m_fontAsset.bytes); } Resources.UnloadAsset(m_fontAsset); m_atlas = new FreeTypeFontAtlas(fontFile); #if !UNITY_EDITOR m_fontAsset = null; #endif m_atlas.textureEnglarged += OnTextureEnlarged; m_atlas.textureUpdated += OnTextureUpdated; m_atlas.textureEnglarged += OnTextureEnlarged; m_atlas.textureUpdated += OnTextureUpdated; if (m_material == null) { m_material = new Material(Shader.Find("Unlit/FreeType Text")); m_material.hideFlags = HideFlags.DontSave | HideFlags.NotEditable; } m_material.mainTexture = m_atlas.Texture; m_updateScheduled = false; } }
void OnValidate() { if (m_atlas != null) { m_atlas.Dispose(); m_atlas = null; } Init(); }