118 lines
5.0 KiB
Python
118 lines
5.0 KiB
Python
"""에셋 스토어 .unitypackage 에서 지정한 프리팹과 그 의존 파일만 골라 이 게임으로 옮기기(GUID 유지 · .meta 째 · 원본 무수정).
|
|
|
|
PD 2026-11-11: 「"Simple Stylized Slash Pack 2" 에셋의 slash_aoe_a 이펙트로 교체」 — WL 프로젝트 사본은 Tools/wl_vfx_import.py 판정에서
|
|
탈락(쓰지 않는 꼬리 재질 칸이 URP 기본 재질 ParticlesUnlit 을 가리킴)이라, 내려받은 원본 패키지에서 그 프리팹이 실제로 쓰는 파일만 푼다.
|
|
의존 = 프리팹·재질(YAML)의 guid 참조 + 셰이더 그래프(JSON)의 guid 참조(하위 그래프·그림) + .meta 의 외부 참조 · 패키지에 없는 guid(URP 기본 재질 등)는 건너뜀.
|
|
경로 = 패키지의 Assets/<rel> → 이 게임 <dest>/<rel>(기본 Assets/VFX) · 같은 GUID 가 이미 있으면 건너뜀.
|
|
|
|
실행: python -I -B -X utf8 Tools/unitypackage_pick.py <패키지.unitypackage> <패키지 안 프리팹 경로(Assets/…)> [...] [--dest Assets/VFX] [--dry]
|
|
"""
|
|
import argparse
|
|
import os
|
|
import re
|
|
import sys
|
|
import tarfile
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
ROOT = os.path.dirname(HERE)
|
|
HEX32 = re.compile(r"(?<![0-9a-f])([0-9a-f]{32})(?![0-9a-f])")
|
|
TEXT_EXT = {".prefab", ".mat", ".asset", ".shadergraph", ".shadersubgraph", ".controller", ".anim", ".shader", ".cginc", ".hlsl"}
|
|
SKIP_EXT = {".cs", ".unity"}
|
|
|
|
|
|
def existing_guids():
|
|
out = set()
|
|
for base, _, files in os.walk(os.path.join(ROOT, "Assets")):
|
|
for f in files:
|
|
if not f.endswith(".meta"):
|
|
continue
|
|
try:
|
|
with open(os.path.join(base, f), encoding="utf-8", errors="replace") as fh:
|
|
for line in fh:
|
|
if line.startswith("guid:"):
|
|
out.add(line.split(":", 1)[1].strip())
|
|
break
|
|
except OSError:
|
|
pass
|
|
return out
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("package")
|
|
ap.add_argument("targets", nargs="+")
|
|
ap.add_argument("--dest", default="Assets/VFX")
|
|
ap.add_argument("--dry", action="store_true")
|
|
a = ap.parse_args()
|
|
|
|
with tarfile.open(a.package, "r:gz") as t:
|
|
entries = {}
|
|
for m in t.getmembers():
|
|
if m.isfile():
|
|
g, _, kind = m.name.partition("/")
|
|
entries.setdefault(g, {})[kind] = m
|
|
path_of = {}
|
|
for g, e in entries.items():
|
|
if "pathname" in e:
|
|
path_of[g] = t.extractfile(e["pathname"]).read().decode("utf-8").splitlines()[0].strip()
|
|
guid_of = {p: g for g, p in path_of.items()}
|
|
|
|
def read(g, kind):
|
|
return t.extractfile(entries[g][kind]).read() if kind in entries[g] else b""
|
|
|
|
todo = []
|
|
for target in a.targets:
|
|
if target not in guid_of:
|
|
print("패키지에 없음:", target)
|
|
sys.exit(1)
|
|
todo.append(guid_of[target])
|
|
seen, missing = set(), set()
|
|
while todo:
|
|
g = todo.pop()
|
|
if g in seen:
|
|
continue
|
|
seen.add(g)
|
|
ext = os.path.splitext(path_of[g])[1].lower()
|
|
blobs = [read(g, "asset.meta")]
|
|
if ext in TEXT_EXT:
|
|
blobs.append(read(g, "asset"))
|
|
for b in blobs:
|
|
for ref in HEX32.findall(b.decode("utf-8", errors="replace")):
|
|
if ref == g or ref in seen:
|
|
continue
|
|
if ref in path_of:
|
|
if os.path.splitext(path_of[ref])[1].lower() not in SKIP_EXT and "asset" in entries[ref]:
|
|
todo.append(ref)
|
|
elif not ref.startswith("0000000000000000") and ext not in (".shadergraph", ".shadersubgraph"):
|
|
missing.add(ref) # 그래프 파일 안의 32자리 값은 대부분 노드 id 라 세지 않음
|
|
|
|
have = existing_guids()
|
|
done = skip = 0
|
|
size = 0
|
|
for g in sorted(seen, key=lambda x: path_of[x]):
|
|
p = path_of[g]
|
|
if not p.startswith("Assets/") or ".." in p.split("/") or "asset" not in entries[g]:
|
|
continue
|
|
if g in have:
|
|
skip += 1
|
|
continue
|
|
dst = os.path.normpath(os.path.join(ROOT, a.dest, p[len("Assets/"):]))
|
|
data = read(g, "asset")
|
|
size += len(data)
|
|
print((" (dry) " if a.dry else " ") + os.path.relpath(dst, ROOT).replace("\\", "/"))
|
|
if a.dry:
|
|
continue
|
|
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
|
with open(dst, "wb") as fh:
|
|
fh.write(data)
|
|
meta = read(g, "asset.meta")
|
|
if meta:
|
|
with open(dst + ".meta", "wb") as fh:
|
|
fh.write(meta)
|
|
done += 1
|
|
print("옮김 %d · 이미 있음 %d · %.1f MB · 패키지에 없는 참조 %d(건너뜀: %s)" % (done, skip, size / 1e6, len(missing), ", ".join(sorted(missing))[:200]))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|