using UnityEngine;
using System.Collections;
using UnityEditor;
/// <summary>
/// 在从外部导入texture、或者在导入之后对texture的自动处理
/// </summary>
public class ImportResDemo : AssetPostprocessor {
/// <summary>
/// 在导入纹理之后调用
/// </summary>
/// <param name="texture"></param>
public void OnPostprocessTexture(Texture2D texture)
{
TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
if (textureImporter != null)
{
string AtlasName = new System.IO.DirectoryInfo(System.IO.Path.GetDirectoryName(assetPath)).Name;
Debug.Log("name is: " + AtlasName);
Debug.Log("textureType is: " + textureImporter.textureType);
Debug.Log("maxTextureSize is: " + textureImporter.maxTextureSize);
Debug.Log("textureFormat is: " + textureImporter.textureFormat);
textureImporter.textureType = TextureImporterType.Sprite;
textureImporter.spriteImportMode = SpriteImportMode.Single;
textureImporter.spritePackingTag = AtlasName;
textureImporter.mipmapEnabled = false;
}
}
/// <summary>
/// 在导入纹理之前调用
/// </summary>
public void OnPreprocessTexture()
{
TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
if (textureImporter != null)
{
textureImporter.textureType = TextureImporterType.Advanced;
textureImporter.textureFormat = TextureImporterFormat.ARGB32;
}
}
/// <summary>
/// 移动、删除资源
/// </summary>
/// <param name="importedAssets"></param>
/// <param name="deletedAssets"></param>
/// <param name="movedAssets"></param>
/// <param name="movedFromAssetPaths"></param>
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
//当移动资源的时候 也就是重新导入资源
for (int i = 0; i < movedAssets.Length; i++)
{
Debug.Log("Reimported Asset: " + movedAssets[i]);
}
//删除资源
for (int i = 0; i < deletedAssets.Length;i++ )
{
Debug.Log("Deleted Asset: " + deletedAssets[i]);
}
//移动资源
for (var i=0;i < movedAssets.Length;i++) {
Debug.Log("Moved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]);
}
}
}
Unity之AssetPostprocessor学习一
猜你喜欢
转载自blog.csdn.net/Rose_Girls/article/details/51454032
今日推荐
周排行