/// <summary>
/// 把纹理放到编辑器中去
/// </summary>
/// <param name="ps"></param>
private static Texture2D AssembleTexture(ParticleSystem ps, Dictionary <int, object> resource)
{
Texture2D tex2D = null;
Texture3D tex = resource[ps.TexId] as Texture3D;
if (tex.IsATF)
{
}
else
{
//实例化一个Texture2D,宽和高设置可以是任意的,因为当使用LoadImage方法会对Texture2D的宽和高会做相应的调整
//Texture2D tex2D = new Texture2D(1,1);
//tex2D.LoadImage(tex.Data);
var fileName = string.Empty;
//if (!File.Exists(SceneFileCopy.GetAbsoluteTextureDir() + tex.Name))
{
fileName = tex.Name;
ps.UnityResourceParam.Texture2DPath = SceneFileCopy.GetRelativeTextureDir(ps.RootFileName) + fileName;
}
//else
//{
// fileName = tex.Name.Substring(0, UnityEngine.Mathf.Max(0, tex.Name.Length - 4)) + "_" + Guid.NewGuid().ToString() + tex.Name.Substring(tex.Name.Length - 4, 4);
// ps.UnityResourceParam.Texture2DPath = SceneFileCopy.GetRelativeTextureDir() + fileName;
//}
ps.UnityResourceParam.Texture2DPath = SceneFileCopy.GetRelativeTextureDir(ps.RootFileName) + fileName;
SaveFile(SceneFileCopy.GetAbsoluteTextureDir(ps.RootFileName) + fileName, tex.Data);
tex2D = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.Texture2DPath, typeof(Texture2D)) as Texture2D;
UnityEditor.TextureImporter textureImporter = UnityEditor.AssetImporter.GetAtPath(ps.UnityResourceParam.Texture2DPath) as UnityEditor.TextureImporter;
UnityEditor.TextureImporterSettings settings = new UnityEditor.TextureImporterSettings();
textureImporter.ReadTextureSettings(settings);
settings.ApplyTextureType(UnityEditor.TextureImporterType.Default);
textureImporter.SetTextureSettings(settings);
textureImporter.textureType = UnityEditor.TextureImporterType.Default;
//使用透明度
textureImporter.alphaIsTransparency = true;
textureImporter.isReadable = true;
textureImporter.filterMode = (UnityEngine.FilterMode)tex.FilterMode;
textureImporter.wrapMode = (UnityEngine.TextureWrapMode)tex.WrapMode;
textureImporter.mipmapEnabled = tex.MipMode > 0;
UnityEditor.AssetDatabase.ImportAsset(ps.UnityResourceParam.Texture2DPath);
}
UnityEditor.AssetDatabase.Refresh();
return(tex2D);
}