Unity编辑器类在Scene下绘制缩放控制柄, 黄色的为绘制一个方向上的方法, 红绿蓝三个是绘制三个方向的
在Editor文件夹下创建脚本HandlerTest
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(Arraw))]
public class HandlerTest : Editor {
float rectangleSize = 3;
void OnSceneGUI()
{
float width = HandleUtility.GetHandleSize(Vector3.zero) * 0.5f;
Arraw arraw = (Arraw)target;
Handles.color = Color.red;
//返回旋转角度,绘制三个方向上的比例
arraw.scale = Handles.ScaleHandle(arraw.scale, arraw.transform.position,
arraw.transform.rotation, 5.0f);
Handles.color = Color.yellow;
arraw.scalAAA = Handles.ScaleSlider( arraw.scalAAA, arraw.transform.position,
Vector3.up, Quaternion.identity, 10, HandleUtility.GetHandleSize(arraw.transform.position));
if (GUI.changed)
{
EditorUtility.SetDirty(arraw);
}
}
}
Arraw脚本如下,将其拖拽到需要绘制的对象上即可
using UnityEngine;
using System.Collections;
public class Arraw : MonoBehaviour {
public Vector3 scale = new Vector3(1, 1, 1);
public float scalAAA = 1.0f;
}