public static bool Button (Vector3 position, Quaternion direction, float size, float pickSize, Handles.CapFunction capFunction);

Parameters

position要在 Handles.matrix 空间中绘制按钮的位置。
direction Handles.matrix 空间中按钮的旋转。
size手柄的可视大小。如果您想要一个恒定的屏幕空间大小,请使用 HandleUtility.GetHandleSize
pickSize用于检测单击的按钮的大小。如果您想要一个恒定的屏幕空间大小,请使用 HandleUtility.GetHandleSize
capFunction按钮的绘制样式。

Returns

bool 当用户单击按钮时,返回 true。

Description

创建一个 3D 按钮。

This button works like one drawn with GUI.Button, but it has a 3D position and is drawn by a handle function.


Button Handle as a rectangle in the Scene View.

Add the following script to your Assets folder as ButtonExample.cs and add the ButtonExample component to an object in a Scene.

using UnityEngine;

public class ButtonExample : MonoBehaviour {}

将以下脚本作为 ButtonExampleEditor.cs 添加到 Assets/Editor,然后选择包含 ButtonExample 组件的对象。

using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(ButtonExample)), CanEditMultipleObjects] class ButtonExampleEditor : Editor { protected virtual void OnSceneGUI() { ButtonExample buttonExample = (ButtonExample)target;

Vector3 position = buttonExample.transform.position + Vector3.up * 2f; float size = 2f; float pickSize = size * 2f;

if (Handles.Button(position, Quaternion.identity, size, pickSize, Handles.RectangleHandleCap)) Debug.Log("The button was pressed!"); } }