当前位置: 首页 > 工具软件 > Gizmo > 使用案例 >

Unity Editor 知识点整理(Gizmo 常用绘制方法)

晋承运
2023-12-01
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GizmoDemo : MonoBehaviour
{
    public Vector3 center = Vector3.zero;
    public Vector3 size = Vector3.one;

    public float radius = 1;

    public Vector3 rayFrom = Vector3.zero;
    public Vector3 rayDirection = Vector3.up;

    public Vector3 lineFrom = new Vector3(1, 0, 0);
    public Vector3 lineTo = new Vector3(0, 0, 1);

    public Vector3 iconPosition = Vector3.zero;

    public Rect screenRect = new Rect(0,0,100,100);
    public Texture texture;

    public Vector3 cameraPostion = Vector3.zero;
    public float fov = 60;
    public float maxViewRange = 3f;
    public float minViewRange = 1f;
    public float aspect = 1.3f;//相机平面的长宽比


    private void OnDrawGizmos()
    {
        //绘制立方体
        Gizmos.DrawCube(center,size);
        //绘制线框立方体
        Gizmos.DrawWireCube(center, size);

        //绘制圆形
        Gizmos.DrawSphere(center,radius);
        //绘制线框圆形
        Gizmos.DrawWireSphere(center, radius);

        //绘制射线      
        Gizmos.DrawRay(rayFrom, rayDirection);

        //绘制直线
        Gizmos.DrawLine(lineFrom,lineTo);

        //绘制icon
        //icon(jpg,png等) 需要放在指定的文件夹Gizmos下
        //icon类型为sprite
        Gizmos.DrawIcon(iconPosition, "UI_LivesAvatar");

        //绘制纹理贴图 指定范围 绘制在xy平面
        //贴图类型为default
        Gizmos.DrawGUITexture(screenRect,texture);

        //绘制视锥体
        Gizmos.DrawFrustum(cameraPostion,fov,maxViewRange,minViewRange,aspect);
    }



    private void OnDrawGizmosSelected()
    {
        
    }
}

 类似资料: