コード例 #1
0
ファイル: BitmapFontCreaterMenu.cs プロジェクト: midfer/Zero
        /// <summary>
        /// 直接
        /// </summary>
        //[MenuItem("Assets/Zero/Create Bitmap Font (GUI)", false, 1)]
        public static void CreateBitmapFontGUI()
        {
            var editorWin = BitmapFontCreateEditorWindow.Open();

            if (Selection.objects.Length > 1 || Selection.objects[0] is Texture2D)
            {
                foreach (var obj in Selection.objects)
                {
                    if (obj is Texture2D)
                    {
                        editorWin.textures.Add(obj as Texture2D);
                    }
                }
            }
            else if (Selection.objects.Length == 1)
            {
                var obj  = Selection.objects[0];
                var path = AssetDatabase.GetAssetPath(obj);
                if (Directory.Exists(path))
                {
                    editorWin.outputPath = path;
                    editorWin.fontName   = obj.name;
                    //找到所有的图片
                    var         files = Directory.GetFiles(path, "*.png", SearchOption.TopDirectoryOnly);
                    List <char> chars = new List <char>();
                    for (var i = 0; i < files.Length; i++)
                    {
                        var nameChars = Path.GetFileNameWithoutExtension(files[i]).ToCharArray();
                        if (nameChars.Length == 1)
                        {
                            chars.Add(nameChars[0]);
                        }
                        editorWin.textures.Add(AssetDatabase.LoadAssetAtPath <Texture2D>(files[i]));
                    }


                    var charsTxtFile = Path.Combine(path, "chars.txt");
                    if (File.Exists(charsTxtFile))
                    {
                        //如果目录中有「chars.txt」文件,则提取字符填入
                        string charsContent = File.ReadAllText(charsTxtFile);
                        editorWin.charContent = charsContent;
                    }
                    else
                    {
                        editorWin.charContent = new string(chars.ToArray());
                    }
                }
            }
        }
コード例 #2
0
ファイル: BitmapFontCreaterMenu.cs プロジェクト: midfer/Zero
 //[MenuItem("Tools/Zero/Create Bitmap Font", false, 1)]
 public static void CreateBitmapFontGUITools()
 {
     BitmapFontCreateEditorWindow.Open();
 }