relate terminal and ball

This commit is contained in:
2022-11-21 11:41:06 +01:00
parent eeb90ac24c
commit dbcb9c0a24
11 changed files with 55 additions and 76 deletions

View File

@@ -1,58 +1,13 @@
using System;
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Modules;
using NaughtyAttributes;
using UnityEngine;
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
{
[RequireComponent(typeof(Animator))]
public class Ball : PuzzleState
public class Ball : ModuleState
{
private static readonly int LightFlash = Animator.StringToHash("Light Flash");
[BoxGroup("Internal")] [Required] public Emission ringLight;
[BoxGroup("Internal")] [Required] public Ring ring;
private Animator _animator;
private void Awake()
{
_animator = GetComponent<Animator>();
}
private void Start()
{
PuzzleEvent += (_, type) =>
{
switch (type)
{
case PuzzleEventType.Restarted:
ring.Solved = false;
TurnOffRingLight();
break;
case PuzzleEventType.Solved:
ring.Solved = true;
ringLight.color = theme.solvedColor;
TurnOnRingLight();
break;
case PuzzleEventType.WrongInput:
ringLight.color = theme.puzzleColor;
_animator.SetTrigger(LightFlash);
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
};
}
public void TurnOnRingLight()
{
ringLight.active = true;
}
public void TurnOffRingLight()
{
ringLight.active = false;
}
public override void SetModule(Module module) {}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using UnityEngine;
@@ -15,6 +16,7 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
[BoxGroup("Internal")] public List<SymbolButton> symbols;
private Animator _animator;
private Ball _ball;
private void Awake()
{
@@ -28,33 +30,55 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
switch (type)
{
case PuzzleEventType.Restarted:
_ball.ringLight.color = theme.puzzleColor;
terminalLight.color = theme.puzzleColor;
symbols.ForEach(symbol => symbol.Enable());
_ball.ring.Solved = false;
break;
case PuzzleEventType.Solved:
_ball.ringLight.color = theme.solvedColor;
terminalLight.color = theme.solvedColor;
symbols.ForEach(symbol => symbol.Disable());
_ball.ring.Solved = true;
break;
case PuzzleEventType.WrongInput:
terminalLight.color = theme.puzzleColor;
_animator.SetTrigger(LightFlash);
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
};
TurnOnRingLight();
}
public void TurnOnRingLight()
public override void SetModule(Module module)
{
base.SetModule(module);
var firstRelatedModule = Module.relatedModules[0];
if (firstRelatedModule.State is Ball ball)
{
_ball = ball;
}
else
{
throw new EngineException("Terminal was not assigned a related Ball.");
}
TurnOnLights();
}
// required in animation
internal void TurnOnLights()
{
terminalLight.active = true;
_ball.ringLight.active = true;
}
public void TurnOffRingLight()
// required in animation
internal void TurnOffLights()
{
terminalLight.active = false;
_ball.ringLight.active = false;
}
}
}