finish puzzle a logic

This commit is contained in:
2022-11-21 20:38:48 +01:00
parent 3fe201b852
commit 07a448a260
6 changed files with 101 additions and 32 deletions

View File

@@ -24,7 +24,6 @@ MonoBehaviour:
spawnDoor: {fileID: 11400000, guid: 6e937b2e9f774999b5962c4b40947165, type: 2}
exitDoorTypes:
- {fileID: 11400000, guid: 29e2ae36585f4e65966bc9ea2f95ac4a, type: 2}
puzzleCount: {x: 2, y: 4}
puzzleCount: {x: 2, y: 3}
puzzleTypes:
- {fileID: 11400000, guid: 2a6dd6683bdc4db9b200ccfab1dd4bed, type: 2}
- {fileID: 11400000, guid: 3f79d37154e44ca47b54bb43bbe8d9aa, type: 2}

View File

@@ -99,6 +99,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7902f6a7fa0fd844f8ed93e3debd7778, type: 3}
m_Name:
m_EditorClassIdentifier:
rotating: 1
rotationAngle: 0
activeRange: {x: -20, y: 20}
crystal: {fileID: 5479821360340449616}
@@ -216,6 +217,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1e099fd852792c34188dcf102aa895e4, type: 3}
m_Name:
m_EditorClassIdentifier:
symbolNumber: 1
anglePosition: 120
--- !u!1 &3032249595895728242
GameObject:
@@ -327,6 +329,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1e099fd852792c34188dcf102aa895e4, type: 3}
m_Name:
m_EditorClassIdentifier:
symbolNumber: 0
anglePosition: 0
--- !u!1 &3501693287014819891
GameObject:
@@ -646,6 +649,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1e099fd852792c34188dcf102aa895e4, type: 3}
m_Name:
m_EditorClassIdentifier:
symbolNumber: 2
anglePosition: 240
--- !u!1 &3858759582118357347
GameObject:
@@ -927,7 +931,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b9b2d31478f94735a2e19e7c07a27f05, type: 3}
m_Name:
m_EditorClassIdentifier:
ringLight: {fileID: 1320470883464003968}
theme: {fileID: 11400000, guid: 568d9a7d70f3edb4cb6db66a0010f105, type: 2}
statusLight: {fileID: 1320470883464003968}
ring: {fileID: 5086091638728871387}
--- !u!95 &2153737246840746917
Animator:

View File

@@ -28,7 +28,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3400578974218326136}
- {fileID: 143671197139830240}
m_Father: {fileID: 5383329221585827904}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -157,7 +157,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 143671197139830240}
- {fileID: 3400578974218326136}
m_Father: {fileID: 5383329221585827904}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -192,7 +192,7 @@ Transform:
m_LocalScale: {x: 1.5, y: 1.5000001, z: 1.5000001}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1715039903437992233}
m_Father: {fileID: 6522234565953195748}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
--- !u!33 &4858124499749322729
@@ -257,6 +257,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3d6620bee0f14224b11a19808d537cbd, type: 3}
m_Name:
m_EditorClassIdentifier:
symbolNumber: 0
theme: {fileID: 11400000, guid: 568d9a7d70f3edb4cb6db66a0010f105, type: 2}
--- !u!1 &5383329221585827911
GameObject:
@@ -328,6 +329,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
theme: {fileID: 11400000, guid: 568d9a7d70f3edb4cb6db66a0010f105, type: 2}
totalSteps: 3
currentStep: 0
terminalLight: {fileID: 7019057833946340774}
symbols:
- {fileID: 7205539446313206328}
@@ -429,6 +432,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3d6620bee0f14224b11a19808d537cbd, type: 3}
m_Name:
m_EditorClassIdentifier:
symbolNumber: 2
theme: {fileID: 11400000, guid: 568d9a7d70f3edb4cb6db66a0010f105, type: 2}
--- !u!1 &8214146423999858347
GameObject:
@@ -457,11 +461,11 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8214146423999858347}
m_LocalRotation: {x: -0.70710653, y: 5.123641e-14, z: 3.992727e-16, w: 0.70710707}
m_LocalPosition: {x: -0, y: -0, z: 0.0004}
m_LocalPosition: {x: 0, y: 0, z: 0.0004}
m_LocalScale: {x: 1.5, y: 1.5000001, z: 1.5000001}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6522234565953195748}
m_Father: {fileID: 1715039903437992233}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
--- !u!33 &4045135655228650100
@@ -526,6 +530,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3d6620bee0f14224b11a19808d537cbd, type: 3}
m_Name:
m_EditorClassIdentifier:
symbolNumber: 1
theme: {fileID: 11400000, guid: 568d9a7d70f3edb4cb6db66a0010f105, type: 2}
--- !u!1 &8471610280302804497
GameObject:

View File

@@ -1,13 +1,39 @@
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime;
using EscapeRoomEngine.Engine.Runtime.Modules;
using NaughtyAttributes;
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
{
public class Ball : ModuleState
{
[BoxGroup("Internal")] [Required] public Emission ringLight;
public EngineTheme theme;
[BoxGroup("Internal")] [Required] public Emission statusLight;
[BoxGroup("Internal")] [Required] public Ring ring;
public bool StatusLight
{
set => statusLight.active = value;
}
public bool Active
{
get => _active;
set
{
_active = value;
statusLight.color = _active ? theme.puzzleColor : theme.solvedColor;
ring.rotating = _active;
if (!_active)
{
ring.crystal.Active = false;
ring.symbols.ForEach(symbol => symbol.Active = false);
}
}
}
private bool _active;
public override void SetModule(Module module) {}
}
}

View File

@@ -6,26 +6,15 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
{
public class Ring : MonoBehaviour
{
public bool rotating = true;
public float rotationAngle;
[MinMaxSlider(-180, 180)] public Vector2 activeRange;
[Required] public Crystal crystal;
public List<Symbol> symbols;
public bool Solved
{
set
{
_solved = value;
crystal.Active = !_solved;
symbols.ForEach(symbol => symbol.Active = !_solved);
}
}
private bool _solved;
private void Update()
{
if(!_solved)
if(rotating)
{
transform.localRotation = Quaternion.AngleAxis(rotationAngle, Vector3.forward);

View File

@@ -4,17 +4,20 @@ using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
{
[RequireComponent(typeof(Animator))]
public class Terminal : PuzzleState
public class Terminal : CyclicStepPuzzle
{
private static readonly int LightFlash = Animator.StringToHash("Light Flash");
[BoxGroup("Internal")] [Required] public Emission terminalLight;
[BoxGroup("Internal")] public List<SymbolButton> symbols;
private int _activeSymbol, _lastPressedSymbol;
private Animator _animator;
private Ball _ball;
@@ -23,23 +26,23 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
_animator = GetComponent<Animator>();
}
private void Start()
protected override void Start()
{
base.Start();
PuzzleEvent += (_, type) =>
{
switch (type)
{
case PuzzleEventType.Restarted:
_ball.ringLight.color = theme.puzzleColor;
_ball.Active = true;
terminalLight.color = theme.puzzleColor;
symbols.ForEach(symbol => symbol.Enable());
_ball.ring.Solved = false;
break;
case PuzzleEventType.Solved:
_ball.ringLight.color = theme.solvedColor;
_ball.Active = false;
terminalLight.color = theme.solvedColor;
symbols.ForEach(symbol => symbol.Disable());
_ball.ring.Solved = true;
break;
case PuzzleEventType.WrongInput:
_animator.SetTrigger(LightFlash);
@@ -48,6 +51,23 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
};
symbols.ForEach(symbol =>
{
symbol.ButtonEvent += (_, type) =>
{
if (type == ButtonEventType.Pressed)
{
PressedSymbol(symbol.symbolNumber);
}
};
});
_ball.ring.symbols.ForEach(symbol =>
{
symbol.SymbolEvent += type =>
_activeSymbol = type == SymbolEventType.Activated ? symbol.symbolNumber : -1;
});
}
public override void SetModule(Module module)
@@ -71,14 +91,39 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
internal void TurnOnLights()
{
terminalLight.active = true;
_ball.ringLight.active = true;
_ball.StatusLight = true;
}
// required in animation
internal void TurnOffLights()
{
terminalLight.active = false;
_ball.ringLight.active = false;
_ball.StatusLight = false;
}
internal void PressedSymbol(int number)
{
if (!Solved)
{
Logger.Log($"Pressed symbol {number} on {this}", LogType.PuzzleDetail);
if (number == _activeSymbol)
{
CheckStep(number);
}
else
{
WrongInput();
}
}
}
#region Debug Buttons
[Button(enabledMode: EButtonEnableMode.Playmode)] public void PressSymbol0() => PressedSymbol(0);
[Button(enabledMode: EButtonEnableMode.Playmode)] public void PressSymbol1() => PressedSymbol(1);
[Button(enabledMode: EButtonEnableMode.Playmode)] public void PressSymbol2() => PressedSymbol(2);
#endregion
}
}