refactor modules
This commit is contained in:
86
Assets/Station46/Modules/Symbols/Scripts/Symbol.cs
Normal file
86
Assets/Station46/Modules/Symbols/Scripts/Symbol.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||
|
||||
namespace Station46.Runtime.Puzzle_A
|
||||
{
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// The main component for the symbols on the symbol ring module.
|
||||
/// </summary>
|
||||
[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;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the symbol is lit up. This is controlled by the <see cref="Ring"/>.
|
||||
/// </summary>
|
||||
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<Emission>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Station46/Modules/Symbols/Scripts/Symbol.cs.meta
Normal file
11
Assets/Station46/Modules/Symbols/Scripts/Symbol.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e099fd852792c34188dcf102aa895e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Station46/Modules/Symbols/Scripts/SymbolButton.cs
Normal file
13
Assets/Station46/Modules/Symbols/Scripts/SymbolButton.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Station46.Runtime.Puzzle_A
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="HoloButton"/> that includes the number of its assigned symbol.
|
||||
/// </summary>
|
||||
public class SymbolButton : HoloButton
|
||||
{
|
||||
[Tooltip("The number of the symbol assigned to this button.")]
|
||||
public int symbolNumber;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d6620bee0f14224b11a19808d537cbd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user