Version: 2017.3 (switch to 2017.4)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorGUI.TagField

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

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

Parameters

position Rectangle on the screen to use for the field.
label Optional label in front of the field.
tag The tag the field shows.
style Optional GUIStyle.

Returns

string The tag selected by the user.

Description

Make a tag selection field.


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(); } }
对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答