DynamicColor, Crystal prefab, Finish Puzzle B
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using JetBrains.Annotations;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
@@ -28,8 +29,7 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
public GameObject environment;
|
||||
|
||||
[BoxGroup("Theme")]
|
||||
[ColorUsage(false, true)]
|
||||
public Color puzzleColor, solvedColor, activeColor;
|
||||
public DynamicColor puzzleColor, solvedColor, activeColor;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -14,6 +14,13 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
Orientation.North, Orientation.East, Orientation.South, Orientation.West
|
||||
});
|
||||
|
||||
public static Orientation FromAngle(int angle) => (Orientation)angle;
|
||||
|
||||
public static float Angle(this Orientation orientation) => (float)orientation;
|
||||
|
||||
public static int AngleInt(this Orientation orientation) => (int)orientation;
|
||||
|
||||
public static Orientation Rotated(this Orientation orientation, int quarterRotations) =>
|
||||
orientation + quarterRotations * 90;
|
||||
}
|
||||
}
|
||||
14
Assets/Engine/Runtime/Utilities/DynamicColor.cs
Normal file
14
Assets/Engine/Runtime/Utilities/DynamicColor.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Utilities
|
||||
{
|
||||
[Serializable]
|
||||
public struct DynamicColor
|
||||
{
|
||||
[ColorUsage(true, true)]
|
||||
public Color hdr;
|
||||
[ColorUsage(true, false)]
|
||||
public Color ldr;
|
||||
}
|
||||
}
|
||||
3
Assets/Engine/Runtime/Utilities/DynamicColor.cs.meta
Normal file
3
Assets/Engine/Runtime/Utilities/DynamicColor.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be15a05372394378a7b6a28e1dd89a1d
|
||||
timeCreated: 1669760387
|
||||
Reference in New Issue
Block a user