public static string TagField (string tag, params GUILayoutOption[] options);
public static string TagField (string tag, GUIStyle style, params GUILayoutOption[] options);
public static string TagField (string label, string tag, params GUILayoutOption[] options);
public static string TagField (string label, string tag, GUIStyle style, params GUILayoutOption[] options);
public static string TagField (GUIContent label, string tag, params GUILayoutOption[] options);
public static string TagField (GUIContent label, string tag, GUIStyle style, params GUILayoutOption[] options);

Parameters

label(可选)字段前的标签。
tag字段显示的标签。
style可选 GUIStyle
options一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

Returns

string 用户选择的标签。

Description

创建一个标签选择字段。


Assign tags on the selected GameObjects.

// Simple editor script that lets you set a tag for the selected GameObjects.
using UnityEditor;
using UnityEngine;

public class EditorGUILayoutTagField : EditorWindow { static string tagStr = "";

[MenuItem("Examples/Set Tags For Selection")] static void Init() { EditorWindow window = GetWindow(typeof(EditorGUILayoutTagField)); window.Show(); }

void OnGUI() { tagStr = EditorGUILayout.TagField("Tag for Objects:", tagStr); if (GUILayout.Button("Set Tag!")) { SetTags(); } }

static void SetTags() { foreach (GameObject go in Selection.gameObjects) { go.tag = tagStr; } } }