</pre><pre name="code" class="csharp">
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
using System.Collections.Generic;
/// <summary>
/// 功能:引擎内图片高级选项批量修改
/// 平台:Unity4.6.4/C#
/// 设计模式:命令模式(15)
/// FileName:TextureManager
/// Creator: Thewen
/// CreateTime:2016/4/20 15:26:45
/// Description:
/// History:
/// </summary>
///<summary>
///命令基类 为子类提供处理具体逻辑的逻辑类
///</summary>
public abstract class Command
{
protected Receiver _receiver;
public Command(Receiver receiver)
{
this._receiver = receiver;
}
public abstract void ExecuteAction();
}
/// <summary>
/// 命令模式关键类 (处理逻辑主体)
/// </summary>
public class Receiver
{
TextureImporterSettings _importsettings=new TextureImporterSettings();
bool _iscompress;
string _texturetype;
string _path;
TextureImporterFormat _iosformat;
TextureImporterFormat _androidformat;
//默认
public Receiver(string texturetype, string path)
{
this._texturetype = texturetype;
this._path = path;
this._importsettings.npotScale = TextureImporterNPOTScale.ToNearest;
this._importsettings.ApplyTextureType(TextureImporterType.Advanced, false);
this._importsettings.readable = false;
this._importsettings.mipmapEnabled = true;
this._importsettings.lightmap = false;
this._iscompress = true;
}
public Receiver(string texturetype, string path,bool iscompress,bool mipmapenabled ,bool lightmap)
{
this._texturetype = texturetype;
this._path = path;
this._importsettings.npotScale = TextureImporterNPOTScale.ToNearest;
this._importsettings.ApplyTextureType(TextureImporterType.Advanced, false);
this._importsettings.readable = false;
this._importsettings.mipmapEnabled = mipmapenabled;
this._importsettings.lightmap = lightmap;
this._iscompress = iscompress;
}
/// <summary>
/// 设置图片的高级属性
/// </summary>
public void SetTextureAnvanceSetting( )
{
ArrayList filePath = TextureManager.GetAssetPath(_texturetype, _path);
for (int i = 0; i < filePath.Count; i++)
{
TextureManager.SetAdvanceForPath(filePath[i].ToString(),_iscompress,_importsettings,_iosformat,_androidformat);
}
}
}
/// <summary>
/// 命令执行类 (便于命令的集中管理,为实现撤销于恢复提供可能)
/// </summary>
public class Invoker
{
public Command _command;
public List<Command> _commandlist;
public Invoker(Command command)
{
this._command = command;
}
public Invoker(List<Command> commandlist)
{
this._commandlist = commandlist;
}
public void ExecuteCommandList()
{
for (int i = 0; i < _commandlist.Count; i