</pre>AssetPostprocessor 简介</h3><div>AssetPostProcessor是一个编辑器类,一个资源导入的一个管理器,在资源导入之前和之后可以根据导入的资源做一些设置和一些数据的修改,比如网格,纹理的压缩,模型添加组件等。</div><h2>简单使用</h2><div>当资源导入之前和之后都会发送通知,可以根据不同的资源类型,在导入之前和之后做不同的处理</div><div><h3><pre name="code" class="csharp">using UnityEngine;
using System.Collections;
using UnityEditor;
public class MyEditor : AssetPostprocessor {
//模型导入之前调用
public void OnPreprocessModel()
{
Debug.Log ("OnPreprocessModel="+this.assetPath);
}
//模型导入之前调用
public void OnPostprocessModel(GameObject go)
{
Debug.Log ("OnPostprocessModel="+go.name);
}
//纹理导入之前调用,针对入到的纹理进行设置
public void OnPreprocessTexture()
{
Debug.Log ("OnPreProcessTexture="+this.assetPath);
TextureImporter impor = this.assetImporter as TextureImporter;
impor.textureFormat = TextureImporterFormat.ARGB32;
impor.maxTextureSize = 512;
impor.textureType = TextureImporterType.Advanced;
impor.mipmapEnabled = false;
}
public void OnPostprocessTexture(Texture2D tex)
{
Debug.Log ("OnPostProcessTexture="+this.assetPath);
}
public void OnPostprocessAudio(AudioClip clip)
{
}
public void OnPreprocessAudio()
{
AudioImporter audio = this.assetImporter as AudioImporter;
audio.format = AudioImporterFormat.Compressed;
}
//所有的资源的导入,删除,移动,都会调用此方法,注意,这个方法是static的
public static void OnPostprocessAllAssets(string[]importedAsset,string[] deletedAssets,string[] movedAssets,string[]movedFromAssetPaths)
{
Debug.Log ("OnPostprocessAllAssets");
foreach (string str in importedAsset) {
Debug.Log("importedAsset = "+str);
}
foreach (string str in deletedAssets) {
Debug.Log("deletedAssets = "+str);
}
foreach (string str in movedAssets) {
Debug.Log("movedAssets = "+str);
}
foreach (string str in movedFromAssetPaths) {
Debug.Log("movedFromAssetPaths = "+str);
}
}
}
</pre>AssetPostprocessor 简介</h3><div>AssetPostProcessor是一个编辑器类,一个资源导入的一个管理器,在资源导入之前和之后可以根据导入的资源做一些设置和一些数据的修改,比如网格,纹理的压缩,模型添加组件等。</div><h2>简单使用</h2><div>当资源导入之前和之后都会发送通知,可以根据不同的资源类型,在导入之前和之后做不同的处理</div><div><h3><pre name="code" class="csharp">using UnityEngine;
using System.Collections;
using UnityEditor;
public class MyEditor : AssetPostprocessor {
//模型导入之前调用
public void OnPreprocessModel()
{
Debug.Log ("OnPreprocessModel="+this.assetPath);
}
//模型导入之前调用
public void OnPostprocessModel(GameObject go)
{
Debug.Log ("OnPostprocessModel="+go.name);
}
//纹理导入之前调用,针对入到的纹理进行设置
public void OnPreprocessTexture()
{
Debug.Log ("OnPreProcessTexture="+this.assetPath);
TextureImporter impor = this.assetImporter as TextureImporter;
impor.textureFormat = TextureImporterFormat.ARGB32;
impor.maxTextureSize = 512;
impor.textureType = TextureImporterType.Advanced;
impor.mipmapEnabled = false;
}
public void OnPostprocessTexture(Texture2D tex)
{
Debug.Log ("OnPostProcessTexture="+this.assetPath);
}
public void OnPostprocessAudio(AudioClip clip)
{
}
public void OnPreprocessAudio()
{
AudioImporter audio = this.assetImporter as AudioImporter;
audio.format = AudioImporterFormat.Compressed;
}
//所有的资源的导入,删除,移动,都会调用此方法,注意,这个方法是static的
public static void OnPostprocessAllAssets(string[]importedAsset,string[] deletedAssets,string[] movedAssets,string[]movedFromAssetPaths)
{
Debug.Log ("OnPostprocessAllAssets");
foreach (string str in importedAsset) {
Debug.Log("importedAsset = "+str);
}
foreach (string str in deletedAssets) {
Debug.Log("deletedAssets = "+str);
}
foreach (string str in movedAssets) {
Debug.Log("movedAssets = "+str);
}
foreach (string str in movedFromAssetPaths) {
Debug.Log("movedFromAssetPaths = "+str);
}
}
}