# GameManager.ts 清理报告 ## 📊 清理统计 | 指标 | 清理前 | 清理后 | 减少 | |------|--------|--------|------| | 代码行数 | 836行 | 345行 | **-59%** | | console.log | 12个 | 0个 | **-100%** | | console.warn | 保留 | 4个 | 仅保留必要警告 | --- ## ✅ 保留的功能(实际被使用) ### 核心方法 1. ✅ `Awake()` - 初始化 2. ✅ `updateDictionaries()` - 更新材质和网格字典 3. ✅ `applyMaterial()` - 应用材质属性 4. ✅ `toggleRollerDoor()` - 卷帘门开关切换 5. ✅ `setRollerDoorState()` - 设置卷帘门状态 6. ✅ `isRollerDoorOpen()` - 查询卷帘门状态 7. ✅ `setYAxisClip()` - Y轴剖切 8. ✅ `clearYAxisClip()` - 清除剖切 9. ✅ `listMeshNames()` - 调试用 ### 私有辅助方法 - ✅ `cacheRollerDoorMeshes()` - 卷帘门网格缓存 --- ## ❌ 移除的功能(未被使用) ### 1. 纹理管理系统(约400行) ```typescript // 整个 initSetMaterial 方法及相关代码 async initSetMaterial(oldObject: any) { ... } private applyPBRProperties(mat: PBRMaterial, component: any) { ... } private clearTextures(textureDic: Dictionary): Promise { ... } private handleTextureAssignment(...) { ... } private checkTextureLoadedWithPromise(texture: Texture): Promise { ... } // 相关字段 private oldTextureDic: Dictionary; private failedTextures: Array<...>; ``` **原因:** 没有任何地方调用 `initSetMaterial()`,整个纹理加载系统未使用 ### 2. 剖切平面可视化(约50行) ```typescript private clipPlaneVisualization: Mesh | null; // 相关创建/销毁逻辑 ``` **原因:** 可视化功能未启用 ### 3. 卷帘门缩放方法 ```typescript private setRollerDoorScale(meshName: string, scale: Vector3): void { ... } ``` **原因:** 从未被调用,且在 Awake 中被注释掉 ### 4. 重置相机方法 ```typescript reSet() { if (this.mainApp.appCamera?.object?.position) { this.mainApp.appCamera.object.position.set(160, 50, 0); } } ``` **原因:** 从未被调用 --- ## 🔧 代码优化 ### 1. 删除所有调试 console.log ```typescript // ❌ 删除 console.log(options); console.log('box', AppConfig.env.background); console.log(material.name); console.log(`[拖拽吸附] ...`); // ✅ 保留必要的警告 console.warn('Scene not found'); console.warn(`Model not found: ${options.modelId}`); ``` ### 2. 修复 applyMaterial Bug ```typescript // ❌ 删除硬编码(之前覆盖用户参数) material.roughness = 0.8; material.metallic = 0; // ✅ 正确实现 if (options.roughness !== undefined) { if (material.roughness !== options.roughness) { material.roughness = options.roughness; } } ``` ### 3. 优化导入语句 ```typescript // ❌ 删除未使用的导入 import { TransformNode } from "@babylonjs/core"; import { AppConfig } from './AppConfig'; // 未使用 ``` ### 4. 简化字段定义 ```typescript // ❌ 删除 private oldTextureDic: Dictionary; private failedTextures: Array<{...}>; private clipPlaneVisualization: Mesh | null; // ✅ 保留必要字段 private materialDic: Dictionary; private meshDic: Dictionary; private rollerDoorMeshes: AbstractMesh[]; private yClipPlane: Plane | null; ``` --- ## 📝 剩余职责 清理后,GameManager 现在只负责: 1. **材质管理** - 维护材质/网格字典 - 应用材质属性 2. **卷帘门动画** - 开关控制 - 平滑动画 3. **Y轴剖切** - 设置剖切平面 - 清除剖切 4. **调试工具** - 列出网格名称 **职责清晰,单一原则!** --- ## ⚠️ 注意事项 ### 备份文件 - 原文件已备份为 `GameManager.old.ts` - 如需回滚:`mv src/babylonjs/GameManager.old.ts src/babylonjs/GameManager.ts` ### 验证测试 请测试以下功能确保正常工作: - [ ] 材质换色 `kernel.material.apply()` - [ ] 卷帘门动画 `kernel.door.toggle()` - [ ] Y轴剖切 `kernel.clipping.setY()` - [ ] 模型拖拽后材质更新 ### 如果发现遗漏的功能 如果有某个功能实际在用但被移除了,请告诉我: 1. 功能名称 2. 调用位置 3. 我会立即恢复并标记为"保留" --- ## 🎯 下一步建议 1. **删除备份文件**(确认无问题后) ```bash rm src/babylonjs/GameManager.old.ts ``` 2. **删除重复文件** ```bash rm src/babylonjs/AppModel\ copy.ts ``` 3. **清理其他文件的 console.log** - AppModelDrag.ts (28个) - AppDropZone.ts (31个) - 其他文件... 4. **考虑进一步拆分**(可选) - MaterialManager.ts - 材质管理 - RollerDoorController.ts - 卷帘门动画 - ClippingManager.ts - 剖切功能