Unity AssetPostprocessor 中 Model 相干函数的理论利用
Unity AssetPostprocessor 是 Unity 引擎中的一个重要性能,它能够在导入资源时主动一些脚本,以便对资源进行自定义解决。其中,Model 相干的函数能够用于对导入的 3D 模型进行解决,包含批改模型的材质、纹理、网格等属性。本文将介绍 Model 相干函数的理论利用,并提供多个应用例子。
ModelImporterMaterialName
ModelImporterMaterialName 函数能够用于批改模型的材质名称。例如,咱们能够将所有模型的材质名称都批改为“DefaultMaterial”。具体实现如下:
using UnityEngine;
using UnityEditor;
public class MyModelPostprocessor : AssetPostprocessor
{void OnPreprocessModel()
{
ModelImporter importer = assetImporter as ModelImporter;
importer.materialName = "DefaultMaterial";
}
}
ModelImporterMaterialSearch
ModelImporterMaterialSearch 函数能够用于批改模型的材质搜寻门路。例如,咱们能够将所有模型的材质搜寻门路都批改为“Assets/Materials”。具体实现如下:
using UnityEngine;
using UnityEditor;
public class MyModelPostprocessor : AssetPostprocessor
{void OnPreprocessModel()
{
ModelImporter importer = assetImporter as ModelImporter;
importer.materialSearch = ModelImporterMaterialSearch.Local;
importer.materialSearchPath = "Assets/Materials";
}
}
ModelImporterMaterialImportMode
ModelImporterMaterialImportMode 函数能够用于批改模型的材质导入模式。例如,咱们能够将所有模型的材质导入模式都批改为“None”。具体实现如下:
using UnityEngine;
using UnityEditor;
public class MyModelPostprocessor : AssetPostprocessor
{void OnPreprocessModel()
{
ModelImporter importer = assetImporter as ModelImporter;
importer.materialImportMode = ModelImporterMaterialImportMode.None;
}
}
ModelImporterMeshCompression
ModelImporterMeshCompression 函数能够用于批改模型的网格压缩形式。例如,咱们能够将所有模型的网格压缩形式都批改为“Off”。具体实现如下:
using UnityEngine;
using UnityEditor;
public class MyModelPostprocessor : AssetPostprocessor
{void OnPreprocessModel()
{
ModelImporter importer = assetImporter as ModelImporter;
importer.meshCompression = ModelImporterMeshCompression.Off;
}
}
ModelImporterNormals
ModelImporterNormals 函数能够用于批改模型的法线计算形式。例如,咱们能够将所有模型的法线计算形式都批改为“Calculate”. 具体实现如下:
using UnityEngine;
using UnityEditor;
public class MyModelPostprocessor : AssetPostprocessor
{void OnPreprocessModel()
{
ModelImporter importer = assetImporter as ModelImporter;
importer.importNormals = ModelImporterNormals.Calculate;
}
}
ModelImporterTangents
ModelImporterTangents 函数能够用于批改模型的切线计算形式。例如,咱们能够将所有模型的切线计算形式都批改为“Calculate”. 具体实现如下:
using UnityEngine;
using UnityEditor;
public class MyModelPostprocessor : AssetPostprocessor
{void OnPreprocessModel()
{
ModelImporter importer = assetImporter as ModelImporter;
importer.importTangents = ModelImporterTangents.Calculate;
}
}
ModelImporterAnimationCompression
ModelImporterAnimationCompression 函数能够用于批改模型的动画压缩形式。例如,咱们能够将所有模型的动画压缩形式都批改为“Off”。具体实现如下:
using UnityEngine;
using UnityEditor;
public class MyModelPostprocessor : AssetPostprocessor
{void OnPreprocess()
{
ModelImporter importer = assetImporter as ModelImporter;
importer.animationCompression = ModelImporterAnimationCompression.Off;
}
}
ModelImporterAnimationType
ModelImporterAnimationType 函数能够用于批改模型的动画类型。例如,咱们能够将所有模型的动画类型都批改为“Legacy”。具体实现如下:
using UnityEngine;
using UnityEditor;
public class MyModelPostprocessor : AssetPostprocessor
{void OnPreprocessModel()
{
ModelImporter importer = assetImporter as ModelImporter;
importer.animationType = ModelImporterAnimationType.Legacy;
}
}
ModelImporterRigImportMode
ModelImporterRigImportMode 函数能够用于批改模型的骨骼导入模式。例如,咱们能够将所有模型的骨骼导入模式都批改为“None”。体实现如下:
using UnityEngine;
using UnityEditor;
public class MyModelPostprocessor : AssetPostprocessor
{void OnPreprocessModel()
{
ModelImporter importer = assetImporter as ModelImporter;
importer.animationType = ModelImporterAnimationType.None;
}
}
论断
本文介绍了 Unity AssetPostprocessor 中 Model 相干函数的理论利用,并提供了多个应用例子。这些函数能够用于对导入的 3D 模型进行自定义解决,包含批改模型的材质、纹理、网格等属性。通过应用这些函数,咱们能够更加灵便地解决导入的 3D 模型,满足不同的需要。