PlaceWithRelatedModule requirement, finish Puzzle D
This commit is contained in:
@@ -1,30 +1,98 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Desert.Runtime.Dispenser;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime
|
||||
{
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class Hoop : MonoBehaviour
|
||||
public class Hoop : StatePuzzle
|
||||
{
|
||||
public float updateDelay;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private List<Emission> rings;
|
||||
|
||||
public bool Solved
|
||||
|
||||
private readonly HashSet<GameObject> _orbs = new();
|
||||
private Dispenser.Dispenser _dispenser;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
set
|
||||
base.Start();
|
||||
|
||||
PuzzleEvent += (_, type) =>
|
||||
{
|
||||
if (value)
|
||||
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
|
||||
switch (type)
|
||||
{
|
||||
rings.ForEach(ring => ring.color = );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
case PuzzleEventType.Restarted:
|
||||
var color = Engine.Runtime.Engine.DefaultEngine.theme.puzzleColor;
|
||||
rings.ForEach(ring => ring.color = color.hdr);
|
||||
_dispenser.Reset();
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
color = Engine.Runtime.Engine.DefaultEngine.theme.solvedColor;
|
||||
rings.ForEach(ring => ring.color = color.hdr);
|
||||
_dispenser.Solve();
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void SetState(int index, int value, bool checkSolution)
|
||||
{
|
||||
base.SetState(index, value, checkSolution);
|
||||
|
||||
for (var i = 0; i < rings.Count; i++)
|
||||
{
|
||||
rings[i].active = i < value;
|
||||
}
|
||||
}
|
||||
|
||||
private int _orbCount;
|
||||
private IEnumerator SetOrbCount()
|
||||
{
|
||||
if (!Solved)
|
||||
{
|
||||
yield return new WaitForSeconds(updateDelay);
|
||||
SetState(0, _orbs.Count, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
var orb = other.GetComponent<DispenserOrb>();
|
||||
if (orb)
|
||||
{
|
||||
_orbs.Add(orb.gameObject);
|
||||
StartCoroutine(SetOrbCount());
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
var orb = other.GetComponent<DispenserOrb>();
|
||||
if (orb)
|
||||
{
|
||||
_orbs.Remove(orb.gameObject);
|
||||
StartCoroutine(SetOrbCount());
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetModule(Module module)
|
||||
{
|
||||
base.SetModule(module);
|
||||
|
||||
var firstRelatedModule = Module.relatedModules[0];
|
||||
if (firstRelatedModule.State is Dispenser.Dispenser dispenser)
|
||||
{
|
||||
_dispenser = dispenser;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new EngineException("Hoop was not assigned a related Dispenser.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_C
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new EngineException("Terminal was not assigned a related Ball.");
|
||||
throw new EngineException("Holes were not assigned a related Dispenser.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user