Unity编辑器空物体位置可视化

效果图

image

 

编辑器可见,Game视窗不可见,适用于空物体位置可视化

 

代码如下:

using UnityEngine;
using System.Collections.Generic;

public class MudflowPathGuide : MonoBehaviour
{
    [Header("路径点设置")]
    public List<Transform> pathPoints = new List<Transform>();
   

    [Header("路径可视化")]
    public bool showPath = true;
    public Color pathColor = new Color(1f, 0.5f, 0f, 0.8f);
    public float gizmoSize = 0.5f;

 

    void OnDrawGizmos()
    {
        if (!showPath || pathPoints.Count < 2) return;

        // 绘制路径点
        Gizmos.color = Color.red;
        foreach (var point in pathPoints)
        {
            if (point != null)
            {
                Gizmos.DrawSphere(point.position, gizmoSize);
            }
        }

        // 绘制路径线
        Gizmos.color = pathColor;
        for (int i = 0; i < pathPoints.Count - 1; i++)
        {
            if (pathPoints[i] != null && pathPoints[i + 1] != null)
            {
                Gizmos.DrawLine(pathPoints[i].position, pathPoints[i + 1].position);

              
            }
        }
    }

  
}

 

本次就记录一下。

 

posted @ 2025-10-29 16:29  剑起苍穹  阅读(7)  评论(0)    收藏  举报
/*鼠标点击特效*/