Version: 2017.2

ArcHandle

class in UnityEditor.IMGUI.Controls

切换到手册

描述

用于在场景视图中编辑角度和半径的复合手柄类。

场景视图中的 ArcHandle。\ \ 该类允许您显示用于编辑圆弧角度和半径的控制手柄。圆弧源自 Vector3.forward,乘以 radius 并围绕 Vector3.up 旋转。由该类的 DrawHandle 方法渲染的手柄受 Handles 类(例如 Handles.matrixHandles.color)中的全局状态影响。\ \ 以下组件通过角度和力属性定义对象。

using UnityEngine;

public class ProjectileExample : MonoBehaviour { public float elevationAngle { get { return m_ElevationAngle; } set { m_ElevationAngle = value; } } [SerializeField] float m_ElevationAngle = 45f;

public float impulse { get { return m_Impulse; } set { m_Impulse = value; } } [SerializeField] float m_Impulse = 20f;

public Vector3 facingDirection { get { Vector3 result = transform.forward; result.y = 0f; return result.sqrMagnitude == 0f ? Vector3.forward : result.normalized; } }

protected virtual void Start() { GameObject ball = GameObject.CreatePrimitive(PrimitiveType.Sphere);

Vector3 direction = facingDirection; direction = Quaternion.AngleAxis(elevationAngle, Vector3.Cross(direction, Vector3.up)) * direction; ball.AddComponent<Rigidbody>().AddForce(direction * impulse, ForceMode.Impulse); } }

以下自定义编辑器示例允许您在场景视图中编辑此组件的仰角和力属性,其中力由手柄的半径表示。

using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;

[CustomEditor(typeof(ProjectileExample))] public class ProjectileExampleEditor : Editor { ArcHandle m_ArcHandle = new ArcHandle();

protected virtual void OnEnable() { // arc handle has no radius handle by default m_ArcHandle.SetColorWithRadiusHandle(Color.white, 0.1f); }

// the OnSceneGUI callback uses the scene view camera for drawing handles by default protected virtual void OnSceneGUI() { ProjectileExample projectileExample = (ProjectileExample)target;

// copy the target object's data to the handle m_ArcHandle.angle = projectileExample.elevationAngle; m_ArcHandle.radius = projectileExample.impulse;

// set the handle matrix so that angle extends upward from target's facing direction along ground Vector3 handleDirection = projectileExample.facingDirection; Vector3 handleNormal = Vector3.Cross(handleDirection, Vector3.up); Matrix4x4 handleMatrix = Matrix4x4.TRS( projectileExample.transform.position, Quaternion.LookRotation(handleDirection, handleNormal), Vector3.one );

using (new Handles.DrawingScope(handleMatrix)) { // draw the handle EditorGUI.BeginChangeCheck(); m_ArcHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { // record the target object before setting new values so changes can be undone/redone Undo.RecordObject(projectileExample, "Change Projectile Properties");

// copy the handle's updated data back to the target object projectileExample.elevationAngle = m_ArcHandle.angle; projectileExample.impulse = m_ArcHandle.radius; } } } }

另请参阅:Editor.OnSceneGUIHandles.SetCamera

变量

angle返回或指定手柄圆弧的角度。
angleHandleColor返回或指定角度控制手柄的颜色。
angleHandleDrawFunctionAn optional CapFunction to use when displaying the angle control handle. Defaults to a line terminated with Handles.CylinderHandleCap if no value is specified.
angleHandleSizeFunctionAn optional SizeFunction to specify how large the angle control handle should be. Defaults to a fixed screen-space size.
fillColor返回或指定圆弧形状的颜色。
radius返回或指定手柄圆弧的半径。
radiusHandleColor返回或指定半径控制手柄的颜色。
radiusHandleDrawFunctionAn optional CapFunction to use when displaying the radius control handle. Defaults to a Handles.DotHandleHandleCap along the arc if no value is specified.
radiusHandleSizeFunctionAn optional SizeFunction to specify how large the radius control handle should be. Defaults to a fixed screen-space size.
wireframeColor返回或指定沿圆弧外侧曲线的颜色。

构造函数

ArcHandle创建 ArcHandle 类的新实例。

公共函数

DrawHandle使用实例的当前配置在当前手柄摄像机中显示此实例的函数。
SetColorWithoutRadiusHandle将 angleHandleColor、wireframeColor 和 fillColor 设置为相同的值,其中 fillColor 将具有指定的 Alpha 值。radiusHandleColor 将被设置为 Color.clear,且半径手柄将被禁用。
SetColorWithRadiusHandle将 angleHandleColor、radiusHandleColor、wireframeColor 和 fillColor 设置为相同的值,其中 fillColor 将具有指定的 Alpha 值。
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961