button and symbol events, PuzzleDetail log type
This commit is contained in:
@@ -1,18 +1,50 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.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);
|
||||
|
||||
[RequireComponent(typeof(Emission))]
|
||||
public class Symbol : MonoBehaviour
|
||||
{
|
||||
public int symbolNumber;
|
||||
public float anglePosition;
|
||||
public event SymbolEventHandler SymbolEvent;
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => _emission.active;
|
||||
set
|
||||
{
|
||||
_emission.active = value;
|
||||
var previous = _emission.active;
|
||||
_emission.active = value;
|
||||
|
||||
if (previous != value)
|
||||
{
|
||||
OnSymbolEvent(value ? SymbolEventType.Activated : SymbolEventType.Deactivated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,5 +59,17 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
Active = false;
|
||||
}
|
||||
|
||||
private void OnSymbolEvent(SymbolEventType type)
|
||||
{
|
||||
Logger.Log(type.Description(this), LogType.PuzzleDetail);
|
||||
|
||||
SymbolEvent?.Invoke(type);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,29 +9,27 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
private static readonly int FresnelColor = Shader.PropertyToID("_FresnelColor");
|
||||
private static readonly int Color = Shader.PropertyToID("_Color");
|
||||
|
||||
public int symbolNumber;
|
||||
public EngineTheme theme;
|
||||
|
||||
public override bool Pressed
|
||||
{
|
||||
get => base.Pressed;
|
||||
protected set
|
||||
{
|
||||
base.Pressed = value;
|
||||
|
||||
var color =
|
||||
Pressed ? theme.activeColor
|
||||
: Active ? theme.puzzleColor
|
||||
: theme.solvedColor;
|
||||
_material.SetColor(FresnelColor, color);
|
||||
_material.SetColor(Color, color);
|
||||
}
|
||||
}
|
||||
|
||||
private Material _material;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_material = GetComponent<MeshRenderer>().material;
|
||||
|
||||
ButtonEvent += (_, type) =>
|
||||
{
|
||||
var color = type switch
|
||||
{
|
||||
ButtonEventType.Pressed => theme.activeColor,
|
||||
ButtonEventType.Deactivated => theme.solvedColor,
|
||||
_ => theme.puzzleColor
|
||||
};
|
||||
|
||||
_material.SetColor(FresnelColor, color);
|
||||
_material.SetColor(Color, color);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user