using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
namespace UnityEditor.Rendering.HighDefinition
{
///
/// Utility class for lights.
///
public class HDLightUtils
{
///
/// Get IES Object for Point, Spot or Rectangular light.
///
/// The light.
/// The IES Profile Object assigned on the light.
public static IESObject GetIESProfile(Light light)
{
if (!light.TryGetComponent(out var additionalData))
return null;
Texture texture = null;
var type = additionalData.legacyLight.type;
if (type == LightType.Point)
texture = additionalData.IESPoint;
else if (type.IsSpot() || type == LightType.Rectangle)
texture = additionalData.IESSpot;
if (texture == null)
return null;
string path = AssetDatabase.GetAssetPath(texture);
return AssetDatabase.LoadAssetAtPath(path);
}
///
/// Set IES Object for Point, Spot or Rectangular light.
///
/// The light to modify.
/// The IES profile to set.
public static void SetIESProfile(Light light, IESObject profile)
{
if (!light.TryGetComponent(out var additionalData))
return;
string guid;
long localID;
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(profile, out guid, out localID);
string path = AssetDatabase.GUIDToAssetPath(guid);
UnityEngine.Object[] textures = AssetDatabase.LoadAllAssetRepresentationsAtPath(path);
foreach (var subAsset in textures)
{
if (AssetDatabase.IsSubAsset(subAsset) && subAsset.name.EndsWith("-Cube-IES"))
additionalData.IESPoint = subAsset as Texture;
else if (AssetDatabase.IsSubAsset(subAsset) && subAsset.name.EndsWith("-2D-IES"))
additionalData.IESSpot = subAsset as Texture;
}
}
}
}