欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity實(shí)現(xiàn)枚舉類型中文顯示

 更新時(shí)間:2021年02月23日 16:42:06   作者:被代碼折磨的狗子  
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)枚舉類型中文顯示,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Unity腳本中枚舉類型在inspector面板中文顯示,供大家參考,具體內(nèi)容如下

效果:

工具腳本:ChineseEnumTool.cs

using System;
using UnityEngine;

#if UNITY_EDITOR
using UnityEditor;
using System.Reflection;
using System.Text.RegularExpressions;
#endif

/// <summary>
/// 設(shè)置枚舉名稱
/// </summary>
#if UNITY_EDITOR
[AttributeUsage(AttributeTargets.Field)]
#endif
public class EnumAttirbute : PropertyAttribute
{
 /// <summary>
 /// 枚舉名稱
 /// </summary>
 public string name;
 public EnumAttirbute(string name)
 {
 this.name = name;
 }
}

#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(EnumAttirbute))]
public class EnumNameDrawer : PropertyDrawer
{
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
 // 替換屬性名稱
 EnumAttirbute enumAttirbute = (EnumAttirbute)attribute;
 label.text = enumAttirbute.name;

 bool isElement = Regex.IsMatch(property.displayName, "Element \\d+");
 if (isElement)
 {
  label.text = property.displayName;
 }

 if (property.propertyType == SerializedPropertyType.Enum)
 {
  DrawEnum(position, property, label);
 }
 else
 {
  EditorGUI.PropertyField(position, property, label, true);
 }
 }

 /// <summary>
 /// 重新繪制枚舉類型屬性
 /// </summary>
 /// <param name="position"></param>
 /// <param name="property"></param>
 /// <param name="label"></param>
 private void DrawEnum(Rect position, SerializedProperty property, GUIContent label)
 {
 EditorGUI.BeginChangeCheck();
 Type type = fieldInfo.FieldType;

 string[] names = property.enumNames;
 string[] values = new string[names.Length];
 while (type.IsArray)
 {
  type = type.GetElementType();
 }

 for (int i = 0; i < names.Length; ++i)
 {
  FieldInfo info = type.GetField(names[i]);
  EnumAttirbute[] enumAttributes = (EnumAttirbute[])info.GetCustomAttributes(typeof(EnumAttirbute), false);
  values[i] = enumAttributes.Length == 0 ? names[i] : enumAttributes[0].name;
 }

 int index = EditorGUI.Popup(position, label.text, property.enumValueIndex, values);
 if (EditorGUI.EndChangeCheck() && index != -1)
 {
  property.enumValueIndex = index;
 }
 }
}
#endif

public class ChineseEnumTool : MonoBehaviour {
}

新建Text腳本測(cè)試

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//定義動(dòng)物類
public enum Animal
{
 [EnumAttirbute("小狗")]
 dog,
 [EnumAttirbute("小貓")]
 cat,
 [EnumAttirbute("老虎")]
 tiger
}
public class Test : MonoBehaviour {

 [EnumAttirbute("動(dòng)物")]
 public Animal animal;

 void Start () {
 
 }
 
 void Update () {
 
 }
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#客戶端程序調(diào)用外部程序的3種實(shí)現(xiàn)方法

    C#客戶端程序調(diào)用外部程序的3種實(shí)現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于C#客戶端程序調(diào)用外部程序的3種實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • 如何使用C#讀寫鎖ReaderWriterLockSlim

    如何使用C#讀寫鎖ReaderWriterLockSlim

    這篇文章向大家介紹了讀寫鎖ReaderWriterLockSlim,其優(yōu)點(diǎn)就是多個(gè)線程可以同時(shí)讀取該對(duì)象,要了解更多讀寫鎖的知識(shí),仔細(xì)閱讀下文吧
    2015-07-07
  • C#導(dǎo)出文本內(nèi)容到word文檔的方法

    C#導(dǎo)出文本內(nèi)容到word文檔的方法

    這篇文章主要介紹了C#導(dǎo)出文本內(nèi)容到word文檔的方法,涉及C#操作word文檔的相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • C#中SerialPort的使用教程詳解

    C#中SerialPort的使用教程詳解

    SerilPort是串口進(jìn)行數(shù)據(jù)通信的一個(gè)控件,這篇文章主要為大家詳細(xì)介紹了C#中SerialPort的使用,具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-12-12
  • C#中方法的詳細(xì)介紹

    C#中方法的詳細(xì)介紹

    本篇文章介紹了,C#中方法的詳細(xì)說明。需要的朋友參考下
    2013-04-04
  • C#實(shí)現(xiàn)自定義動(dòng)畫鼠標(biāo)的示例詳解

    C#實(shí)現(xiàn)自定義動(dòng)畫鼠標(biāo)的示例詳解

    這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)自定義動(dòng)畫鼠標(biāo)效果,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
    2022-12-12
  • C#使用晚綁定來實(shí)現(xiàn)壓縮Access數(shù)據(jù)庫的方法

    C#使用晚綁定來實(shí)現(xiàn)壓縮Access數(shù)據(jù)庫的方法

    這篇文章主要介紹了C#使用晚綁定來實(shí)現(xiàn)壓縮Access數(shù)據(jù)庫的方法,項(xiàng)目開發(fā)中有一定的實(shí)用價(jià)值,需要的朋友可以參考下
    2014-08-08
  • C#文件路徑操作詳細(xì)總結(jié)

    C#文件路徑操作詳細(xì)總結(jié)

    本篇文章主要是對(duì)C#中的文件路徑操作進(jìn)行了詳細(xì)的總結(jié)介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助
    2014-01-01
  • C#獲取Visio模型信息的簡(jiǎn)單方法示例

    C#獲取Visio模型信息的簡(jiǎn)單方法示例

    這篇文章主要給大家介紹了關(guān)于C#獲取Visio模型信息的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • Visual Studio C#創(chuàng)建windows服務(wù)程序

    Visual Studio C#創(chuàng)建windows服務(wù)程序

    用Visual C#創(chuàng)建Windows服務(wù)不是一件困難的事,本文就將指導(dǎo)你一步一步創(chuàng)建一個(gè)Windows服務(wù)并使用它,本文主要介紹了Visual Studio C#創(chuàng)建windows服務(wù)程序,感興趣的可以了解一下
    2024-01-01

最新評(píng)論