using System; using NaughtyAttributes; using Station46.Modules.Hover_Sphere.Scripts; using Station46.Scripts; using UnityEngine; using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger; using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType; namespace Station46.Modules.Symbols.Scripts { public enum SymbolEventType { Activated, Deactivated } public static class SymbolEventExtensions { public static string Description(this SymbolEventType type, Symbol symbol) { var action = type switch { SymbolEventType.Activated => "activated", SymbolEventType.Deactivated => "deactivated", _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) }; return $"{symbol} was {action}"; } } public delegate void SymbolEventHandler(SymbolEventType e); /// /// The main component for the symbols on the symbol ring module. /// [RequireComponent(typeof(Emission))] public class Symbol : MonoBehaviour { [Tooltip("The number of the symbol in the puzzle solution.")] public int symbolNumber; [BoxGroup("Internal")] public int symbolPosition; [BoxGroup("Internal")] public float anglePosition; public event SymbolEventHandler SymbolEvent; /// /// Whether the symbol is lit up. This is controlled by the . /// public bool Active { set { var previous = _emission.active; _emission.active = value; if (previous != value) { OnSymbolEvent(value ? SymbolEventType.Activated : SymbolEventType.Deactivated); } } } private Emission _emission; private void Awake() { _emission = GetComponent(); } private void Start() { Active = false; } private void OnSymbolEvent(SymbolEventType type) { Logger.Log(type.Description(this), LogType.PuzzleDetail); SymbolEvent?.Invoke(type); } public override string ToString() { return name; } } }