Files
CartoonRPG/Library/PackageCache/com.unity.visualeffectgraph@2973a8ac1070/Samples~/VFXOutputEventHandlers/Runtime/VFXOutputEventPrefabAttributeLightHandler.cs
Caleb Sandford deQuincey 02c4b5ab66 Adding in new packages
2025-06-05 22:59:18 +01:00

38 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if VFX_OUTPUTEVENT_HDRP_10_0_0_OR_NEWER
using UnityEngine.Rendering.HighDefinition;
#endif
namespace UnityEngine.VFX.Utility
{
[RequireComponent(typeof(Light))]
#if VFX_OUTPUTEVENT_HDRP_10_0_0_OR_NEWER
[RequireComponent(typeof(HDAdditionalLightData))]
#endif
class VFXOutputEventPrefabAttributeLightHandler : VFXOutputEventPrefabAttributeAbstractHandler
{
public float brightnessScale = 1.0f;
static readonly int k_Color = Shader.PropertyToID("color");
public override void OnVFXEventAttribute(VFXEventAttribute eventAttribute, VisualEffect visualEffect)
{
var color = eventAttribute.GetVector3(k_Color);
var intensity = color.magnitude;
var c = new Color(color.x, color.y, color.z) / intensity;
intensity *= brightnessScale;
#if VFX_OUTPUTEVENT_HDRP_10_0_0_OR_NEWER
var hdlight = GetComponent<HDAdditionalLightData>();
hdlight.SetColor(c);
hdlight.SetIntensity(intensity);
#else
var light = GetComponent<Light>();
light.color = c;
light.intensity = intensity;
#endif
}
}
}