</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);
}
}
}
Unity3d_AssetPostprocessor簡單用法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.