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

参数

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

返回

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

描述

创建一个 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!"); } }