Aetheria/Assets/Scripts/Gameplay/Weapons/ConstantParticleWeapon.cs

73 lines
1.7 KiB
C#
Raw Normal View History

2021-02-06 15:29:04 +00:00
using System.Linq;
using UnityEngine;
public class ConstantParticleWeapon : MonoBehaviour
{
public ParticleSystem[] Particles;
2026-06-21 09:37:54 +01:00
public float CastRadius = 0.25f;
2021-02-06 15:29:04 +00:00
public float Damage { get; set; }
2026-06-21 09:37:54 +01:00
public float Range { get; set; }
2021-02-06 15:29:04 +00:00
public DamageType DamageType { get; set; }
public EntityInstance Source { get; set; }
public EntityInstance Target { get; set; }
private bool _stopping;
private void OnEnable()
{
foreach(var p in Particles)
2026-06-21 09:37:54 +01:00
{
var emission = p.emission;
emission.enabled = true;
}
2021-02-06 15:29:04 +00:00
_stopping = false;
}
public void Initialize()
{
foreach(var p in Particles)
{
var main = p.main;
main.simulationSpace = ParticleSystemSimulationSpace.Custom;
main.customSimulationSpace = Source.LocalSpace;
2021-02-06 15:29:04 +00:00
}
}
private void Update()
{
if (Source == null) return;
if (_stopping && Particles.All(p=>p.particleCount == 0))
{
GetComponent<Prototype>().ReturnToPool();
return;
}
2026-06-21 09:37:54 +01:00
if (_stopping || Target == null || Range <= 0)
return;
if (AetheriaYmirPhysicsBridge.Instance.TryCastTargetHulls(
Target,
transform.position,
transform.forward,
Range,
CastRadius,
out var hits))
2021-02-06 15:29:04 +00:00
{
2026-06-21 09:37:54 +01:00
foreach (var hit in hits)
{
break;
}
2021-02-06 15:29:04 +00:00
}
}
public void Stop()
{
foreach(var p in Particles)
2026-06-21 09:37:54 +01:00
{
var emission = p.emission;
emission.enabled = false;
}
2021-02-06 15:29:04 +00:00
_stopping = true;
}
}