Select your preferred scripting language. All code snippets will be displayed in this language.
class in UnityEditor.IMGUI.Controls
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseA class for a compound handle to edit an angle and a radius in the Scene view.
ArcHandle in the Scene View.
This class allows you to display control handles for editing the angle and radius of an arc. The arc originates at Vector3.forward multiplied by the radius and rotates around Vector3.up. The handle rendered by this class's DrawHandle method is affected by global state in the Handles class, such as Handles.matrix and Handles.color.
The following component defines an object with an angle and force property.
#pragma strict public class ProjectileExample extends MonoBehaviour { floatelevationAngle { return m_ElevationAngle; } { m_ElevationAngle = value; } @SerializeField var m_ElevationAngle: float = 45f; floatimpulse { return m_Impulse; } { m_Impulse = value; } @SerializeField var m_Impulse: float = 20f; Vector3facingDirection { var result: Vector3 = transform.forward; result.y = 0f; return result.sqrMagnitude == 0f ? Vector3.forward : result.normalized; } protected virtual function Start() { var ball: GameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); var direction: Vector3 = facingDirection; direction = Quaternion.AngleAxis(elevationAngle, Vector3.Cross(direction, Vector3.up)) * direction; ball.AddComponent.<Rigidbody>().AddForce(direction * impulse, ForceMode.Impulse); } }
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); } }
The following Custom Editor example allows you to edit the elevation angle and force properties for this component in the Scene view, where the force is represented by the radius of the handle.
#pragma strict @CustomEditor(ProjectileExample) public class ProjectileExampleEditor extends Editor { var m_ArcHandle: ArcHandle = new ArcHandle(); protected virtual function 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 function OnSceneGUI() { var projectileExample: ProjectileExample = ProjectileExampletarget; // 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 var handleDirection: Vector3 = projectileExample.facingDirection; var handleNormal: Vector3 = Vector3.Cross(handleDirection, Vector3.up); var handleMatrix: Matrix4x4 = Matrix4x4.TRS(projectileExample.transform.position, Quaternion.LookRotation(handleDirection, handleNormal), Vector3.one); 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; } } } }
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; } } } }
See Also: Editor.OnSceneGUI, Handles.SetCamera.
angle | Returns or specifies the angle of the arc for the handle. |
angleHandleColor | Returns or specifies the color of the angle control handle. |
angleHandleDrawFunction | An optional CapFunction to use when displaying the angle control handle. Defaults to a line terminated with Handles.CylinderHandleCap if no value is specified. |
angleHandleSizeFunction | An optional SizeFunction to specify how large the angle control handle should be. Defaults to a fixed screen-space size. |
fillColor | Returns or specifies the color of the arc shape. |
radius | Returns or specifies the radius of the arc for the handle. |
radiusHandleColor | Returns or specifies the color of the radius control handle. |
radiusHandleDrawFunction | An optional CapFunction to use when displaying the radius control handle. Defaults to a Handles.DotHandleHandleCap along the arc if no value is specified. |
radiusHandleSizeFunction | An optional SizeFunction to specify how large the radius control handle should be. Defaults to a fixed screen-space size. |
wireframeColor | Returns or specifies the color of the curved line along the outside of the arc. |
ArcHandle | Creates a new instance of the ArcHandle class. |
DrawHandle | A function to display this instance in the current handle camera using its current configuration. |
SetColorWithoutRadiusHandle | Sets angleHandleColor, wireframeColor, and fillColor to the same value, where fillColor will have the specified alpha value. radiusHandleColor will be set to Color.clear and the radius handle will be disabled. |
SetColorWithRadiusHandle | Sets angleHandleColor, radiusHandleColor, wireframeColor, and fillColor to the same value, where fillColor will have the specified alpha value. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thanks for helping to make the Unity documentation better!