Files
modular-vr/Assets/Engine/Runtime/Modules/StepPuzzle.cs

80 lines
2.3 KiB
C#

using System;
using NaughtyAttributes;
using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
namespace EscapeRoomEngine.Engine.Runtime.Modules
{
public abstract class StepPuzzle : PuzzleState
{
[BoxGroup("Step Puzzle")]
[InfoBox("In easy mode, the step puzzle will not reset if a wrong input is made.")]
public bool easyMode;
[BoxGroup("Step Puzzle")] [Min(0)] public int totalSteps;
[BoxGroup("Step Puzzle")] [ProgressBar("Step", "totalSteps", EColor.Orange)]
public int currentStep;
protected override void Start()
{
PuzzleEvent += (_, type) =>
{
switch (type)
{
case PuzzleEventType.Restarted:
currentStep = 0;
break;
case PuzzleEventType.Solved:
currentStep = totalSteps;
break;
case PuzzleEventType.WrongInput:
if (!easyMode)
{
currentStep = 0;
}
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
};
base.Start();
}
protected virtual void CheckStep(int step)
{
if (!Solved)
{
if (step == currentStep)
{
Step();
}
else
{
WrongInput();
}
}
}
#region Debug Buttons
[Button(enabledMode: EButtonEnableMode.Playmode)]
protected void Step()
{
if (!Solved)
{
currentStep++;
if (currentStep >= totalSteps)
{
Solve();
}
else
{
Logger.Log($"{this} step {currentStep}/{totalSteps}", LogType.PuzzleDetail);
}
}
}
#endregion
}
}