get theme colours from engine instead of storing reference to theme in module
This commit is contained in:
8
Assets/Desert/Assets/Modules/Puzzle A2.meta
Normal file
8
Assets/Desert/Assets/Modules/Puzzle A2.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 392e042234faea84aab057c8329c8589
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 392e042234faea84aab057c8329c8589
|
||||
guid: 0558edff2d866f6428c81f676abdeab2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
using EscapeRoomEngine.Engine.Runtime;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
public class Ball : ModuleState
|
||||
{
|
||||
public EngineTheme theme;
|
||||
[BoxGroup("Internal")] [Required] public Emission statusLight;
|
||||
[BoxGroup("Internal")] [Required] public Ring ring;
|
||||
|
||||
private Color _puzzleColor, _solvedColor;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_puzzleColor = Engine.Runtime.Engine.DefaultEngine.theme.puzzleColor;
|
||||
_solvedColor = Engine.Runtime.Engine.DefaultEngine.theme.solvedColor;
|
||||
}
|
||||
|
||||
public bool StatusLight
|
||||
{
|
||||
set => statusLight.active = value;
|
||||
@@ -22,7 +29,7 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
_active = value;
|
||||
|
||||
statusLight.color = _active ? theme.puzzleColor : theme.solvedColor;
|
||||
statusLight.color = _active ? _puzzleColor : _solvedColor;
|
||||
ring.rotating = _active;
|
||||
if (!_active)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using EscapeRoomEngine.Engine.Runtime;
|
||||
using NaughtyAttributes;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
@@ -10,14 +9,17 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
private static readonly int Color = Shader.PropertyToID("_Color");
|
||||
|
||||
public int symbolNumber;
|
||||
public EngineTheme theme;
|
||||
[BoxGroup("Internal")] [Required] public MeshRenderer holoRenderer;
|
||||
|
||||
private Material _material;
|
||||
private Color _puzzleColor, _solvedColor, _activeColor;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_material = holoRenderer.material;
|
||||
_puzzleColor = Engine.Runtime.Engine.DefaultEngine.theme.puzzleColor;
|
||||
_solvedColor = Engine.Runtime.Engine.DefaultEngine.theme.solvedColor;
|
||||
_activeColor = Engine.Runtime.Engine.DefaultEngine.theme.activeColor;
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
@@ -26,13 +28,13 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
|
||||
ButtonEvent += (_, _) =>
|
||||
{
|
||||
var color = theme.puzzleColor;
|
||||
var color = _puzzleColor;
|
||||
if (!Active)
|
||||
{
|
||||
color = theme.solvedColor;
|
||||
color = _solvedColor;
|
||||
} else if (Pressed)
|
||||
{
|
||||
color = theme.activeColor;
|
||||
color = _activeColor;
|
||||
}
|
||||
|
||||
_material.SetColor(FresnelColor, color);
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
private IOption<Symbol> _activeSymbol;
|
||||
private Animator _animator;
|
||||
private Ball _ball;
|
||||
private Color _puzzleColor, _solvedColor;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -34,6 +35,9 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
List<SymbolButton> symbolInstances = new(symbols.Count);
|
||||
symbolInstances.AddRange(symbols.Select((t, i) => Instantiate(t, symbolSlots[i], false)));
|
||||
symbols = symbolInstances;
|
||||
|
||||
_puzzleColor = Engine.Runtime.Engine.DefaultEngine.theme.puzzleColor;
|
||||
_solvedColor = Engine.Runtime.Engine.DefaultEngine.theme.solvedColor;
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
@@ -46,12 +50,12 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
case PuzzleEventType.Restarted:
|
||||
_ball.Active = true;
|
||||
terminalLight.color = theme.puzzleColor;
|
||||
terminalLight.color = _puzzleColor;
|
||||
symbols.ForEach(symbol => symbol.Enable());
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
_ball.Active = false;
|
||||
terminalLight.color = theme.solvedColor;
|
||||
terminalLight.color = _solvedColor;
|
||||
symbols.ForEach(symbol => symbol.Disable());
|
||||
break;
|
||||
case PuzzleEventType.WrongInput:
|
||||
|
||||
3
Assets/Desert/Runtime/Puzzle B.meta
Normal file
3
Assets/Desert/Runtime/Puzzle B.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d97e612b38c148c1a988eefa9af29b75
|
||||
timeCreated: 1669687251
|
||||
27
Assets/Desert/Runtime/Puzzle B/PuzzleB.cs
Normal file
27
Assets/Desert/Runtime/Puzzle B/PuzzleB.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using JetBrains.Annotations;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_B
|
||||
{
|
||||
public class PuzzleB : StatePuzzle
|
||||
{
|
||||
[ValidateInput("CorrectRotatorCount")]
|
||||
public List<Transform> rotators;
|
||||
|
||||
protected override void StatesUpdate()
|
||||
{
|
||||
base.StatesUpdate();
|
||||
|
||||
for (var i = 0; i < stateCount; i++)
|
||||
{
|
||||
rotators[i].localRotation = Quaternion.AngleAxis(states[i], Vector3.up);
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private bool CorrectRotatorCount(List<Transform> list) => list != null && list.Count == stateCount;
|
||||
}
|
||||
}
|
||||
3
Assets/Desert/Runtime/Puzzle B/PuzzleB.cs.meta
Normal file
3
Assets/Desert/Runtime/Puzzle B/PuzzleB.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b80d4bcd2f6465189d94b993e13a034
|
||||
timeCreated: 1669688216
|
||||
@@ -30,7 +30,6 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
public class PuzzleState : ModuleState
|
||||
{
|
||||
public event PuzzleEventHandler PuzzleEvent;
|
||||
public EngineTheme theme;
|
||||
|
||||
protected PuzzleModule Module { get; private set; }
|
||||
public bool Solved
|
||||
|
||||
81
Assets/Engine/Runtime/Modules/StatePuzzle.cs
Normal file
81
Assets/Engine/Runtime/Modules/StatePuzzle.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
{
|
||||
public class StatePuzzle : PuzzleState
|
||||
{
|
||||
[BoxGroup("State Puzzle")]
|
||||
[SerializeField]
|
||||
protected List<int> states, solution;
|
||||
[BoxGroup("Step Puzzle")]
|
||||
[SerializeField]
|
||||
[ValidateInput("CorrectStateCount", "States count must be equal to the number of states and the length of the solution.")]
|
||||
[Min(0)]
|
||||
protected int stateCount;
|
||||
[BoxGroup("State Puzzle")]
|
||||
[ProgressBar("Correct States", "stateCount", EColor.Orange)]
|
||||
public int correctStates;
|
||||
|
||||
private List<int> _initialStates;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_initialStates = states;
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
PuzzleEvent += (_, type) =>
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PuzzleEventType.Restarted:
|
||||
states = _initialStates;
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
states = solution;
|
||||
break;
|
||||
case PuzzleEventType.WrongInput:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void SetState(int index, int value)
|
||||
{
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
if (correctStates == stateCount && correctStates > 0)
|
||||
{
|
||||
Solve();
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private bool CorrectStateCount(int count) =>
|
||||
states != null && count == states.Count &&
|
||||
solution != null && count == solution.Count;
|
||||
}
|
||||
}
|
||||
3
Assets/Engine/Runtime/Modules/StatePuzzle.cs.meta
Normal file
3
Assets/Engine/Runtime/Modules/StatePuzzle.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 713782041b1d40a28cfe199081a4a009
|
||||
timeCreated: 1669687388
|
||||
Reference in New Issue
Block a user