label | (可选)字段前的标签。 |
layer | 字段中显示的层。 |
style | 可选 GUIStyle。 |
options | (可选)一个布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。另请参阅:GUILayout.Width、GUILayout.Height、GUILayout.MinWidth、GUILayout.MaxWidth、GUILayout.MinHeight、 GUILayout.MaxHeight、GUILayout.ExpandWidth、GUILayout.ExpandHeight。 |
int 用户选择的层。
创建一个层选择字段。
\ 设置所选游戏对象的层。
// Simple editor script that lets you set the layer for the // selected GameObjects.
using UnityEngine; using UnityEditor;
public class LayerFieldExample : EditorWindow { static int selectedLayer = 0;
[MenuItem("Examples/Layer Field usage")] static void Init() { LayerFieldExample window = (LayerFieldExample)GetWindow(typeof(LayerFieldExample)); window.Show(); }
// Disable menu if we dont have at least 1 gameobject selected [MenuItem("Examples/Layer Field usage", true)] static bool ValidateSelection() { return Selection.activeGameObject != null; }
void OnGUI() { selectedLayer = EditorGUILayout.LayerField("Layer for Objects:", selectedLayer); if (GUILayout.Button("Set Layer!")) SetLayer(); }
static void SetLayer() { foreach (var go in Selection.gameObjects) go.layer = selectedLayer; } }