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

@@ -1,6 +1,7 @@
using System;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
@@ -27,6 +28,7 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
public delegate void PuzzleEventHandler(PuzzleModule source, PuzzleEventType e);
[SelectionBase]
public class PuzzleState : ModuleState
{
public event PuzzleEventHandler PuzzleEvent;
@@ -48,6 +50,11 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
private bool _solved;
protected virtual void Start()
{
OnPuzzleEvent(PuzzleEventType.Restarted);
}
private void OnPuzzleEvent(PuzzleEventType type)
{
Logger.Log(type.Description(Module), LogType.PuzzleFlow);

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();
}
}
}

View File

@@ -15,7 +15,7 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
[BoxGroup("Step Puzzle")] [ProgressBar("Step", "totalSteps", EColor.Orange)]
public int currentStep;
protected virtual void Start()
protected override void Start()
{
PuzzleEvent += (_, type) =>
{
@@ -37,6 +37,8 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
};
base.Start();
}
protected virtual void CheckStep(int step)