using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering;
using UnityEditor;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
using UnityEditor.Experimental.AssetImporters;
#endif
namespace UnityEditor.Rendering.HighDefinition
{
///
/// Class to describe the HDRP specific function
///
[InitializeOnLoad]
public static class HDIESImporter
{
///
/// Constructor of HD IES Importer
///
/// The title of the Preview
static HDIESImporter()
{
UnityEditor.Rendering.IESImporter.createRenderPipelinePrefabLight += CreateRenderPipelinePrefabLight;
}
///
/// Describe how to create an Prefab for the current SRP, have to be reimplemented for each SRP.
///
/// Context used from the asset importer
/// Filename of the current IES file
/// True if uses the internal Intensity from the file
/// The string of the units described by the intensity
/// Intensity
/// Light used for the prefab
/// Texture used for the prefab
static public void CreateRenderPipelinePrefabLight(AssetImportContext ctx, string iesFileName, bool useIESMaximumIntensity, string iesMaximumIntensityUnit, float iesMaximumIntensity, Light light, Texture ies)
{
HDLightTypeAndShape hdLightTypeAndShape = (light.type == LightType.Point) ? HDLightTypeAndShape.Point : HDLightTypeAndShape.ConeSpot;
HDAdditionalLightData hdLight = GameObjectExtension.AddHDLight(light.gameObject, hdLightTypeAndShape);
if (useIESMaximumIntensity)
{
LightUnit lightUnit = (iesMaximumIntensityUnit == "Lumens") ? LightUnit.Lumen : LightUnit.Candela;
hdLight.SetIntensity(iesMaximumIntensity, lightUnit);
if (light.type == LightType.Point)
hdLight.IESPoint = ies;
else
hdLight.IESSpot = ies;
}
// The light object will be automatically converted into a prefab.
ctx.AddObjectToAsset(iesFileName + "-HDRP", light.gameObject);
}
}
}