【Unity3D自學記錄】利用代碼修改圖片屬性(Inspector),unity3dinspector

來源:互聯網
上載者:User

【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的話就不用加。:)
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.