riversong code showcase
This commit is contained in:
44
Source/Riversong/Game/DebugCommands/DebugCommandsSystem.cs
Normal file
44
Source/Riversong/Game/DebugCommands/DebugCommandsSystem.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using QFSW.QC;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
[GameSystemGroup(typeof(DebugSystemGroup))]
|
||||
public class DebugCommandsSystem : GameSystem, IInitializable, IDisposable
|
||||
{
|
||||
[InjectService]
|
||||
private IUnlocksService _unlocksService;
|
||||
|
||||
[InjectService]
|
||||
private ISignalBus _signalBus;
|
||||
|
||||
public DebugCommandsSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
||||
{
|
||||
}
|
||||
|
||||
public UniTask InitializeAsync()
|
||||
{
|
||||
QuantumRegistry.RegisterObject(this);
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
QuantumRegistry.DeregisterObject(this);
|
||||
}
|
||||
|
||||
[Command("unlock-all", MonoTargetType.Registry)]
|
||||
private void UnlockAll()
|
||||
{
|
||||
_unlocksService.UnlockAll();
|
||||
}
|
||||
|
||||
[Command("complete-demo", MonoTargetType.Registry)]
|
||||
private void CompleteDemo(float gameTime = 15 * 60)
|
||||
{
|
||||
_signalBus.Raise(new DemoCompletedSignal(gameTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Source/Riversong/Game/DebugCommands/DebugSystemGroup.cs
Normal file
8
Source/Riversong/Game/DebugCommands/DebugSystemGroup.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
[InitializeAfter(typeof(UISystemGroup))]
|
||||
public class DebugSystemGroup : GameSystemGroup
|
||||
{
|
||||
}
|
||||
}
|
||||
61
Source/Riversong/Game/DebugCommands/DrawGizmosSystem.cs
Normal file
61
Source/Riversong/Game/DebugCommands/DrawGizmosSystem.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
[GameSystemGroup(typeof(DebugSystemGroup))]
|
||||
public class DrawGizmosSystem : GameSystem, IInitializable, IDisposable
|
||||
{
|
||||
[InjectService]
|
||||
private IEngine _engine;
|
||||
|
||||
private DrawGizmosSceneProxy _sceneProxy;
|
||||
|
||||
private List<IDrawGizmos> _callbacks = new();
|
||||
|
||||
public DrawGizmosSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
||||
{
|
||||
}
|
||||
|
||||
public UniTask InitializeAsync()
|
||||
{
|
||||
#if DEBUG
|
||||
_sceneProxy = new GameObject(nameof(DrawGizmosSceneProxy)).AddComponent<DrawGizmosSceneProxy>();
|
||||
_sceneProxy.DrawGizmos += OnDrawGizmos;
|
||||
#endif
|
||||
|
||||
foreach (var system in _engine.Systems)
|
||||
if (system is IDrawGizmos callback)
|
||||
_callbacks.Add(callback);
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_sceneProxy.DrawGizmos -= OnDrawGizmos;
|
||||
}
|
||||
|
||||
private void OnDrawGizmos(bool selected)
|
||||
{
|
||||
foreach (var callback in _callbacks) callback.DrawGizmos(selected);
|
||||
}
|
||||
|
||||
private class DrawGizmosSceneProxy : MonoBehaviour
|
||||
{
|
||||
public event Action<bool> DrawGizmos;
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
DrawGizmos?.Invoke(false);
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
DrawGizmos?.Invoke(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Source/Riversong/Game/DebugCommands/IDrawGizmos.cs
Normal file
7
Source/Riversong/Game/DebugCommands/IDrawGizmos.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public interface IDrawGizmos
|
||||
{
|
||||
void DrawGizmos(bool selected);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user