Version: 2022.3
言語: 日本語
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 ユーザーによって設定された値

説明

Makes a tag selection field.


Tag field in an Editor window.

using UnityEngine;
using UnityEditor;

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

class EditorGUITagLayerField : EditorWindow { string selectedTag = ""; int selectedLayer = 0;

[MenuItem("Examples/Tag - Layer for Selection")] static void Init() { EditorWindow window = GetWindow<EditorGUITagLayerField>(); window.position = new Rect(0, 0, 350, 70); window.Show(); }

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

if (Selection.activeGameObject) { if (GUI.Button(new Rect(3, 25, 90, 17), "Change Tags")) { foreach (GameObject go in Selection.gameObjects) go.tag = selectedTag; }

if (GUI.Button(new Rect(position.width - 96, 25, 90, 17), "Change Layers")) { foreach (GameObject go in Selection.gameObjects) go.layer = selectedLayer; } } }

void OnInspectorUpdate() { Repaint(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961