zoukankan      html  css  js  c++  java
  • 【Unity3D自学记录】利用代码改动图片属性(Inspector)

    这段时间一直都在打包资源,然后每次导入都要改图片的属性。真是麻烦,所以一直在寻找一键改动而且打包的方法。

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

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

    核心部分:

    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();
    
        }
    }
    

    希望大家喜欢。

  • 相关阅读:
    使用Junit对Spring进行单元测试实战小结
    【VBA编程】02.调试VBA程序
    【VBA编程】01.第一个VBA程序Hello world
    VBA验证工作表是否存在
    VBA对指定单元格填充颜色并且赋值
    Excle中range的一些用法
    Debug.print的用法
    EXCLE图形插入实例
    DB2建立不记录日志的表
    Excle快速输入√与×
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5054958.html
Copyright © 2011-2022 走看看