194 lines
6.1 KiB
C#
194 lines
6.1 KiB
C#
using OpenCvSharp.Flann;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Experimental.GlobalIllumination;
|
|
using UnityEngine.Serialization;
|
|
|
|
[Serializable]
|
|
public class MirrorLibraryLightData
|
|
{
|
|
public List<Light> light;
|
|
|
|
public bool ChangeLightColorToRed;
|
|
public bool ChangeLightColorToGreen;
|
|
|
|
public ChangeLightColour changeLightColourToOff;
|
|
public ChangeLightColour changeLightColourToDefault;
|
|
public ChangeLightColour changeLightColourToRed;
|
|
public ChangeLightColour changeLightColourToGreen;
|
|
}
|
|
public class MirrorLibraryClockwiseLighting : MonoBehaviour
|
|
{
|
|
public List<MirrorLibraryLightData> lightData;
|
|
public List<MirrorLibraryLightData> lightDataMirrored;
|
|
|
|
public float waitTime = 0.3f;
|
|
public int currentLightIndex;
|
|
public int previousLightIndex;
|
|
public bool shouldUpdateClockwise;
|
|
|
|
private Coroutine ClockwiseUpdaterCoroutine;
|
|
|
|
private void Start()
|
|
{
|
|
previousLightIndex = lightData.Count - 1;
|
|
}
|
|
|
|
public void UpdateClockwise()
|
|
{
|
|
foreach (var lightData in lightData)
|
|
{
|
|
foreach (var light in lightData.light)
|
|
{
|
|
light.enabled = false;
|
|
}
|
|
lightData.changeLightColourToOff.ChangeColour();
|
|
}
|
|
foreach (var lightDataMirrored in lightDataMirrored)
|
|
{
|
|
foreach (var light in lightDataMirrored.light)
|
|
{
|
|
light.enabled = false;
|
|
}
|
|
lightDataMirrored.changeLightColourToOff.ChangeColour();
|
|
}
|
|
|
|
shouldUpdateClockwise = true;
|
|
if(ClockwiseUpdaterCoroutine == null)
|
|
{
|
|
ClockwiseUpdaterCoroutine = StartCoroutine(ClockwiseUpdater());
|
|
}
|
|
}
|
|
|
|
public void StopUpdatingClockwise()
|
|
{
|
|
shouldUpdateClockwise = false;
|
|
if (ClockwiseUpdaterCoroutine != null)
|
|
{
|
|
StopCoroutine(ClockwiseUpdaterCoroutine);
|
|
ClockwiseUpdaterCoroutine = null;
|
|
}
|
|
}
|
|
|
|
public void PuzzleSolved()
|
|
{
|
|
StopUpdatingClockwise();
|
|
CorrectSolution();
|
|
}
|
|
|
|
IEnumerator ClockwiseUpdater()
|
|
{
|
|
while (shouldUpdateClockwise)
|
|
{
|
|
UpdateLight(lightData);
|
|
UpdateLight(lightDataMirrored);
|
|
yield return new WaitForSeconds(waitTime);
|
|
UpdateLightIndexes(lightData);
|
|
//UpdateLightIndexes(lightDataMirrored);
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
private void UpdateLight(List<MirrorLibraryLightData> lightData)
|
|
{
|
|
foreach (var light in lightData[currentLightIndex].light)
|
|
{
|
|
light.enabled = true;
|
|
}
|
|
lightData[currentLightIndex].changeLightColourToDefault.ChangeColour();
|
|
|
|
if (lightData[previousLightIndex].ChangeLightColorToGreen == false)
|
|
{
|
|
foreach (var light in lightData[previousLightIndex].light)
|
|
{
|
|
light.enabled = false;
|
|
}
|
|
lightData[previousLightIndex].changeLightColourToOff.ChangeColour();
|
|
}
|
|
|
|
if (lightData[currentLightIndex].ChangeLightColorToGreen)
|
|
{
|
|
if (lightData[currentLightIndex].changeLightColourToGreen!=null)
|
|
lightData[currentLightIndex].changeLightColourToGreen.ChangeColour();
|
|
}
|
|
else if (lightData[currentLightIndex].ChangeLightColorToRed)
|
|
{
|
|
if (lightData[currentLightIndex].changeLightColourToRed != null)
|
|
lightData[currentLightIndex].changeLightColourToRed.ChangeColour();
|
|
}
|
|
else if (lightData[currentLightIndex].ChangeLightColorToGreen == false && lightData[currentLightIndex].ChangeLightColorToRed == false)
|
|
{
|
|
if (lightData[currentLightIndex].changeLightColourToDefault != null)
|
|
lightData[currentLightIndex].changeLightColourToDefault.ChangeColour();
|
|
}
|
|
}
|
|
private void UpdateLightIndexes(List<MirrorLibraryLightData> lightData)
|
|
{
|
|
previousLightIndex = currentLightIndex;
|
|
currentLightIndex += 1;
|
|
if (currentLightIndex >= lightData.Count)
|
|
{
|
|
previousLightIndex = lightData.Count -1;
|
|
currentLightIndex = 0;
|
|
}
|
|
}
|
|
|
|
public void ChangeLightColorToRed(int LightDataIndex)
|
|
{
|
|
lightData[LightDataIndex].ChangeLightColorToRed = true;
|
|
lightData[LightDataIndex].ChangeLightColorToGreen = false;
|
|
lightData[LightDataIndex].changeLightColourToRed.ChangeColour();
|
|
}
|
|
|
|
public void ChangeLightColorToGreen(int LightDataIndex)
|
|
{
|
|
lightData[LightDataIndex].ChangeLightColorToRed = false;
|
|
lightData[LightDataIndex].ChangeLightColorToGreen = true;
|
|
lightData[LightDataIndex].changeLightColourToGreen.ChangeColour();
|
|
foreach (var light in lightData[LightDataIndex].light)
|
|
{
|
|
light.enabled = true;
|
|
}
|
|
}
|
|
|
|
public void ChangeLightColorToRedMirrored(int LightDataIndex)
|
|
{
|
|
lightDataMirrored[LightDataIndex].ChangeLightColorToRed = true;
|
|
lightDataMirrored[LightDataIndex].ChangeLightColorToGreen = false;
|
|
lightDataMirrored[LightDataIndex].changeLightColourToRed.ChangeColour();
|
|
}
|
|
|
|
public void ChangeLightColorToGreenMirrored(int LightDataIndex)
|
|
{
|
|
lightDataMirrored[LightDataIndex].ChangeLightColorToRed = false;
|
|
lightDataMirrored[LightDataIndex].ChangeLightColorToGreen = true;
|
|
lightDataMirrored[LightDataIndex].changeLightColourToGreen.ChangeColour();
|
|
foreach (var light in lightDataMirrored[LightDataIndex].light)
|
|
{
|
|
light.enabled = true;
|
|
}
|
|
}
|
|
|
|
public void CorrectSolution()
|
|
{
|
|
foreach (var lightData in lightData)
|
|
{
|
|
foreach (var light in lightData.light)
|
|
{
|
|
light.enabled = true;
|
|
}
|
|
lightData.changeLightColourToGreen.ChangeColour();
|
|
}
|
|
foreach (var lightDataMirrored in lightDataMirrored)
|
|
{
|
|
foreach (var light in lightDataMirrored.light)
|
|
{
|
|
light.enabled = true;
|
|
}
|
|
lightDataMirrored.changeLightColourToGreen.ChangeColour();
|
|
}
|
|
}
|
|
}
|