button and symbol events, PuzzleDetail log type
This commit is contained in:
@@ -1,53 +1,103 @@
|
||||
using NaughtyAttributes;
|
||||
using System;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime
|
||||
{
|
||||
public enum ButtonEventType
|
||||
{
|
||||
Pressed, Released, Activated, Deactivated
|
||||
}
|
||||
|
||||
public static class ButtonEventExtensions
|
||||
{
|
||||
public static string Description(this ButtonEventType type, Button button)
|
||||
{
|
||||
var action = type switch
|
||||
{
|
||||
ButtonEventType.Pressed => "pressed",
|
||||
ButtonEventType.Released => "released",
|
||||
ButtonEventType.Activated => "activated",
|
||||
ButtonEventType.Deactivated => "deactivated",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||
};
|
||||
|
||||
return $"{button} was {action}";
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void ButtonEventHandler(Button source, ButtonEventType e);
|
||||
|
||||
public class Button : MonoBehaviour
|
||||
{
|
||||
public bool Active
|
||||
public event ButtonEventHandler ButtonEvent;
|
||||
|
||||
[ShowNativeProperty]
|
||||
private bool Active
|
||||
{
|
||||
get => _active;
|
||||
private set
|
||||
set
|
||||
{
|
||||
var previous = _active;
|
||||
_active = value;
|
||||
Pressed = Pressed; // check whether is still pressed
|
||||
|
||||
if (previous != _active)
|
||||
{
|
||||
OnButtonEvent(_active ? ButtonEventType.Activated : ButtonEventType.Deactivated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Pressed
|
||||
[ShowNativeProperty]
|
||||
private bool Pressed
|
||||
{
|
||||
get => _pressed;
|
||||
protected set
|
||||
set
|
||||
{
|
||||
var previous = _pressed;
|
||||
_pressed = Active && value;
|
||||
|
||||
if (previous != _pressed)
|
||||
{
|
||||
OnButtonEvent(_pressed ? ButtonEventType.Pressed : ButtonEventType.Released);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _active, _pressed;
|
||||
private bool _active = true, _pressed;
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void Enable()
|
||||
protected virtual void Awake()
|
||||
{
|
||||
Active = true;
|
||||
ButtonEvent += (_, type) =>
|
||||
{
|
||||
if (type == ButtonEventType.Deactivated)
|
||||
{
|
||||
Pressed = false; // release button if it is deactivated
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void Disable()
|
||||
private void OnButtonEvent(ButtonEventType type)
|
||||
{
|
||||
Active = false;
|
||||
Logger.Log(type.Description(this), LogType.PuzzleDetail);
|
||||
|
||||
ButtonEvent?.Invoke(this, type);
|
||||
}
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void Press()
|
||||
{
|
||||
Pressed = true;
|
||||
}
|
||||
#region Debug Buttons
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void Release()
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void Enable() => Active = true;
|
||||
[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;
|
||||
|
||||
#endregion
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
Pressed = false;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
@@ -62,18 +61,10 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
Module = PuzzleModule.FromModule(module);
|
||||
}
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void Solve()
|
||||
{
|
||||
Solved = true;
|
||||
}
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
public void Restart()
|
||||
{
|
||||
Solved = false;
|
||||
}
|
||||
#region Debug Buttons
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void Solve() => Solved = true;
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void Restart() => Solved = false;
|
||||
[Button("Trigger Wrong Input", EButtonEnableMode.Playmode)]
|
||||
public void WrongInput()
|
||||
{
|
||||
@@ -83,6 +74,8 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static PuzzleState FromState(ModuleState state)
|
||||
{
|
||||
if (state is PuzzleState puzzleState)
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace EscapeRoomEngine.Engine.Runtime.Utilities
|
||||
PassageConnection,
|
||||
RoomGeneration,
|
||||
RequirementResolution,
|
||||
PuzzleFlow
|
||||
PuzzleFlow,
|
||||
PuzzleDetail
|
||||
}
|
||||
|
||||
public class Logger : MonoBehaviour
|
||||
@@ -31,7 +32,7 @@ namespace EscapeRoomEngine.Engine.Runtime.Utilities
|
||||
public bool loggingEnabled;
|
||||
public List<LogType> typeFilter;
|
||||
|
||||
public static void Log(string message, LogType type = LogType.Important)
|
||||
public static void Log(string message, LogType type)
|
||||
{
|
||||
if (DefaultLogger.loggingEnabled && DefaultLogger.typeFilter.Contains(type))
|
||||
{
|
||||
|
||||
@@ -1648,7 +1648,7 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
loggingEnabled: 1
|
||||
typeFilter: 0000000005000000
|
||||
typeFilter: 000000000500000006000000
|
||||
--- !u!1 &1718957584
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
Reference in New Issue
Block a user