Ejemplo n.º 1
0
        private static void LoadFonts()
        {
            string fontPath = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + ToolMenu.fontPath;
            bool   NoFound  = true;

            if (File.Exists(fontPath))
            {
                FontList fontList = AssetDatabase.LoadAssetAtPath <FontList>(ToolMenu.fontPath);
                if (null != fontList && fontList.list.Count > 0)
                {
                    NoFound = false;
                    m_Fonts = fontList.list;
                }
            }
            if (NoFound)
            {
                m_Fonts = new List <FontItem>()
                {
                    new FontItem()
                    {
                        Name = "Arial",
                        Font = Resources.GetBuiltinResource <Font>("Arial.ttf")
                    }
                };
            }
        }
Ejemplo n.º 2
0
        public static void CreateFontAsset()
        {
            fontPath = "Assets/Art/Fonts/Fonts.asset";
            string fullPath = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + fontPath;

            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }

            Util.MakeDirs(Path.GetDirectoryName(fullPath));

            FontList fontList = new FontList();

            fontList.list.Add(new FontItem()
            {
                Name = "Arial",
                Font = Resources.GetBuiltinResource <Font>("Arial.ttf")
            });

            //遍历目录下字体文件,自动加载
            string[] files = Directory.GetFiles(Path.GetDirectoryName(fullPath));
            foreach (var file in files)
            {
                if (file.EndsWith(".ttf") || file.EndsWith(".ttc"))
                {
                    fontList.list.Add(new FontItem()
                    {
                        Name = Path.GetFileNameWithoutExtension(file),
                        Font = AssetDatabase.LoadAssetAtPath <Font>(file.Substring(file.IndexOf("Assets"), file.Length - file.IndexOf("Assets")))
                    });
                }
            }
            AssetDatabase.CreateAsset(fontList, fontPath);
            AssetDatabase.Refresh();
        }