class in UnityEditor.IMGUI.Controls
A class for a compound handle to edit multiaxial angular motion limits in the Scene view.
JointAngularLimitHandle in the Scene View.
The shapes rendered by the DrawHandle method assume that angular limits are applied first along the x-axis, then the y-axis, and finally the z-axis.
The following component defines angular limits for a CharacterJoint to be added at run time.
#pragma strict public class JointExample extends MonoBehaviour { floatxMin { return m_XMin; } { m_XMin = value; } @SerializeField var m_XMin: float = -45f; floatxMax { return m_XMax; } { m_XMax = value; } @SerializeField var m_XMax: float = 45f; floatyMax { return m_YMax; } { m_YMax = value; } @SerializeField var m_YMax: float = 45f; floatzMax { return m_ZMax; } { m_ZMax = value; } @SerializeField var m_ZMax: float = 45f; protected virtual function Start() { var joint: var = gameObject.AddComponent.<CharacterJoint>(); var limit: var = joint.lowTwistLimit; limit.limit = m_XMin; joint.lowTwistLimit = limit; limit = joint.highTwistLimit; limit.limit = m_XMax; joint.highTwistLimit = limit; limit = joint.swing1Limit; limit.limit = m_YMax; joint.swing1Limit = limit; limit = joint.swing2Limit; limit.limit = m_ZMax; joint.swing2Limit = limit; } }
using UnityEngine;
public class JointExample : MonoBehaviour { public float xMin { get { return m_XMin; } set { m_XMin = value; } } [SerializeField] float m_XMin = -45f;
public float xMax { get { return m_XMax; } set { m_XMax = value; } } [SerializeField] float m_XMax = 45f;
public float yMax { get { return m_YMax; } set { m_YMax = value; } } [SerializeField] float m_YMax = 45f;
public float zMax { get { return m_ZMax; } set { m_ZMax = value; } } [SerializeField] float m_ZMax = 45f;
protected virtual void Start() { var joint = gameObject.AddComponent<CharacterJoint>();
var limit = joint.lowTwistLimit; limit.limit = m_XMin; joint.lowTwistLimit = limit;
limit = joint.highTwistLimit; limit.limit = m_XMax; joint.highTwistLimit = limit;
limit = joint.swing1Limit; limit.limit = m_YMax; joint.swing1Limit = limit;
limit = joint.swing2Limit; limit.limit = m_ZMax; joint.swing2Limit = limit; } }
The following Custom Editor example allows you to edit the serialized angular limits in the Scene view.
#pragma strict @CustomEditor(JointExample) @CanEditMultipleObjects public class JointExampleEditor extends Editor { var m_Handle: JointAngularLimitHandle = new JointAngularLimitHandle(); // the OnSceneGUI callback uses the scene view camera for drawing handles by default protected virtual function OnSceneGUI() { var jointExample: var = JointExampletarget; // copy the target object's data to the handle m_Handle.xMin = jointExample.xMin; m_Handle.xMax = jointExample.xMax; // CharacterJoint and ConfigurableJoint implement y- and z-axes symmetrically m_Handle.yMin = -jointExample.yMax; m_Handle.yMax = jointExample.yMax; m_Handle.zMin = -jointExample.zMax; m_Handle.zMax = jointExample.zMax; // set the handle matrix to match the object's position/rotation with a uniform scale var handleMatrix: Matrix4x4 = Matrix4x4.TRS(jointExample.transform.position, jointExample.transform.rotation, Vector3.one); EditorGUI.BeginChangeCheck(); new Handles.DrawingScope(handleMatrix) { // maintain a constant screen-space size for the handle's radius based on the origin of the handle matrix m_Handle.radius = HandleUtility.GetHandleSize(Vector3.zero); // draw the handle EditorGUI.BeginChangeCheck(); m_Handle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { // record the target object before setting new values so changes can be undone/redone Undo.RecordObject(jointExample, "Change Joint Example Properties"); // copy the handle's updated data back to the target object jointExample.xMin = m_Handle.xMin; jointExample.xMax = m_Handle.xMax; jointExample.yMax = m_Handle.yMax == jointExample.yMax ? -m_Handle.yMin : m_Handle.yMax; jointExample.zMax = m_Handle.zMax == jointExample.zMax ? -m_Handle.zMin : m_Handle.zMax; } } } }
using UnityEditor; using UnityEditor.IMGUI.Controls; using UnityEngine;
[CustomEditor(typeof(JointExample)), CanEditMultipleObjects] public class JointExampleEditor : Editor { JointAngularLimitHandle m_Handle = new JointAngularLimitHandle();
// the OnSceneGUI callback uses the scene view camera for drawing handles by default protected virtual void OnSceneGUI() { var jointExample = (JointExample)target;
// copy the target object's data to the handle m_Handle.xMin = jointExample.xMin; m_Handle.xMax = jointExample.xMax;
// CharacterJoint and ConfigurableJoint implement y- and z-axes symmetrically m_Handle.yMin = -jointExample.yMax; m_Handle.yMax = jointExample.yMax;
m_Handle.zMin = -jointExample.zMax; m_Handle.zMax = jointExample.zMax;
// set the handle matrix to match the object's position/rotation with a uniform scale Matrix4x4 handleMatrix = Matrix4x4.TRS( jointExample.transform.position, jointExample.transform.rotation, Vector3.one );
EditorGUI.BeginChangeCheck();
using (new Handles.DrawingScope(handleMatrix)) { // maintain a constant screen-space size for the handle's radius based on the origin of the handle matrix m_Handle.radius = HandleUtility.GetHandleSize(Vector3.zero);
// draw the handle EditorGUI.BeginChangeCheck(); m_Handle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { // record the target object before setting new values so changes can be undone/redone Undo.RecordObject(jointExample, "Change Joint Example Properties");
// copy the handle's updated data back to the target object jointExample.xMin = m_Handle.xMin; jointExample.xMax = m_Handle.xMax;
jointExample.yMax = m_Handle.yMax == jointExample.yMax ? -m_Handle.yMin : m_Handle.yMax;
jointExample.zMax = m_Handle.zMax == jointExample.zMax ? -m_Handle.zMin : m_Handle.zMax; } } } }
angleHandleDrawFunction | An optional CapFunction to use for displaying the control handles. Defaults to a line terminated with Handles.CylinderHandleCap if no value is specified. |
angleHandleSizeFunction | An optional SizeFunction to specify how large the control handles should be. Defaults to a fixed screen-space size. |
fillAlpha | Returns or specifies the opacity to use when rendering fill shapes for the range of motion for each axis. Defaults to 0.1. |
radius | Returns or specifies the radius of the arc for the handle. Defaults to 1.0. |
wireframeAlpha | Returns or specifies the opacity to use for the curved lines along the outside of the arcs of motion. Defaults to 1.0. |
xHandleColor | Returns or specifies the color to use for the handle limiting motion around the x-axis. Defaults to Handles.xAxisColor. |
xMax | Returns or specifies the maximum angular motion about the x-axis. |
xMin | Returns or specifies the minimum angular motion about the x-axis. |
xMotion | Returns or specifies how angular motion is limited about the x-axis. Defaults to ConfigurableJointMotion.Limited. |
xRange | Returns or specifies the range of valid values for angular motion about the x-axis. Defaults to [-180.0, 180.0]. |
yHandleColor | Returns or specifies the color to use for the handle limiting motion around the y-axis. Defaults to Handles.yAxisColor. |
yMax | Returns or specifies the maximum angular motion about the y-axis. |
yMin | Returns or specifies the minimum angular motion about the y-axis. |
yMotion | Returns or specifies how angular motion is limited about the y-axis. Defaults to ConfigurableJointMotion.Limited. |
yRange | Returns or specifies the range of valid values for angular motion about the y-axis. Defaults to [-180.0, 180.0]. |
zHandleColor | Returns or specifies the color to use for the handle limiting motion around the z-axis. Defaults to Handles.zAxisColor. |
zMax | Returns or specifies the maximum angular motion about the z-axis. |
zMin | Returns or specifies the minimum angular motion about the z-axis. |
zMotion | Returns or specifies how angular motion is limited about the z-axis. Defaults to ConfigurableJointMotion.Limited. |
zRange | Returns or specifies the range of valid values for angular motion about the z-axis. Defaults to [-180.0, 180.0]. |
JointAngularLimitHandle | Creates a new instance of the JointAngularLimitHandle class. |
DrawHandle | A function to display this instance in the current handle camera using its current configuration. |
Did you find this page useful? Please give it a rating: