public static string TagField (Rect position, string tag, GUIStyle style= EditorStyles.popup);
public static string TagField (Rect position, string label, string tag, GUIStyle style= EditorStyles.popup);
public static string TagField (Rect position, GUIContent label, string tag, GUIStyle style= EditorStyles.popup);

参数

position屏幕上用于字段的矩形。
label(可选)字段前的标签。
tag字段显示的标签。
style可选 GUIStyle

返回

string 用户选择的标签。

描述

创建一个标签选择字段。


Tag field in an Editor window.

// Change the Tag and/or the layer of the selected GameObjects.

class EditorGUITagLayerField extends EditorWindow {

var selectedTag : String = ""; var selectedLayer : int = 0;

@MenuItem("Examples/Tag - Layer for Selection") static function Init() { var window = GetWindow(EditorGUITagLayerField); window.position = Rect(0,0,350,70); window.Show(); }

function OnGUI() { selectedTag = EditorGUI.TagField( Rect(3,3,position.width/2 - 6, 20), "New Tag:", selectedTag); selectedLayer = EditorGUI.LayerField( Rect(position.width/2 + 3,3, position.width/2 - 6, 20), "New Layer:", selectedLayer);

if(Selection.activeGameObject) { if(GUI.Button(Rect(3,25,90,17),"Change Tags")) for(var go : GameObject in Selection.gameObjects) go.tag = selectedTag; if(GUI.Button(Rect(position.width-96, 25,90,17),"Change Layers")) for(var go : GameObject in Selection.gameObjects) go.layer = selectedLayer; } }

function OnInspectorUpdate() { Repaint(); } }