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. |
string The tag selected by the user.
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(); } }
Did you find this page useful? Please give it a rating: