unity-find-fault
Version:
A tool to find fault in unity project.
57 lines • 2.23 kB
JavaScript
import fg from "fast-glob";
import fs from "fs-extra";
import path from "path";
import { PrefabParser } from "../unity/PrefabParser.js";
import { toolchain } from "../toolchain.js";
export class AlphaImageFinder {
async lookUp() {
const uiRoot = path.join(toolchain.opts.projectRoot, 'Assets/AssetSources/ui');
const prefabs = await fg('**/*.prefab', { cwd: uiRoot });
let out = '';
for (const p of prefabs) {
const file = path.join(uiRoot, p);
const pp = new PrefabParser();
const prefab = await pp.parse(file);
const usages = [];
for (const e of prefab) {
// console.log('check top element:', e.type, e.fileID);
this.findaAlphaImageInternal(e, '', usages);
}
if (usages.length > 0) {
console.log(file);
console.log('---------------');
out += file + '\n';
for (const u of usages) {
console.log(u);
out += u + '\n';
}
console.log('');
out += '';
}
}
await fs.writeFile(toolchain.opts.output.replace('$', 'alpha0'), out, 'utf-8');
}
findaAlphaImageInternal(element, path, usages) {
if (element.type == 'GameObject') {
path += '.' + element.object.m_Name;
const image = element.components['MonoBehaviour_' + "fe87c0e1cc204ed48ad3b37840f39efc" /* EGUID.Image */];
if (image != null) {
if (image.object.m_Color.a == 0) {
usages.push(path);
}
}
const rawImage = element.components['MonoBehaviour_' + "1344c3c82d62a2a41a3576d8abb8e3ea" /* EGUID.RawImage */];
if (rawImage != null) {
if (rawImage.object.m_Color.a == 0) {
usages.push(path);
}
}
if (element.children != null) {
for (const c of element.children) {
this.findaAlphaImageInternal(c, path, usages);
}
}
}
}
}
//# sourceMappingURL=AlphaImageFinder.js.map