1.8 KiB
1.8 KiB
#unity/日常积累
unity进游戏的时候,有时候可能会遇到这些报错,但逻辑上并没有报错
这时候,很可能就是Library库出现了问题 一般定位到,是哪个资源出现问题,重新导入一遍资源就好,用reimport
reimport的代码简单使用,例如只重新导入所有模型:
[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资源:
/// <summary>
/// 完全重新导入全部 Assets
/// </summary>
/// <param name="buildSettings"></param>
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");
}