您的位置:首页 > 移动开发 > Unity3D

Unity之Handles绘制球体控制柄-十五

2014-12-26 19:03 351 查看
Unity编辑器类在Scene下绘制球体



在Editor文件夹下创建脚本 HandlerTest

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(Arraw))]
public class HandlerTest : Editor {

float sphereSize = 3;

void OnSceneGUI()
{
float width = HandleUtility.GetHandleSize(Vector3.zero) * 0.5f;
Arraw arraw = (Arraw)target;

Handles.color = Color.red;

//绘制球体
Handles.SphereCap( 0, arraw.transform.position + new Vector3(5, 0, 0),
arraw.transform.rotation, sphereSize);

Handles.color = Color.green;
//绘制球体
Handles.SphereCap(0, arraw.transform.position + new Vector3( 0, 5, 0),
arraw.transform.rotation, sphereSize);

Handles.color = Color.blue;
//绘制球体
Handles.SphereCap(0, arraw.transform.position + new Vector3(0, 0, 5),
arraw.transform.rotation, sphereSize);

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

}
}

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

public class Arraw : MonoBehaviour {

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: