【Unity3D自學記錄】利用代碼修改圖片屬性(Inspector),unity3dinspector
這段時間一直都在打包資源,然後每次匯入都要改圖片的屬性,真是麻煩,所以一直在尋找一鍵修改並且打包的方法。
終於讓我找到了,太坑人了。
根據自己的需求改代碼哦,相信大家都能看明白。
核心部分:
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裡面 ,點擊一下按鈕然後自動更改人物屬性資料,比如說攻擊力增加等等的代碼怎編寫?
首先定義屬性,然後擷取屬性,然後在按鈕的點擊事件裡賦值
unity3d裡面怎讓自訂的類變數顯示在inspector中
添加 [System.Serializable] 的類就可以顯示了,如果是js的話就不用加。:)