2022-06-07 02:07:08 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class LightManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
public List<GameObject> Lights = new List<GameObject>();
|
2022-07-26 15:13:45 +02:00
|
|
|
public List<Material> Materials = new List<Material>();
|
2022-06-07 02:07:08 +02:00
|
|
|
public float FadeDuration = 0.5f;
|
|
|
|
private IEnumerator[] coroutines = new IEnumerator[240];
|
2022-07-26 15:13:45 +02:00
|
|
|
|
2022-06-07 02:07:08 +02:00
|
|
|
private void Start()
|
|
|
|
{
|
2022-07-26 15:13:45 +02:00
|
|
|
for (int i = 0; i < Lights.Count; i++)
|
|
|
|
{
|
|
|
|
Materials[i] = Lights[i].GetComponent<Renderer>().material;
|
|
|
|
}
|
2022-06-07 02:07:08 +02:00
|
|
|
}
|
|
|
|
public void UpdateLight(int Area, bool State)
|
|
|
|
{
|
|
|
|
Area -= 1;
|
2022-07-26 15:13:45 +02:00
|
|
|
|
2022-06-07 02:07:08 +02:00
|
|
|
if (State)
|
|
|
|
{
|
2022-07-26 15:13:45 +02:00
|
|
|
Materials[Area].SetColor("_EmissionColor", new Color(1f, 1f, 1f, 1f));
|
2022-06-07 02:07:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (coroutines[Area] != null)
|
|
|
|
StopCoroutine(coroutines[Area]);
|
2022-07-26 15:13:45 +02:00
|
|
|
coroutines[Area] = FadeOut(Area, Materials[Area]);
|
2022-06-07 02:07:08 +02:00
|
|
|
StartCoroutine(coroutines[Area]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public IEnumerator FadeOut(int Area, Material mat)
|
|
|
|
{
|
|
|
|
for (float time = 0f; time < FadeDuration; time += Time.deltaTime)
|
|
|
|
{
|
|
|
|
float p = 1 - time / FadeDuration;
|
|
|
|
mat.SetColor("_EmissionColor", new Color(p, p, p, 1f));
|
|
|
|
yield return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|