add StepPuzzle and CyclicStepPuzzle
This commit is contained in:
35
Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs
Normal file
35
Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using NaughtyAttributes;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||||
|
{
|
||||||
|
public class CyclicStepPuzzle : StepPuzzle
|
||||||
|
{
|
||||||
|
[BoxGroup("Step Puzzle")] [Min(0)] public int cycleStep;
|
||||||
|
|
||||||
|
protected override void CheckStep(int step)
|
||||||
|
{
|
||||||
|
if (!Solved)
|
||||||
|
{
|
||||||
|
if (currentStep == 0)
|
||||||
|
{
|
||||||
|
// begin at any step
|
||||||
|
cycleStep = NextInCycle(step);
|
||||||
|
Step();
|
||||||
|
}
|
||||||
|
else if (step == cycleStep)
|
||||||
|
{
|
||||||
|
// next step in cycle
|
||||||
|
cycleStep = NextInCycle(cycleStep);
|
||||||
|
Step();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WrongInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int NextInCycle(int step) => (step + 1) % totalSteps;
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs.meta
Normal file
3
Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4551ae21288a497dac75931c56f86409
|
||||||
|
timeCreated: 1669057382
|
||||||
@@ -5,5 +5,10 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
|||||||
public abstract class ModuleState : MonoBehaviour
|
public abstract class ModuleState : MonoBehaviour
|
||||||
{
|
{
|
||||||
public abstract void SetModule(Module module);
|
public abstract void SetModule(Module module);
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
78
Assets/Engine/Runtime/Modules/StepPuzzle.cs
Normal file
78
Assets/Engine/Runtime/Modules/StepPuzzle.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
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 virtual 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Engine/Runtime/Modules/StepPuzzle.cs.meta
Normal file
3
Assets/Engine/Runtime/Modules/StepPuzzle.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5095ea3f77724269857f7275fbf7159b
|
||||||
|
timeCreated: 1669052447
|
||||||
Reference in New Issue
Block a user