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; } }