言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

EditorGUI.LayerField

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

Sumbission failed

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

Close

Cancel

public static function LayerField(position: Rect, label: GUIContent, layer: int, style: GUIStyle = EditorStyles.popup): int;
public static int LayerField(Rect position, GUIContent label, int layer, GUIStyle style = EditorStyles.popup);
public static def LayerField(position as Rect, label as GUIContent, layer as int, style as GUIStyle = EditorStyles.popup) as int

Parameters

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

Returns

int The layer selected by the user.

Description

Make a layer selection field.


Layer 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();
		}
	}