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,40 @@
using UnityEngine;
using UnityEngine.VFX;
namespace DanieleMarotta.RiversongCodeShowcase
{
[RequireComponent(typeof(VisualEffect))]
public class AutoDestroyVfx : MonoBehaviour
{
private const float DestroyDelayWhenNoParticles = 1;
private VisualEffect _vfx;
private bool _emittedOnce;
private float _timer;
private void Awake()
{
_vfx = GetComponent<VisualEffect>();
}
private void Update()
{
if (!_vfx) return;
_emittedOnce |= _vfx.aliveParticleCount > 0;
if (!_emittedOnce) return;
if (_vfx.aliveParticleCount > 0)
{
_timer = 0;
return;
}
_timer += Time.unscaledDeltaTime;
if (_timer >= DestroyDelayWhenNoParticles) Destroy(gameObject);
}
}
}

View File

@@ -0,0 +1,18 @@
using UnityEngine;
using UnityEngine.VFX;
namespace DanieleMarotta.RiversongCodeShowcase
{
public static class DustVfxProperties
{
public static readonly int IntensityID = Shader.PropertyToID("Intensity");
public static readonly int SizeID = Shader.PropertyToID("Size");
public static void Setup(VisualEffect vfx, float intensity, Vector2 size)
{
vfx.SetFloat(IntensityID, intensity);
vfx.SetVector2(SizeID, size);
}
}
}

View File

@@ -0,0 +1,9 @@
namespace DanieleMarotta.RiversongCodeShowcase
{
public interface IProjectileManager
{
float ComputeProjectileTravelTime(Agent source, Agent target);
void FireProjectile(Agent source, Agent target);
}
}

View File

@@ -0,0 +1,61 @@
using Cysharp.Threading.Tasks;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace DanieleMarotta.RiversongCodeShowcase
{
[Service(typeof(IProjectileManager))]
public class ProjectileManagerSystem : GameSystem, IProjectileManager
{
private const float ProjectileSpeed = 4;
[InjectService]
private IIntentLogicExecutor _intentLogicExecutor;
public ProjectileManagerSystem(IServiceLocator serviceLocator) : base(serviceLocator)
{
}
public float ComputeProjectileTravelTime(Agent source, Agent target)
{
return math.distance(source.Position, target.Position) / ProjectileSpeed;
}
public void FireProjectile(Agent source, Agent target)
{
_ = FireProjectileAsync(source, target, ComputeProjectileTravelTime(source, target));
}
private async UniTask FireProjectileAsync(Agent source, Agent target, float travelTime)
{
var prefabRef = source.Definition.Projectile;
var projectile = await prefabRef.InstantiateAsync();
var p0 = (Vector3)source.Position;
var p1 = (Vector3)target.Position;
// const float peakHeightPerMeter = 0.1f;
// var peak = Vector3.Distance(p0, p1) * peakHeightPerMeter;
var t = 0f;
while (t < 1)
{
t = Mathf.Clamp01(t + Time.deltaTime / travelTime);
var position = Vector3.Lerp(p0, p1, t);
//position.y += 4 * peak * t * (1 - t);
var rotation = Quaternion.LookRotation((position - projectile.transform.position).normalized);
projectile.transform.SetPositionAndRotation(position, rotation);
await UniTask.NextFrame();
}
Addressables.ReleaseInstance(projectile);
_intentLogicExecutor.CancelRemainingIntents(target);
}
}
}