批量改 cocos 系统字体为指定字体
语言 python3
要准备好自己的字体的 uuid
import json import os # 读取一个json文件,并且转为json对象 def file_to_json(file_name): file = open(file_name) s = file.read() file.close() return json.loads(s) # 保存字符串到文件 def save_to_file(file_name, contents): fh = open(file_name, 'w') fh.write(contents) fh.close() # 处理一个文件 def display(frb_path): # frb_path = "/Users/wangankang/git_kingEra/KingEra/assets/resources/Prefab/UI/Union/Union.prefab"; frb = file_to_json(frb_path) f = False for i in range(0, len(frb)): x = frb[i] if x['__type__'] != "cc.Label": continue if x['_isSystemFontUsed'] == False: continue x['_isSystemFontUsed'] = False; x['_N$file'] = { "__uuid__": uuid } f = True # py字典[对象] 转json字符串 indent=2[美化] ensure_ascii[中文] out = json.dumps(frb, indent=2, ensure_ascii=False) save_to_file(frb_path, out) return f def file_name(file_dir): file_list = [] for root, dirs, files in os.walk(file_dir): for name in files: # print(os.path.join(root, name)) if name.endswith(".prefab"): file_list.append(os.path.join(root, name)) if name.endswith(".fire"): file_list.append(os.path.join(root, name)) return file_list dir_path = r'/Users/wangankang/git_kingEra/KingEra/assets' uuid = "b87d4b6a-5278-4c71-aff5-fc6e91a99db9" all_file = file_name(dir_path) d = 0 c = 0 for path in all_file: flag = display(path) print(".", end="") c = c + 1 if c > 20: c = 0 print("", end="\n") if flag: d = d + 1 print() print("总共:", len(all_file), "个文件") print("总共处理:", d, "个文件")
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于