DynamicColor, Crystal prefab, Finish Puzzle B

This commit is contained in:
2022-11-28 23:31:00 +01:00
parent 60e390a993
commit 450c16c94f
63 changed files with 2915 additions and 361 deletions

View File

@@ -11,7 +11,7 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
[BoxGroup("State Puzzle")]
[SerializeField]
protected List<int> states, solution;
[BoxGroup("Step Puzzle")]
[BoxGroup("State Puzzle")]
[SerializeField]
[ValidateInput("CorrectStateCount", "States count must be equal to the number of states and the length of the solution.")]
[Min(0)]
@@ -22,22 +22,28 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
private List<int> _initialStates;
private void Awake()
protected virtual void Awake()
{
_initialStates = states;
_initialStates = new List<int>(states);
}
protected virtual void Start()
protected override void Start()
{
PuzzleEvent += (_, type) =>
{
switch (type)
{
case PuzzleEventType.Restarted:
states = _initialStates;
for (var i = 0; i < stateCount; i++)
{
SetState(i, _initialStates[i], false);
}
break;
case PuzzleEventType.Solved:
states = solution;
for (var i = 0; i < stateCount; i++)
{
SetState(i, solution[i], false);
}
break;
case PuzzleEventType.WrongInput:
break;
@@ -45,31 +51,28 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
};
base.Start();
}
public void SetState(int index, int value)
protected virtual void SetState(int index, int value, bool checkSolution)
{
if (index >= 0 && index < stateCount)
{
states[index] = value;
StatesUpdate();
}
}
protected virtual void StatesUpdate()
{
correctStates = 0;
for (var i = 0; i < stateCount; i++)
{
if (states[i] == solution[i])
correctStates = 0;
for (var i = 0; i < stateCount; i++)
{
correctStates++;
if (states[i] == solution[i])
{
correctStates++;
}
}
}
if (correctStates == stateCount && correctStates > 0)
{
Solve();
if (checkSolution && correctStates == stateCount && correctStates > 0)
{
Solve();
}
}
}