finish puzzle a logic
This commit is contained in:
@@ -1,13 +1,39 @@
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using NaughtyAttributes;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
public class Ball : ModuleState
|
||||
{
|
||||
[BoxGroup("Internal")] [Required] public Emission ringLight;
|
||||
public EngineTheme theme;
|
||||
[BoxGroup("Internal")] [Required] public Emission statusLight;
|
||||
[BoxGroup("Internal")] [Required] public Ring ring;
|
||||
|
||||
public bool StatusLight
|
||||
{
|
||||
set => statusLight.active = value;
|
||||
}
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => _active;
|
||||
set
|
||||
{
|
||||
_active = value;
|
||||
|
||||
statusLight.color = _active ? theme.puzzleColor : theme.solvedColor;
|
||||
ring.rotating = _active;
|
||||
if (!_active)
|
||||
{
|
||||
ring.crystal.Active = false;
|
||||
ring.symbols.ForEach(symbol => symbol.Active = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _active;
|
||||
|
||||
public override void SetModule(Module module) {}
|
||||
}
|
||||
}
|
||||
@@ -6,26 +6,15 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
public class Ring : MonoBehaviour
|
||||
{
|
||||
public bool rotating = true;
|
||||
public float rotationAngle;
|
||||
[MinMaxSlider(-180, 180)] public Vector2 activeRange;
|
||||
[Required] public Crystal crystal;
|
||||
public List<Symbol> symbols;
|
||||
|
||||
public bool Solved
|
||||
{
|
||||
set
|
||||
{
|
||||
_solved = value;
|
||||
crystal.Active = !_solved;
|
||||
symbols.ForEach(symbol => symbol.Active = !_solved);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _solved;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(!_solved)
|
||||
if(rotating)
|
||||
{
|
||||
transform.localRotation = Quaternion.AngleAxis(rotationAngle, Vector3.forward);
|
||||
|
||||
|
||||
@@ -4,17 +4,20 @@ using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class Terminal : PuzzleState
|
||||
public class Terminal : CyclicStepPuzzle
|
||||
{
|
||||
private static readonly int LightFlash = Animator.StringToHash("Light Flash");
|
||||
|
||||
[BoxGroup("Internal")] [Required] public Emission terminalLight;
|
||||
[BoxGroup("Internal")] public List<SymbolButton> symbols;
|
||||
|
||||
|
||||
private int _activeSymbol, _lastPressedSymbol;
|
||||
private Animator _animator;
|
||||
private Ball _ball;
|
||||
|
||||
@@ -23,23 +26,23 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
_animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
PuzzleEvent += (_, type) =>
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PuzzleEventType.Restarted:
|
||||
_ball.ringLight.color = theme.puzzleColor;
|
||||
_ball.Active = true;
|
||||
terminalLight.color = theme.puzzleColor;
|
||||
symbols.ForEach(symbol => symbol.Enable());
|
||||
_ball.ring.Solved = false;
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
_ball.ringLight.color = theme.solvedColor;
|
||||
_ball.Active = false;
|
||||
terminalLight.color = theme.solvedColor;
|
||||
symbols.ForEach(symbol => symbol.Disable());
|
||||
_ball.ring.Solved = true;
|
||||
break;
|
||||
case PuzzleEventType.WrongInput:
|
||||
_animator.SetTrigger(LightFlash);
|
||||
@@ -48,6 +51,23 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
};
|
||||
|
||||
symbols.ForEach(symbol =>
|
||||
{
|
||||
symbol.ButtonEvent += (_, type) =>
|
||||
{
|
||||
if (type == ButtonEventType.Pressed)
|
||||
{
|
||||
PressedSymbol(symbol.symbolNumber);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
_ball.ring.symbols.ForEach(symbol =>
|
||||
{
|
||||
symbol.SymbolEvent += type =>
|
||||
_activeSymbol = type == SymbolEventType.Activated ? symbol.symbolNumber : -1;
|
||||
});
|
||||
}
|
||||
|
||||
public override void SetModule(Module module)
|
||||
@@ -71,14 +91,39 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
internal void TurnOnLights()
|
||||
{
|
||||
terminalLight.active = true;
|
||||
_ball.ringLight.active = true;
|
||||
_ball.StatusLight = true;
|
||||
}
|
||||
|
||||
// required in animation
|
||||
internal void TurnOffLights()
|
||||
{
|
||||
terminalLight.active = false;
|
||||
_ball.ringLight.active = false;
|
||||
_ball.StatusLight = false;
|
||||
}
|
||||
|
||||
internal void PressedSymbol(int number)
|
||||
{
|
||||
if (!Solved)
|
||||
{
|
||||
Logger.Log($"Pressed symbol {number} on {this}", LogType.PuzzleDetail);
|
||||
|
||||
if (number == _activeSymbol)
|
||||
{
|
||||
CheckStep(number);
|
||||
}
|
||||
else
|
||||
{
|
||||
WrongInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Debug Buttons
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void PressSymbol0() => PressedSymbol(0);
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void PressSymbol1() => PressedSymbol(1);
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void PressSymbol2() => PressedSymbol(2);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user