unity-find-fault
Version:
A tool to find fault in unity project.
29 lines (28 loc) • 1.03 kB
JavaScript
import fg from "fast-glob";
import path from "path";
import { UnityHelper } from "./UnityHelper.js";
import { strArrayToMap } from "./vendor.js";
export class ImageStriper {
async removeUseless(option) {
// 收集用到的guid
//#region
const usedGUIDs = await UnityHelper.collectUsedGUID(option.projectRoot, ['.mat']);
const usedGUIDMap = strArrayToMap(usedGUIDs);
//#endregion
let cnt = 0;
const animRoot = path.join(option.projectRoot, 'Assets');
const anims = await fg('**/*.mat', { cwd: animRoot });
for (const anim of anims) {
const file = path.join(animRoot, anim);
const guid = await UnityHelper.readGUID(file + '.meta');
if (!usedGUIDMap[guid]) {
// 未被直接引用
// await fs.unlink(file);
// await fs.unlink(file + '.meta');
console.log(file);
cnt++;
}
}
console.log(`${cnt} removed`);
}
}