前面给大家分享了一个关卡编辑器,但是我们的策划同学反映在摆道具的时候不够直观,坐标总是对不齐,于是就使用Gizmos给策划同学们写了一个辅助线的脚本,分享出来:
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteInEditMode]
public class MapEditor : MonoBehaviour {
public Color sideColor = Color.white;
public Color insideColor = Color.black;
public float width = 10.0f;
public float height = 1.0f;
public int mapHeight = 10;
public int mapWidth = 100;
//public float autoDPos = 0.1f;
// Use this for initialization
void Start () {
}
void OnDrawGizmos()
{
DrawBGLine();
}
public void DrawBGLine(){
#if UNITY_EDITOR
Gizmos.color = insideColor;
for (float y = 0; y < mapHeight; y += height)
{
Gizmos.DrawLine(new Vector3(0, y , -1f),
new Vector3(mapWidth, y , -1f));
Handles.Label(new Vector3(-1f,y+0.5f , 0f), "" + y);