Aetheria/Assets/Scripts/Gameplay/Weapons/ConstantLightning.cs
Meta Vens 6140a06a0a Swap Unity.Mathematics usings for CultMath
Every Unity.Mathematics using, alias and qualified name under Assets\Scripts
and tools now names CultMath. The nine `using static ...noise;` lines are
gone: snoise lives on CultMath's math. UnityExtensions loses float4.ToColor
and Color.ToFloat4, which duplicate the bridge's ToColor and ToCultMath; the
float3 colour pair stays because the bridge has none.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:39:12 +02:00

87 lines
2.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static CultMath.math;
public class ConstantLightning : MonoBehaviour
{
public LightningCompute Lightning;
public float HitRadius;
public AnimationCurve FadeCurve;
public float StartWidth = 1;
public float EndWidth = 1;
public float FadeDuration;
public Transform Barrel { get; set; }
public float Damage { get; set; }
public float Penetration { get; set; }
public float Spread { get; set; }
public DamageType DamageType { get; set; }
public EntityInstance Source { get; set; }
public float Range { get; set; }
private bool _stopping;
private float _startTime;
private void OnEnable()
{
_stopping = false;
Lightning.StartAnimation();
}
private void Update()
{
if (Barrel == null) return;
if (_stopping)
{
var lerp = (Time.time - _startTime) / FadeDuration;
Lightning.StartWidth = FadeCurve.Evaluate(lerp) * StartWidth;
Lightning.EndWidth = FadeCurve.Evaluate(lerp) * EndWidth;
if (lerp > 1)
{
GetComponent<Prototype>().ReturnToPool();
return;
}
}
else
{
Lightning.StartWidth = StartWidth;
Lightning.EndWidth = EndWidth;
}
Lightning.FixedEndpoint = false;
var hits = Physics.SphereCastAll(Barrel.position, HitRadius, Barrel.forward, Range, 1 | (1 << 17));
foreach (var hit in hits)
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield && (shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (shield.Entity == Source.Entity) continue;
shield.Entity.Shield.TakeHit(DamageType, Damage * Time.deltaTime);
shield.ShowHit(hit.point, sqrt(Damage));
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (hull.Entity == Source.Entity) continue;
hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, Source.Entity, hit.textureCoord, Barrel.forward);
}
Lightning.FixedEndpoint = true;
Lightning.EndPosition = hit.point;
break;
}
if(!Lightning.FixedEndpoint)
Lightning.EndPosition = Barrel.position + Barrel.forward * Range;
Lightning.StartPosition = Barrel.position;
}
public void Stop()
{
_stopping = true;
_startTime = Time.time;
}
}