ModelTranslator: document Unity template version, harden guid_for against unreadable meta
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
"""Unity 资产(.meta / .mat)文本模板与 GUID 管理。纯 stdlib,可独立测试。"""
|
||||
"""Unity 资产(.meta / .mat)文本模板与 GUID 管理。纯 stdlib,可独立测试。
|
||||
|
||||
模板采自 Unity 2022.3(TextureImporter serializedVersion 12 / Material 8 /
|
||||
ModelImporter 22200);升级 Unity 后如导入异常,在编辑器导出同类资产 diff 更新模板。"""
|
||||
import os
|
||||
import re
|
||||
import uuid
|
||||
@@ -16,8 +19,11 @@ def guid_for(asset_path):
|
||||
"""资产已有 .meta 则复用其中 guid(重复转换不破坏 Unity 引用),否则新分配。"""
|
||||
meta = asset_path + ".meta"
|
||||
if os.path.isfile(meta):
|
||||
with open(meta, "r", encoding="utf-8") as f:
|
||||
try:
|
||||
with open(meta, "r", encoding="utf-8", errors="replace") as f:
|
||||
m = _GUID_RE.search(f.read())
|
||||
except OSError:
|
||||
m = None # meta 损坏/不可读时按无 meta 处理,重新分配
|
||||
if m:
|
||||
return m.group(1)
|
||||
return new_guid()
|
||||
|
||||
Reference in New Issue
Block a user