DynamicColor, Crystal prefab, Finish Puzzle B
This commit is contained in:
@@ -92,6 +92,13 @@ namespace EscapeRoomEngine.Desert.Runtime
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void Disable() => Active = false;
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void Press() => Pressed = true;
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void Release() => Pressed = false;
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void PressAndRelease()
|
||||
{
|
||||
Press();
|
||||
Release();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using NaughtyAttributes;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
namespace EscapeRoomEngine.Desert.Runtime
|
||||
{
|
||||
[RequireComponent(typeof(Emission))]
|
||||
public class Crystal : MonoBehaviour
|
||||
@@ -10,7 +11,6 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => _emission.active;
|
||||
set
|
||||
{
|
||||
_emission.active = value;
|
||||
@@ -18,16 +18,20 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
}
|
||||
}
|
||||
|
||||
public DynamicColor Color
|
||||
{
|
||||
set
|
||||
{
|
||||
_emission.color = value.hdr;
|
||||
crystalLight.color = value.ldr;
|
||||
}
|
||||
}
|
||||
|
||||
private Emission _emission;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_emission = GetComponent<Emission>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
@@ -9,7 +9,7 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
[BoxGroup("Internal")] [Required] public Emission statusLight;
|
||||
[BoxGroup("Internal")] [Required] public Ring ring;
|
||||
|
||||
private Color _puzzleColor, _solvedColor;
|
||||
private DynamicColor _puzzleColor, _solvedColor;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -29,7 +29,7 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
_active = value;
|
||||
|
||||
statusLight.color = _active ? _puzzleColor : _solvedColor;
|
||||
statusLight.color = _active ? _puzzleColor.hdr : _solvedColor.hdr;
|
||||
ring.rotating = _active;
|
||||
if (!_active)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
private IOption<Symbol> _activeSymbol;
|
||||
private Animator _animator;
|
||||
private Ball _ball;
|
||||
private Color _puzzleColor, _solvedColor;
|
||||
private DynamicColor _puzzleColor, _solvedColor;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -50,12 +50,12 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
case PuzzleEventType.Restarted:
|
||||
_ball.Active = true;
|
||||
terminalLight.color = _puzzleColor;
|
||||
terminalLight.color = _puzzleColor.hdr;
|
||||
symbols.ForEach(symbol => symbol.Enable());
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
_ball.Active = false;
|
||||
terminalLight.color = _solvedColor;
|
||||
terminalLight.color = _solvedColor.hdr;
|
||||
symbols.ForEach(symbol => symbol.Disable());
|
||||
break;
|
||||
case PuzzleEventType.WrongInput:
|
||||
|
||||
@@ -1,27 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using JetBrains.Annotations;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_B
|
||||
{
|
||||
[Serializable]
|
||||
internal struct ButtonAction
|
||||
{
|
||||
public SymbolButton button;
|
||||
public List<int> stateIndices;
|
||||
}
|
||||
|
||||
public class PuzzleB : StatePuzzle
|
||||
{
|
||||
[ValidateInput("CorrectRotatorCount")]
|
||||
public List<Transform> rotators;
|
||||
public List<Rotator> rotators;
|
||||
[InfoBox("Every button action will toggle the states at the given indices between 0 and 90 degrees.")]
|
||||
[SerializeField]
|
||||
private List<ButtonAction> buttonActions;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private List<Emission> lights;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private Crystal crystal;
|
||||
|
||||
private DynamicColor _puzzleColor, _solvedColor;
|
||||
|
||||
protected override void StatesUpdate()
|
||||
protected override void Awake()
|
||||
{
|
||||
base.StatesUpdate();
|
||||
base.Awake();
|
||||
|
||||
_puzzleColor = Engine.Runtime.Engine.DefaultEngine.theme.puzzleColor;
|
||||
_solvedColor = Engine.Runtime.Engine.DefaultEngine.theme.solvedColor;
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
PuzzleEvent += (_, type) =>
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PuzzleEventType.Restarted:
|
||||
crystal.Color = _puzzleColor;
|
||||
lights.ForEach(emission => emission.color = _puzzleColor.hdr);
|
||||
rotators.ForEach(rotator => rotator.Emission.color = _puzzleColor.hdr);
|
||||
buttonActions.ForEach(action => action.button.Enable());
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
crystal.Color = _solvedColor;
|
||||
lights.ForEach(emission => emission.color = _solvedColor.hdr);
|
||||
rotators.ForEach(rotator => rotator.Emission.color = _solvedColor.hdr);
|
||||
buttonActions.ForEach(action => action.button.Disable());
|
||||
break;
|
||||
case PuzzleEventType.WrongInput:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var buttonAction in buttonActions)
|
||||
{
|
||||
buttonAction.button.ButtonEvent += (_, type) =>
|
||||
{
|
||||
if (type == ButtonEventType.Pressed)
|
||||
{
|
||||
Switch(buttonAction);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
crystal.Active = true;
|
||||
lights.ForEach(emission => emission.active = true);
|
||||
rotators.ForEach(rotator => rotator.Emission.active = true);
|
||||
}
|
||||
|
||||
protected override void SetState(int index, int value, bool checkSolution)
|
||||
{
|
||||
base.SetState(index, value, checkSolution);
|
||||
|
||||
for (var i = 0; i < stateCount; i++)
|
||||
{
|
||||
rotators[i].localRotation = Quaternion.AngleAxis(states[i], Vector3.up);
|
||||
rotators[i].angle = states[i];
|
||||
}
|
||||
}
|
||||
|
||||
private void Switch(ButtonAction action)
|
||||
{
|
||||
for (var i = 0; i < action.stateIndices.Count; i++)
|
||||
{
|
||||
var stateIndex = action.stateIndices[i];
|
||||
var current = OrientationExtensions.FromAngle(states[stateIndex]);
|
||||
current = current == Orientation.North ? current.Rotated(1) : current.Rotated(-1);
|
||||
|
||||
// set state but only check solution on the last change
|
||||
SetState(stateIndex, current.AngleInt(), i == action.stateIndices.Count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private bool CorrectRotatorCount(List<Transform> list) => list != null && list.Count == stateCount;
|
||||
private bool CorrectRotatorCount(List<Rotator> list) => list != null && list.Count == stateCount;
|
||||
}
|
||||
}
|
||||
29
Assets/Desert/Runtime/Puzzle B/Rotator.cs
Normal file
29
Assets/Desert/Runtime/Puzzle B/Rotator.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_B
|
||||
{
|
||||
[RequireComponent(typeof(Emission))]
|
||||
public class Rotator : MonoBehaviour
|
||||
{
|
||||
[Range(0, 359)] public int angle;
|
||||
[Range(0, 1)] public float speed;
|
||||
|
||||
public Emission Emission { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Emission = GetComponent<Emission>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
angle %= 360;
|
||||
var angleDifference = angle - transform.localEulerAngles.y;
|
||||
if (Math.Abs(angleDifference) >= 0.1)
|
||||
{
|
||||
transform.Rotate(0, angleDifference*Mathf.Pow(speed, 2), 0, Space.Self);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Desert/Runtime/Puzzle B/Rotator.cs.meta
Normal file
11
Assets/Desert/Runtime/Puzzle B/Rotator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4596ccc5a8dcfb4294f3932f43e1847
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,7 +1,8 @@
|
||||
using NaughtyAttributes;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
namespace EscapeRoomEngine.Desert.Runtime
|
||||
{
|
||||
public class SymbolButton : Button
|
||||
{
|
||||
@@ -12,7 +13,7 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
[BoxGroup("Internal")] [Required] public MeshRenderer holoRenderer;
|
||||
|
||||
private Material _material;
|
||||
private Color _puzzleColor, _solvedColor, _activeColor;
|
||||
private DynamicColor _puzzleColor, _solvedColor, _activeColor;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -37,8 +38,8 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
color = _activeColor;
|
||||
}
|
||||
|
||||
_material.SetColor(FresnelColor, color);
|
||||
_material.SetColor(Color, color);
|
||||
_material.SetColor(FresnelColor, color.hdr);
|
||||
_material.SetColor(Color, color.hdr);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user