refactor modules

This commit is contained in:
2023-03-22 17:03:55 +01:00
parent 52cf3a7fbd
commit 128ab216d2
503 changed files with 1835 additions and 379 deletions

View File

@@ -0,0 +1,40 @@
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Modules.State;
using NaughtyAttributes;
namespace Station46.Runtime.Puzzle_A
{
/// <summary>
/// The main component for the symbol ball module.
/// </summary>
public class Ball : ModuleState
{
[BoxGroup("Internal")] [Required]
public Emission statusLight;
[BoxGroup("Internal")] [Required]
public Ring ring;
public bool StatusLight
{
set => statusLight.active = value;
}
public bool Active
{
set
{
statusLight.color = value ?
EscapeRoomEngine.Engine.Runtime.Engine.Theme.puzzleColor.hdr
: EscapeRoomEngine.Engine.Runtime.Engine.Theme.solvedColor.hdr;
ring.rotating = value;
if (!value)
{
ring.crystal.Active = false;
ring.symbols.ForEach(symbol => symbol.Active = false);
}
}
}
public override void SetModule(Module module) {}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b9b2d31478f94735a2e19e7c07a27f05
timeCreated: 1668705636

View File

@@ -0,0 +1,48 @@
using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using UnityEngine;
namespace Station46.Runtime
{
/// <summary>
/// A rotating crystal that can change colour.
/// </summary>
[RequireComponent(typeof(Emission))]
public class Crystal : MonoBehaviour
{
[Required]
[BoxGroup("Internal")]
public Light crystalLight;
/// <summary>
/// Turns the crystal light on or off.
/// </summary>
public bool Active
{
set
{
_emission.active = value;
crystalLight.enabled = value;
}
}
/// <summary>
/// The crystal light and emission colours.
/// </summary>
public DynamicColor Color
{
set
{
_emission.color = value.hdr;
crystalLight.color = value.ldr;
}
}
private Emission _emission;
private void Awake()
{
_emission = GetComponent<Emission>();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3b9480c87b3b4def9c85adb088dab147
timeCreated: 1668703088

View File

@@ -0,0 +1,65 @@
using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using JetBrains.Annotations;
using NaughtyAttributes;
using UnityEngine;
namespace Station46.Runtime.Puzzle_A
{
/// <summary>
/// The rotating ring in the symbol ball module.
/// </summary>
public class Ring : MonoBehaviour
{
[Tooltip("Whether the ring is rotating.")]
public bool rotating = true;
[Tooltip("The current angle of the rotation.")]
public float rotationAngle;
[Tooltip("The range in degrees from the front of the module where a symbol should be lit up.")]
[MinMaxSlider(-180, 180)]
public Vector2 activeRange;
[BoxGroup("Internal")] [Required]
public Crystal crystal;
[BoxGroup("Internal")]
[ValidateInput("SymbolCount", "Must have same amount of symbols and slots.")]
public List<Symbol> symbols;
[BoxGroup("Internal")]
public List<Transform> symbolSlots;
private void Awake()
{
var angleDistance = 360f / symbols.Count;
List<Symbol> symbolInstances = new(symbols.Count);
for (var i = 0; i < symbols.Count; i++)
{
var symbol = Instantiate(symbols.RandomElement(), symbolSlots[i], false);
symbol.symbolPosition = i;
symbol.anglePosition = i * angleDistance;
symbolInstances.Add(symbol);
}
symbols = symbolInstances;
}
private void Update()
{
if(rotating)
{
transform.localRotation = Quaternion.AngleAxis(rotationAngle, Vector3.forward);
var activeSymbol = false;
symbols.ForEach(symbol =>
{
var angle = (rotationAngle - symbol.anglePosition) % 360;
var active = angle > activeRange.x && angle < activeRange.y || angle > 360 + activeRange.x;
symbol.Active = active;
activeSymbol |= active;
});
crystal.Active = activeSymbol;
}
}
[UsedImplicitly] private bool SymbolCount(List<Symbol> list) => list.Count == symbolSlots.Count;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7902f6a7fa0fd844f8ed93e3debd7778
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: