Unity之Handles矩形控制器-十二

Unity编辑器类在Scene下创建举行控制器

Unity之Handles矩形控制器-十二_第1张图片



在Editor文件夹下创建脚本
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;

        Handles.RectangleCap(0, arraw.transform.position + new Vector3(5, 0, 0),
            arraw.transform.rotation, rectangleSize);

        if (GUI.changed)
        {
             EditorUtility.SetDirty(arraw);
        }

    }
}





Arraw脚本如下,将其拖拽到需要绘制的对象上即可
using UnityEngine;
using System.Collections;

public class Arraw : MonoBehaviour {

    public float areaOfEffect = 5;

}








你可能感兴趣的:(Unity之Editor)