Unity编辑器类在Scene下绘制从点连接到点的线
在Editor文件夹下创建脚本
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(Arraw))]
public class HandlerTest : Editor {
Vector3[] positions;
void OnSceneGUI()
{
float width = HandleUtility.GetHandleSize(Vector3.zero) * 0.5f;
Arraw arraw = (Arraw)target;
for (int i = 0; i < arraw.polyLineObjs.Length; i++)
{
if (arraw.polyLineObjs[i])
{
Handles.DrawLine(arraw.transform.position, arraw.polyLineObjs[i].transform.position);
}
}
if (GUI.changed)
{
EditorUtility.SetDirty(arraw);
}
}
}
Arraw脚本如下,将其拖拽到需要连线的对象即可
using UnityEngine;
using System.Collections;
public class Arraw : MonoBehaviour {
public GameObject[] polyLineObjs; //存储对象
}