riversong code showcase

This commit is contained in:
Daniele Marotta
2026-05-21 15:52:18 +02:00
commit 4c9eea1c02
462 changed files with 23406 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.InputSystem;
namespace DanieleMarotta.RiversongCodeShowcase
{
[Service(typeof(IGameSpeed))]
[GameSystemGroup(typeof(EarlyGameSystemGroup))]
[RequiresWorldReadyForUpdate]
[UpdateBefore(typeof(WorldTimeSystem))]
public class GameSpeedSystem : GameSystem, IGameSpeed, IInitializable, IUpdatable, IDisposable
{
private const float NormalSpeed = 1;
private const float FastSpeed = 2;
private const float VeryFastSpeed = 4;
public GameSpeedSystem(IServiceLocator serviceLocator) : base(serviceLocator)
{
}
public int SpeedLevel { get; private set; }
public UniTask InitializeAsync()
{
SetSpeedLevel(0);
return UniTask.CompletedTask;
}
public void Dispose()
{
SetSpeedLevel(0);
}
public void Update()
{
if (Keyboard.current.digit1Key.wasPressedThisFrame)
SetSpeedLevel(0);
else if (Keyboard.current.digit2Key.wasPressedThisFrame)
SetSpeedLevel(1);
else if (Keyboard.current.digit3Key.wasPressedThisFrame) SetSpeedLevel(2);
Time.timeScale = GetTimeScale();
}
public void SetSpeedLevel(int speedLevel)
{
SpeedLevel = speedLevel;
}
private float GetTimeScale()
{
return SpeedLevel switch
{
1 => FastSpeed,
2 => VeryFastSpeed,
_ => NormalSpeed
};
}
}
}