#unity/日常积累 unity进游戏的时候,有时候可能会遇到这些报错,但逻辑上并没有报错 ![[Pasted image 20230302111745.png]] 这时候,很可能就是Library库出现了问题 一般定位到,是哪个资源出现问题,重新导入一遍资源就好,用reimport reimport的代码简单使用,例如只重新导入所有模型: ``` cs [MenuItem("Tools/Reimport All Models")] public static void ReimportAllModel() { string[] assetPaths = AssetDatabase.GetAllAssetPaths(); foreach (string assetPath in assetPaths) { string normalizedAssetPath = assetPath.ToLower(); if (!normalizedAssetPath.EndsWith(".fbx") && !normalizedAssetPath.EndsWith(".obj") && !normalizedAssetPath.EndsWith(".3ds") && !normalizedAssetPath.EndsWith(".asset")) { continue; } AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ImportRecursive | ImportAssetOptions.ForceUpdate); } } ``` 例如,重新导入所有Asset资源: ``` cs /// /// 完全重新导入全部 Assets /// /// private static void StepReimportAllAssets(BuildSettings buildSettings) { if (GLog.IsLogInfoEnabled) GLog.LogInfo("[BuildToolV2.StepReimportAllAssets] Start"); if (buildSettings.ReimportAllAssets) { AssetDatabase.ImportAsset("Assets", ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive | ImportAssetOptions.DontDownloadFromCacheServer); } if (GLog.IsLogInfoEnabled) GLog.LogInfo("[BuildToolV2.StepReimportAllAssets] OK"); } ```