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

Parameters

positionThe position to draw the button in the space of Handles.matrix.
directionThe rotation of the button in the space of Handles.matrix.
sizeThe visual size of the handle. Use HandleUtility.GetHandleSize if you want a constant screen-space size.
pickSizeThe size of the button for the purpose of detecting a click. Use HandleUtility.GetHandleSize if you want a constant screen-space size.
capFunction@param normal Перпендикуляр диска.

Returns

bool True when the user clicks the button.

Description

Make a 3D Button.

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

Add the following script to Assets/Editor as ButtonExampleEditor.cs and select the object with the ButtonExample component.

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!"); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961