Version: 2020.3
public static int GetControlID (FocusType focus);
public static int GetControlID (FocusType focus, Rect position);

描述

为控件获取一个唯一的 ID。

using UnityEngine;

public class Example : MonoBehaviour { // Prints a not used ID that can be assigned to a control

void OnGUI() { // Gets a ID for a control that cannot receive keyboard focus (A button) Debug.Log("Available id: " + GUIUtility.GetControlID(FocusType.Passive)); } }

public static int GetControlID (int hint, FocusType focus);
public static int GetControlID (int hint, FocusType focusType, Rect rect);

描述

为控件获取一个唯一的 ID,使用整数作为提示,以帮助确保 ID 与控件的正确匹配。


public static int GetControlID (GUIContent contents, FocusType focus);
public static int GetControlID (GUIContent contents, FocusType focus, Rect position);

描述

为控件获取一个唯一的 ID,使用标签内容作为提示,以帮助确保 ID 与控件的正确匹配。