Version: Unity 6 Beta (6000.0)
LanguageEnglish
  • C#

Gizmos.CalculateLOD

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static float CalculateLOD(Vector3 position, float radius);

Parameters

position The centre of the gizmo in world space.
radius The maximum extent of the gizmo.

Returns

float Returns a value between 0 and 1 that represents the level of detail for the gizmo.

Description

Determines the appropriate level of detail for a gizmo in the Scene view at a specified position with a specified radius.

A return value of 0 indicates the gizmo is not visible. The gizmo might not be visible because it is too small on the screen or because it is outside of the Scene view camera frustum. The return value is quantized to eighths to reduce the number of produced batches. This can be further controlled with the 'Fade Gizmos' options in the Gizmos menu.

using UnityEngine;

public class MyLODedComponent : MonoBehaviour { // Draw a blue sphere at the transform's position, fading out as it gets further away private void OnDrawGizmos() { float lod = Gizmos.CalculateLOD(transform.position, 1);

// Cull any gizmos that are too small or off screen if (lod == 0.0f) return;

// Fade the gizmos out so that they don't pop in and out when scrolling around the scene Gizmos.color = Color.blue * lod; Gizmos.DrawSphere(transform.position, 1); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961