您的位置:首页 > 移动开发 > Unity3D

【Unity3D自学记录】利用代码修改图片属性(Inspector)

2014-10-24 11:19 435 查看
这段时间一直都在打包资源,然后每次导入都要改图片的属性,真是麻烦,所以一直在寻找一键修改并且打包的方法。

终于让我找到了,太坑人了。

根据自己的需求改代码哦,相信大家都能看明白。

核心部分:

TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(obj));
ti.textureType = TextureImporterType.GUI;
ti.filterMode = FilterMode.Point;
ti.textureFormat = TextureImporterFormat.RGBA32;

全部代码如下:

using UnityEngine;
using System.Collections;
using UnityEditor;

public class AssetBundleTest : Editor
{

[MenuItem("Creat/CreateAssetBunldes")]
public static void CreateAssetBunldes()
{
Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);

foreach (Object obj in SelectedAsset)
{
TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(obj));
ti.textureType = TextureImporterType.GUI;
ti.filterMode = FilterMode.Point;
ti.textureFormat = TextureImporterFormat.RGBA32;

string targetPath = Application.dataPath + "/Asset/" + obj.name + ".assetbundle";
if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies))
{
Debug.Log(obj.name + "资源打包成功");
}
else
{
Debug.Log(obj.name + "资源打包失败");
}
}

AssetDatabase.Refresh();

}
}

希望大家喜欢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity3d