Version: 2017.3

JointAngularLimitHandle

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.

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.

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

변수

angleHandleDrawFunctionAn optional CapFunction to use for displaying the control handles. Defaults to a line terminated with Handles.CylinderHandleCap if no value is specified.
angleHandleSizeFunctionAn optional SizeFunction to specify how large the control handles should be. Defaults to a fixed screen-space size.
fillAlphaReturns or specifies the opacity to use when rendering fill shapes for the range of motion for each axis. Defaults to 0.1.
radiusReturns or specifies the radius of the arc for the handle. Defaults to 1.0.
wireframeAlphaReturns or specifies the opacity to use for the curved lines along the outside of the arcs of motion. Defaults to 1.0.
xHandleColorReturns or specifies the color to use for the handle limiting motion around the x-axis. Defaults to Handles.xAxisColor.
xMaxReturns or specifies the maximum angular motion about the x-axis.
xMinReturns or specifies the minimum angular motion about the x-axis.
xMotionReturns or specifies how angular motion is limited about the x-axis. Defaults to ConfigurableJointMotion.Limited.
xRangeReturns or specifies the range of valid values for angular motion about the x-axis. Defaults to [-180.0, 180.0].
yHandleColorReturns or specifies the color to use for the handle limiting motion around the y-axis. Defaults to Handles.yAxisColor.
yMaxReturns or specifies the maximum angular motion about the y-axis.
yMinReturns or specifies the minimum angular motion about the y-axis.
yMotionReturns or specifies how angular motion is limited about the y-axis. Defaults to ConfigurableJointMotion.Limited.
yRangeReturns or specifies the range of valid values for angular motion about the y-axis. Defaults to [-180.0, 180.0].
zHandleColorReturns or specifies the color to use for the handle limiting motion around the z-axis. Defaults to Handles.zAxisColor.
zMaxReturns or specifies the maximum angular motion about the z-axis.
zMinReturns or specifies the minimum angular motion about the z-axis.
zMotionReturns or specifies how angular motion is limited about the z-axis. Defaults to ConfigurableJointMotion.Limited.
zRangeReturns or specifies the range of valid values for angular motion about the z-axis. Defaults to [-180.0, 180.0].

생성자

JointAngularLimitHandleCreates a new instance of the JointAngularLimitHandle class.

Public 함수

DrawHandleA function to display this instance in the current handle camera using its current configuration.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961