Unity實現列舉型別中文顯示

2022-09-26 01:24:13 字數 1369 閱讀 3841

unity指令碼中列舉型別在inspector面板中文顯示,供大家參考,具體內容如下

效果:工具指令碼:chineseenumtool.cs

using system;

using unityengine;

#if unity_editor

using unityeditor;

using system.reflection;

using system.text.regularexpressions;

#endif

///

/// 設定列舉名稱

///

#if unity_editor

[attributeusage(attributetargets.field)]

#endif

public class enumattirbute : propertyattribute

}#if unity_editor

[custompropertydrawer(typeof(enumattirbute))]

public class enumnamedrawer : propertydrawer

if (property程式設計客棧.propertytype == serializedpropertytype.enum)

else }

///

/// 重新繪製列舉型別屬性

///

///

///

///

private void drawenum(rect position, serializedproperty property, guicontent label)

for (int i = 0; i < names.length; ++i)

int index = editorgui.popup(position, label.text, property.enumvalueindex, values);

if (editorgui.endchangecheck() && index != -1) }

}#endif

public class chineseenumtool : monobeh**iour

新建text指令碼測試

using system.collections;

using system.collections.generic;

using unityengine;

//定義動物類

public enum animal

public class test : monobeh**iour

void update ()

}本文標題: unity實現列舉型別中文顯示

本文位址:

enum中使用中文 unity 列舉顯示中文問題

示例 有人為了顯示中文,這樣定義列舉嗎?publicenumtimeofday 上午,下午,晚上這樣定義,很彆扭,特別是在使用的時候,比如,this.time timeofday.上午 而且你會逐漸發現它的侷限性。列舉定義很頭疼 在系統開發中,我們經常使用列舉,但是定義列舉是個頭疼的問題。按照習慣我...

Spring boot 列舉 顯示中文

getter public enum gender enumvalue對應資料庫的字段,即在資料庫中存int 定義兩個屬性 code對應資料庫儲存的字段,value對應的中文值 enumvalue private final int code private final string value 呼...

Unity3d之列舉型別

列舉型別 列舉型別是一種的值型別,它用於宣告一組命名的常數 列舉的宣告 列舉宣告用於宣告新的列舉型別 訪問修辭符 enum 列舉名 基礎型別 列舉成員的預設值 在列舉型別中宣告的第乙個列舉成員它的默值為零,例 例 public enum timeofday uint morning,afternoo...