Version: 2021.1
public static void BeginGUI ();

描述

在 3D 手柄 GUI 内开始一个 2D GUI 块。

函数调用的 GUILayout 序列的开头。 根据预期,EndGUI 用于关闭这些 GUI。

另请参阅:Handles.EndGUI

\ 场景视图中的 GUI。

// Change the transform values for the selected object.
// When selected this script starts and the handleExample is managed.
// The HandlesGUI.BeginGUI() and EndGUI() functions allow the shieldArea
// to be changed back to five, which is the starting value.

using UnityEditor; using UnityEngine;

[CustomEditor(typeof(HandleExample))] class HandleExampleEditor : Editor { protected virtual void OnSceneGUI() { HandleExample handleExample = (HandleExample)target;

if (handleExample == null) { return; }

Handles.color = Color.yellow;

GUIStyle style = new GUIStyle(); style.normal.textColor = Color.green;

Vector3 position = handleExample.transform.position + Vector3.up * 2f; string posString = position.ToString();

Handles.Label(position, posString + "\nShieldArea: " + handleExample.shieldArea.ToString(), style );

Handles.BeginGUI(); if (GUILayout.Button("Reset Area", GUILayout.Width(100))) { handleExample.shieldArea = 5; } Handles.EndGUI();

Handles.DrawWireArc( handleExample.transform.position, handleExample.transform.up, -handleExample.transform.right, 180, handleExample.shieldArea);

handleExample.shieldArea = Handles.ScaleValueHandle(handleExample.shieldArea, handleExample.transform.position + handleExample.transform.forward * handleExample.shieldArea, handleExample.transform.rotation, 1, Handles.ConeHandleCap, 1); } }

添加一个脚本,指定可在 SceneView 中 生成动画的对象。

using UnityEngine;

[ExecuteInEditMode] public class HandleExample : MonoBehaviour { public float shieldArea = 5.0f; }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961