Version: Unity 6.0 (6000.0)
语言 : 中文
光照浏览器窗口
添加环境中的环境光

自定义光照浏览器

Light Explorer 扩展让您可以创建自定义版本的 Light Explorer 窗口。您可以使用此选项来调整 Light Explorer 窗口的功能,使其与自定义可编程渲染管线 (SRP) 或高清渲染管线的自定义光源配合使用。

在 Light Explorer 窗口会显示场景中的所有光源,并让您编辑它们的属性。凭借此扩展,您可以通过多种方式扩展当前窗口。例如,您可以执行以下操作:

  • 更改选项卡(从简单地更改选项卡名称到添加自定义选项卡)以显示不同类型的__ GameObject__Unity 场景中的基础对象,可以表示角色、道具、风景、摄像机、路径点等。GameObject 的功能由所附的组件决定。更多信息
    See in Glossary
    的列表。例如,如果要显示自定义反射探针的属性信息,这将很有用。
  • 更改选项卡上的列(同样从更改名称到添加自定义列均可)。添加列可以让您轻松查看更多光源属性。

扩展光照浏览器

要扩展光照浏览器,可以继承自:

  • ILightingExplorerExtension 接口并覆盖 GetContentTabs 方法。
  • 继承自 ILightingExplorerExtensionDefaultLightingExplorerExtension 类。此类提供了窗口中已经存在的所有内容。如果您只希望覆盖选项卡的数量、选项卡的标题或要显示的光源,请使用此方法。要了解如何以这种方式扩展光照浏览器,请参阅下方示例。

示例代码

本节中的示例展示了如何扩展默认光照浏览器的类以仅显示光源的名称 (Name) 列,以及如何更改选项卡的数量。在您自己的实现中,您可以按需覆盖任意数量的方法。

以下示例仅显示了光源的名称列:

using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor;

[SupportedOnRenderPipeline(typeof(ExampleRenderPipelineAsset))]
public class SimpleExplorerExtension : DefaultLightingExplorerExtension
{
    private static class Styles
    {
        public static readonly GUIContent Name = EditorGUIUtility.TrTextContent("Name");
    }
    
    protected override LightingExplorerTableColumn[] GetLightColumns()
    {
        return new[]
        {
            new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Name, Styles.Name, null, 200), // 0: Name
        };
    }
}

以下示例仅显示光源的名称和启用状态,并隐藏了自发光材质 (Emissive Materials) 选项卡(仅显示 3 个选项卡,而不是 4 个)

using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor;

[SupportedOnRenderPipeline(typeof(ExampleRenderPipelineAsset))]
public class ComplexLightExplorerExtension : DefaultLightingExplorerExtension
{
    private static class Styles
    {
        public static readonly GUIContent Name = EditorGUIUtility.TrTextContent("Name");
        public static readonly GUIContent Enabled = EditorGUIUtility.TrTextContent("Enabled");
    }
    
    protected override UnityEngine.Object[] GetLights()
    {
        return Resources.FindObjectsOfTypeAll<Light>();
    }

    protected override LightingExplorerTableColumn[] GetLightColumns()
    {
        return new[]
        {
            new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Name, Styles.Name, null, 200), // 0: Name
            new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, Styles.Enabled, "m_Enabled", 25), // 1: Enabled
        };
    }

    public override LightingExplorerTab[] GetContentTabs()
    {
        return new[]
        {
            new LightingExplorerTab("Lights", GetLights, GetLightColumns, true),
            new LightingExplorerTab("2D Lights", Get2DLights, Get2DLightColumns, true),
            new LightingExplorerTab("Reflection Probes", GetReflectionProbes, GetReflectionProbeColumns, true),
            new LightingExplorerTab("Light Probes", GetLightProbes, GetLightProbeColumns, true),
            new LightingExplorerTab("Static Emissives", GetEmissives, GetEmissivesColumns, false),
        };
    }
}

实用的类和方法

下面列出了可用于扩展光照浏览器的类和方法:

ILightingExplorerExtension:

public virtual LightingExplorerTab[] GetContentTabs();
public virtual void OnEnable() {}
public virtual void OnDisable() {}

DefaultLightingExplorerExtension(继承自 ILightingExplorerExtension):

public virtual LightingExplorerTab[] GetContentTabs();
public virtual void OnEnable() {}
public virtual void OnDisable() {}

protected virtual UnityEngine.Object[] GetLights();
protected virtual LightingExplorerTableColumn[] GetLightColumns();

protected virtual UnityEngine.Object[] GetReflectionProbes();
protected virtual LightingExplorerTableColumn[] GetReflectionProbeColumns();

protected virtual UnityEngine.Object[] GetLightProbes();
protected virtual LightingExplorerTableColumn[] GetLightProbeColumns();

protected virtual UnityEngine.Object[] GetEmissives();
protected virtual LightingExplorerTableColumn[] GetEmissivesColumns();

  • 2019–08–13
  • 2018.3 中添加了 Light Explorer 扩展 NewIn20183
光照浏览器窗口
添加环境中的环境光