Files
HauntedBloodlines/Assets/Scripts/Lights/LightInteractableData.cs
2025-05-29 22:31:40 +03:00

86 lines
3.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightInteractableData : MonoBehaviour
{
public List<Renderer> lightRenderers;
public List<Material> lightMaterials;
public List<Color> emissionColors;
public List<float> emissiveExposureWeight;
public List<bool> isEmissiveMaterial;
private void Awake()
{
foreach (var _lightRenderers in lightRenderers)
{
foreach (var material in _lightRenderers.materials)
{
Color currentEmissiveColor = material.GetColor("_EmissiveColor");
// Check if the emissive color is larger than (0, 0, 0, 255)
if (currentEmissiveColor.r > 0 && currentEmissiveColor.g > 0 && currentEmissiveColor.b > 0 && currentEmissiveColor.a > 0)
{
emissionColors.Add(currentEmissiveColor);
emissiveExposureWeight.Add(1f);
isEmissiveMaterial.Add(true);
}
else
{
emissionColors.Add(currentEmissiveColor);
emissiveExposureWeight.Add(-100f);
isEmissiveMaterial.Add(false);
}
}
}
}
public void UpdateLightEmissionAndExposureWeightOnRuntime()
{
foreach (var lightRenderer in lightRenderers)
{
foreach (var material in lightRenderer.materials)
{
for (int i = 0; i < emissionColors.Count; i++)
{
Color currentEmissiveColor = material.GetColor("_EmissiveColor");
if (currentEmissiveColor.r > 0 && currentEmissiveColor.g > 0 && currentEmissiveColor.b > 0 && currentEmissiveColor.a > 0)
{
// Debugging print statement to verify the assignment
print($"Assigning emissive color to emissionColors[{i}]");
emissionColors[i] = currentEmissiveColor;
print("Updated Light emission and exposure weight on runtime!");
}
else
{
// Debugging print statement to verify the condition is met
print("Skipped due to zero emissive color.");
i++;
//continue;
}
}
}
}
}
public void UpdateLightEmissionAndExposureWeightOnRuntimeBasedOnIndices(int lampRendererMaterialIndices)
{
foreach (Renderer lightRenderer in lightRenderers)
{
Material[] materials = lightRenderer.materials;
Color currentEmissiveColor = materials[lampRendererMaterialIndices].GetColor("_EmissiveColor");
// Debugging print statement to verify the assignment
print($"Assigning emissive color to emissionColors[{lampRendererMaterialIndices}]");
emissionColors[lampRendererMaterialIndices] = currentEmissiveColor;
print("Updated Light emission and exposure weight on runtime!");
}
}
}