scale | 用户可以修改的值。 |
position | Handles.matrix 空间中手柄的位置。 |
direction | Handles.matrix 空间中手柄的方向。 |
rotation | Handles.matrix 空间中手柄的旋转。 |
size | Handles.matrix 空间中手柄的大小。如果您想要一个恒定的屏幕空间大小,请使用 HandleUtility.GetHandleSize。 |
snap | 贴靠增量。请参阅 Handles.SnapValue。 |
float 通过用户与手柄的交互修改的新值。如果用户没有移动手柄,则将返回您传递给相应函数的值。
创建一个定向缩放滑动条。
This method will draw a 3D-draggable handle on the screen that looks like one axis on Unity's built-in scale tool. The handle will stretch and will scale a single float up and down.
Scale slider handle in the Scene View.
Add the following script to your Assets folder as ScaleSliderExample.cs and add the ScaleSliderExample component to an object in a Scene.
using UnityEngine;
[ExecuteInEditMode] public class ScaleSliderExample : MonoBehaviour { public float scale { get { return m_Scale; } set { m_Scale = value; } } [SerializeField] private float m_Scale = 1f;
public virtual void Update() { transform.localScale = new Vector3(scale, 1f, 1f); } }
将以下脚本作为 ScaleSliderExampleEditor.cs 添加到 Assets/Editor,然后选择包含 ScaleSliderExample 组件的对象。
using UnityEditor; using UnityEngine;
[CustomEditor(typeof(ScaleSliderExample)), CanEditMultipleObjects] public class ScaleSliderExampleEditor : Editor { public void OnSceneGUI() { ScaleSliderExample example = (ScaleSliderExample)target;
float size = HandleUtility.GetHandleSize(example.transform.position) * 1f; float snap = 0.5f;
EditorGUI.BeginChangeCheck(); float scale = Handles.ScaleSlider(example.scale, example.transform.position, example.transform.right, example.transform.rotation, size, snap); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Change Scale Value"); example.scale = scale; example.Update(); } } }