Version: 2021.3
public static int LayerField (int layer, params GUILayoutOption[] options);
public static int LayerField (int layer, GUIStyle style, params GUILayoutOption[] options);
public static int LayerField (string label, int layer, params GUILayoutOption[] options);
public static int LayerField (string label, int layer, GUIStyle style, params GUILayoutOption[] options);
public static int LayerField (GUIContent label, int layer, params GUILayoutOption[] options);
public static int LayerField (GUIContent label, int layer, GUIStyle style, params GUILayoutOption[] options);

参数

label (可选)字段前的标签。
layer 字段中显示的层。
style 可选 GUIStyle
options 一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.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; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961