您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
37 行
1.1 KiB
37 行
1.1 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace UIWidgets.ui
|
|
{
|
|
|
|
public class FontManager
|
|
{
|
|
private List<Font> _fonts = new List<Font>();
|
|
|
|
public static readonly FontManager instance = new FontManager();
|
|
|
|
public Font getOrCreate(string[] names, int fontSize)
|
|
{
|
|
var founded = _fonts.Find((font) =>
|
|
(
|
|
font.fontSize == fontSize &&
|
|
(names == font.fontNames || (names != null && names.SequenceEqual(font.fontNames)))));
|
|
if (founded != null)
|
|
{
|
|
return founded;
|
|
}
|
|
|
|
Debug.Log(string.Format("Create new Font names={0}, size={1}", names, fontSize));
|
|
var newFont = Font.CreateDynamicFontFromOSFont(names,
|
|
fontSize);
|
|
_fonts.Add(newFont);
|
|
return newFont;
|
|
}
|
|
|
|
public Font getOrCreate(string name, int fontSize)
|
|
{
|
|
return getOrCreate(new []{name}, fontSize);
|
|
}
|
|
}
|
|
}
|