unity-find-fault
Version:
A tool to find fault in unity project.
38 lines • 1.4 kB
JavaScript
import fg from "fast-glob";
import fs from "fs-extra";
import path from "path";
import { UnityHelper } from "./UnityHelper.js";
import { strArrayToMap } from "./vendor.js";
import { toolchain } from "../toolchain.js";
export class AnimStriper {
async removeUseless() {
// 先删除*.controller
console.log('checking *.controller ...');
await this.removeSpecified('.controller');
// 再删除*.anim
console.log('checking *.anim ...');
await this.removeSpecified('.anim');
}
async removeSpecified(ext) {
// 收集用到的guid
//#region
const usedGUIDs = await UnityHelper.collectUsedGUID(toolchain.opts.projectRoot, [ext]);
const usedGUIDMap = strArrayToMap(usedGUIDs);
//#endregion
let cnt = 0;
const animRoot = path.join(toolchain.opts.projectRoot, 'Assets');
const anims = await fg(`**/*${ext}`, { 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');
cnt++;
}
}
console.log(`${cnt} anim removed`);
}
}
//# sourceMappingURL=AnimStriper.js.map