using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Rendering.Universal
{
///
/// Class ShadowShape2DProvider has methods called by a ShadowCaster2D to determine if it should be listed as a Casting Option, and to provide geometry if it is the active ShadowShape2DProvider
///
[Serializable]
public abstract class ShadowShape2DProvider : Provider2D
{
///
/// Gets the name to be listed in the ShadowCaster2D Casting Option drop down.
///
/// The name of component associated with the provider.
/// The string to be listed in the ShadowCaster2D Casting Option drop down.
public virtual GUIContent ProviderName(string componentName) { return new GUIContent(componentName, "Implemented by " + this.GetType().Name); }
///
/// Called for the active ShadowShape2DProvider when the ShadowCaster2D becomes enabled
///
/// The component associated with the provider
/// An instance of ShadowShape2D that is used by the ShadowCaster2D
public virtual void Enabled(Component sourceComponent, ShadowShape2D persistantShadowShape) {}
///
/// Called for the active ShadowShape2DProvider when the ShadowCaster2D becomes disabled
///
/// The component associated with the provider
/// An instance of ShadowShape2D that is used by the ShadowCaster2D
public virtual void Disabled(Component sourceComponent, ShadowShape2D persistantShadowShape) {}
///
/// Called when the ShadowShape2DProvider is selected as the active Casting Option.
///
/// The component associated with the provider
/// An instance of ShadowShape2D that is used by the ShadowCaster2D
public virtual void OnInitialized(Component sourceComponent, ShadowShape2D persistantShadowShape) { }
[Obsolete("Use latest OnBeforeRender")]
public virtual void OnBeforeRender(Component sourceComponent, Bounds worldCullingBounds, ShadowShape2D persistantShadowShape) { }
///
/// Called before 2D lighting is rendered each frame
///
/// The camera being rendered
/// The component associated with the provider
/// The bounds enclosing the region of the view frustum and all visible lights
/// An instance of ShadowShape2D that is used by the ShadowCaster2D
public virtual void OnBeforeRender(Camera camera, Component sourceComponent, Bounds worldCullingBounds, ShadowShape2D persistantShadowShape) { }
///
/// Called for each component on a ShadowCaster2D's GameObject. Returns true if the provided component is the data source of the ShadowShapeProvider.
///
/// The component to test as a source
/// Returns true if sourceComponent is the data source of the ShadowShapeProvider.
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;
}
}
}
}