Version: 6000.3
语言: 中文
光源资源管理器窗口
添加来自环境的环境光

自定义光源浏览器

Light Explorer 扩展允许您创建自己的 Light Explorer 窗口版本。你可以使用它来调整 光源资源管理器(Light Explorer) 窗口的功能,以便它与自定义的可脚本对象一起使用渲染管线(Render Pipeline) 获取场景内容并将其显示在屏幕上的一系列作。Unity 允许您从预构建的渲染管道中进行选择,或编写自己的渲染管道。更多信息
请参阅术语表
(SRP),或使用高清渲染管线的自定义光源

光源资源管理器窗口可让您查看场景场景包含游戏的环境和菜单。将每个唯一的场景文件视为一个独特的关卡。在每个场景中,你放置你的环境、障碍物和装饰品,基本上是将你的游戏设计和构建成碎片。更多信息
请参阅术语表
并编辑其属性。使用此扩展,您可以通过多种方式扩展当前窗口。例如,您可以:

  • 更改选项卡,从简单地更改选项卡名称到添加您自己的自定义选项卡,以显示不同类型的游戏对象Unity 场景中的基本对象,可以表示角色、道具、风景、相机、航路点等。游戏对象的功能由附加到它的组件定义。更多信息
    请参阅术语表
    .如果要显示自己的自定义的属性信息,这非常有用反射探针(Reflection Probes一个渲染组件,可捕获周围环境的各个方向的球形视图,就像摄像机一样。然后,捕获的图像将存储为立方体贴图,可供具有反射材质的对象使用。更多信息
    请参阅术语表
    例如。
  • 更改选项卡上的列,再次从更改名称到添加您自己的自定义列。如果要查看额外的光源属性,添加列非常有用。

扩展光源浏览器

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

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

示例代码

本节中的示例将介绍如何扩展默认的光源资源管理器类,以仅显示光源的 名称(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();
光源资源管理器窗口
添加来自环境的环境光