通过 Light Explorer 扩展,可以创建自定义版本的 Light Explorer 窗口。可以将这种扩展用于调整 Light Explorer 窗口的功能,以便处理可编程渲染管线 (SRP) 或者高清渲染管线的自定义光源。
在 Light Explorer 窗口中,可以看到场景中的所有光源并可编辑它们的属性。使用此扩展,可以通过多种方式扩展当前窗口。例如,可以执行以下操作:
要扩展 Light Explorer,可以继承自:
ILightingExplorerExtension
接口,然后覆盖 GetContentTabs
方法。DefaultLightingExplorerExtension
类(继承自 ILightingExplorerExtension
)。此类提供窗口中已经存在的所有内容。如果只希望覆盖选项卡的数量、每个选项卡的标题或要显示的光源,请使用此选项。要了解如何以这种方式扩展 Light Explorer,请参阅下面的示例。本节中的示例展示了如何扩展默认的 Light Explorer 类以仅显示光源的名称 (Name) 列,以及如何更改选项卡的数量。在您自己的实现中,可以根据需要覆盖任意数量的方法。
以下示例显示了光源的名称列:
using UnityEngine;
using UnityEditor;
[LightingExplorerExtensionAttribute(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 UnityEditor;
[LightingExplorerExtensionAttribute(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),
};
}
}
下面列出了可用于扩展 Light Explorer 的类和方法:
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();
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.