91 lines
5.1 KiB
C#
91 lines
5.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UnityEngine.Rendering.Universal
|
|
{
|
|
/// <summary>
|
|
/// Class <c>ShadowShape2DProvider</c> has methods called by a <c>ShadowCaster2D</c> to determine if it should be listed as a Casting Option, and to provide geometry if it is the active <c>ShadowShape2DProvider</c>
|
|
/// </summary>
|
|
[Serializable]
|
|
public abstract class ShadowShape2DProvider : Provider2D
|
|
{
|
|
/// <summary>
|
|
/// Gets the name to be listed in the <c>ShadowCaster2D</c> Casting Option drop down.
|
|
/// </summary>
|
|
/// <param name="componentName">The name of component associated with the provider.</param>
|
|
/// <returns>The string to be listed in the <c>ShadowCaster2D</c> Casting Option drop down.</returns>
|
|
public virtual GUIContent ProviderName(string componentName) { return new GUIContent(componentName, "Implemented by " + this.GetType().Name); }
|
|
|
|
|
|
/// <summary>
|
|
/// Called for the active <c>ShadowShape2DProvider</c> when the <c>ShadowCaster2D</c> becomes enabled
|
|
/// </summary>
|
|
/// <param name="sourceComponent">The component associated with the provider</param>
|
|
/// <param name="persistantShadowShape">An instance of <c>ShadowShape2D</c> that is used by the <c>ShadowCaster2D</c></param>
|
|
public virtual void Enabled(Component sourceComponent, ShadowShape2D persistantShadowShape) {}
|
|
|
|
/// <summary>
|
|
/// Called for the active <c>ShadowShape2DProvider</c> when the <c>ShadowCaster2D</c> becomes disabled
|
|
/// </summary>
|
|
/// <param name="sourceComponent">The component associated with the provider</param>
|
|
/// <param name="persistantShadowShape">An instance of <c>ShadowShape2D</c> that is used by the <c>ShadowCaster2D</c></param>
|
|
public virtual void Disabled(Component sourceComponent, ShadowShape2D persistantShadowShape) {}
|
|
|
|
/// <summary>
|
|
/// Called when the <c>ShadowShape2DProvider</c> is selected as the active Casting Option.
|
|
/// </summary>
|
|
/// <param name="sourceComponent">The component associated with the provider</param>
|
|
/// <param name="persistantShadowShape">An instance of <c>ShadowShape2D</c> that is used by the <c>ShadowCaster2D</c></param>
|
|
public virtual void OnInitialized(Component sourceComponent, ShadowShape2D persistantShadowShape) { }
|
|
|
|
|
|
[Obsolete("Use latest OnBeforeRender")]
|
|
public virtual void OnBeforeRender(Component sourceComponent, Bounds worldCullingBounds, ShadowShape2D persistantShadowShape) { }
|
|
|
|
/// <summary>
|
|
/// Called before 2D lighting is rendered each frame
|
|
/// </summary>
|
|
/// <param name="camera">The camera being rendered</param>
|
|
/// <param name="sourceComponent">The component associated with the provider</param>
|
|
/// <param name="worldCullingBounds">The bounds enclosing the region of the view frustum and all visible lights</param>
|
|
/// <param name="persistantShadowShape">An instance of <c>ShadowShape2D</c> that is used by the <c>ShadowCaster2D</c></param>
|
|
public virtual void OnBeforeRender(Camera camera, Component sourceComponent, Bounds worldCullingBounds, ShadowShape2D persistantShadowShape) { }
|
|
|
|
/// <summary>
|
|
/// Called for each component on a <c>ShadowCaster2D's</c> <c>GameObject</c>. Returns true if the provided component is the data source of the <c>ShadowShapeProvider</c>.
|
|
/// </summary>
|
|
/// <param name="sourceComponent">The component to test as a source</param>
|
|
/// <returns>Returns true if sourceComponent is the data source of the <c>ShadowShapeProvider</c>.</returns>
|
|
public abstract bool IsRequiredComponentData(Component sourceComponent);
|
|
|
|
|
|
internal override GUIContent Internal_ProviderName(string componentName) { return ProviderName(componentName); }
|
|
internal override bool Internal_IsRequiredComponentData(Component sourceComponent) { return IsRequiredComponentData(sourceComponent); }
|
|
|
|
// Cached stable identifier hash for this provider's concrete type. Computed lazily on
|
|
// first access and cached for the lifetime of the instance, so per-frame change detection
|
|
// does not pay the string/CRC cost. Uses assembly name + full type name so two providers
|
|
// sharing a class name in different assemblies do not collide, and excludes assembly
|
|
// version so version bumps do not invalidate the hash.
|
|
[NonSerialized] int m_TypeIdentifierHash;
|
|
|
|
internal int TypeIdentifierHash
|
|
{
|
|
get
|
|
{
|
|
if (m_TypeIdentifierHash == 0)
|
|
{
|
|
Type type = GetType();
|
|
string qualified = type.Assembly.GetName().Name + "::" + type.FullName;
|
|
int hash = unchecked((int)URP2D_Crc32.Compute(qualified));
|
|
// Reserve 0 as "uncomputed" sentinel.
|
|
m_TypeIdentifierHash = hash == 0 ? 1 : hash;
|
|
}
|
|
return m_TypeIdentifierHash;
|
|
}
|
|
}
|
|
}
|
|
}
|