riversong code showcase
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
[GameSystemGroup(typeof(LateGameSystemGroup))]
|
||||
public class GlobalShaderParametersSystem : GameSystem, IInitializable, IDisposable, IUpdatable
|
||||
{
|
||||
[InjectService]
|
||||
private World _world;
|
||||
|
||||
[InjectService]
|
||||
private ISignalBus _signalBus;
|
||||
|
||||
public GlobalShaderParametersSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
||||
{
|
||||
}
|
||||
|
||||
public UniTask InitializeAsync()
|
||||
{
|
||||
_signalBus.Subscribe<WorldReadySignal>(OnWorldReady);
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_signalBus.Unsubscribe<WorldReadySignal>(OnWorldReady);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
var t = Time.unscaledTime;
|
||||
Shader.SetGlobalVector(ShaderProperties.UnscaledTime, new Vector4(t / 20, t, t * 2, t * 3));
|
||||
}
|
||||
|
||||
private void OnWorldReady(WorldReadySignal signal)
|
||||
{
|
||||
Shader.SetGlobalVector(ShaderProperties.WorldSize, new Vector4(_world.Size.x, _world.Size.y, 0, 0));
|
||||
Shader.SetGlobalVector(ShaderProperties.InverseWorldSize, new Vector2(1 / (float)_world.Size.x, 1 / (float)_world.Size.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user