Charged Weapons & Hitscan Weapons
Implemented two new weapon types and created the Railgun (which is both) and accompanying VFX
This commit is contained in:
parent
4c0038830b
commit
2a0fe34611
36 changed files with 49495 additions and 25 deletions
38
Assets/Scripts/Gameplay/Weapons/ChargeEffectManager.cs
Normal file
38
Assets/Scripts/Gameplay/Weapons/ChargeEffectManager.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ChargeEffectManager : MonoBehaviour
|
||||
{
|
||||
public Prototype EffectPrototype;
|
||||
|
||||
private Dictionary<ChargedWeapon, WeaponChargeEffect> ActiveEffects = new Dictionary<ChargedWeapon, WeaponChargeEffect>();
|
||||
|
||||
public void StartCharging(ChargedWeapon weapon, EquippedItem item, EntityInstance source)
|
||||
{
|
||||
var effect = EffectPrototype.Instantiate<WeaponChargeEffect>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var t = effect.transform;
|
||||
t.SetParent(barrel);
|
||||
t.forward = barrel.forward;
|
||||
t.position = barrel.position;
|
||||
effect.Weapon = weapon;
|
||||
ActiveEffects[weapon] = effect;
|
||||
}
|
||||
|
||||
public void StopCharging(ChargedWeapon weapon)
|
||||
{
|
||||
ActiveEffects[weapon].StopCharging();
|
||||
}
|
||||
|
||||
public void Charged(ChargedWeapon weapon)
|
||||
{
|
||||
ActiveEffects[weapon].Charged();
|
||||
}
|
||||
|
||||
public void Failed(ChargedWeapon weapon)
|
||||
{
|
||||
ActiveEffects[weapon].Failed();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/Weapons/ChargeEffectManager.cs.meta
Normal file
11
Assets/Scripts/Gameplay/Weapons/ChargeEffectManager.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: acaf148dd74205a4098665bb4be3f3a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
|||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: 70
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
|
|||
72
Assets/Scripts/Gameplay/Weapons/HitscanEffect.cs
Normal file
72
Assets/Scripts/Gameplay/Weapons/HitscanEffect.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class HitscanEffect : MonoBehaviour
|
||||
{
|
||||
public float Duration;
|
||||
public AnimationCurve IntensityCurve;
|
||||
public LineRenderer Line;
|
||||
public ParticleSystem LineEffect;
|
||||
public Prototype HitEffect;
|
||||
|
||||
public Zone Zone { get; set; }
|
||||
|
||||
public float Damage { get; set; }
|
||||
public float Penetration { get; set; }
|
||||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
public float Range { get; set; }
|
||||
|
||||
private float _startTime;
|
||||
private bool _active = false;
|
||||
|
||||
public void Fire()
|
||||
{
|
||||
_startTime = Time.time;
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(new Ray(transform.position, transform.forward), out hit, Range, 1))
|
||||
{
|
||||
var hull = hit.collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
if (hull.Entity != SourceEntity)
|
||||
{
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit, transform.forward);
|
||||
}
|
||||
}
|
||||
var length = (hit.point - transform.position).magnitude;
|
||||
Line.SetPosition(1, Vector3.forward * length);
|
||||
var emission = LineEffect.emission;
|
||||
emission.rateOverTimeMultiplier = length;
|
||||
var shape = LineEffect.shape;
|
||||
shape.position = Vector3.forward * (length / 2);
|
||||
shape.scale = Vector3.one * (length / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
Line.SetPosition(1, Vector3.forward * Range);
|
||||
var emission = LineEffect.emission;
|
||||
emission.rateOverTimeMultiplier = Range;
|
||||
var shape = LineEffect.shape;
|
||||
shape.position = Vector3.forward * (Range / 2);
|
||||
shape.scale = Vector3.one * (Range / 2);
|
||||
}
|
||||
LineEffect.Play(true);
|
||||
_active = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!_active) return;
|
||||
var lerp = (Time.time - _startTime) / Duration;
|
||||
if (lerp > 1)
|
||||
{
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
return;
|
||||
}
|
||||
|
||||
Line.widthMultiplier = IntensityCurve.Evaluate(lerp);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/Weapons/HitscanEffect.cs.meta
Normal file
11
Assets/Scripts/Gameplay/Weapons/HitscanEffect.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f8555514e892b2c438fe085da1fdf89d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Scripts/Gameplay/Weapons/HitscanManager.cs
Normal file
21
Assets/Scripts/Gameplay/Weapons/HitscanManager.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
public class HitscanManager : InstantWeaponEffectManager
|
||||
{
|
||||
public Prototype Prototype;
|
||||
public override void Fire(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
{
|
||||
var p = Prototype.Instantiate<HitscanEffect>();
|
||||
p.SourceEntity = source.Entity;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var t = p.transform;
|
||||
t.position = barrel.position;
|
||||
t.forward = barrel.forward;
|
||||
p.Range = source.Entity.ItemManager.Evaluate(data.Range, item.EquippableItem, source.Entity);
|
||||
p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item.EquippableItem, source.Entity);
|
||||
p.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item.EquippableItem, source.Entity);
|
||||
p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item.EquippableItem, source.Entity);
|
||||
p.DamageType = data.DamageType;
|
||||
p.Zone = source.Entity.Zone;
|
||||
p.Fire();
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Gameplay/Weapons/HitscanManager.cs.meta
Normal file
3
Assets/Scripts/Gameplay/Weapons/HitscanManager.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 90fe995fff18457987112f6f96b45a17
|
||||
timeCreated: 1611954267
|
||||
|
|
@ -5,4 +5,4 @@ using UnityEngine;
|
|||
public abstract class InstantWeaponEffectManager : MonoBehaviour
|
||||
{
|
||||
public abstract void Fire(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target);
|
||||
}
|
||||
}
|
||||
72
Assets/Scripts/Gameplay/Weapons/ParticleChargeEffect.cs
Normal file
72
Assets/Scripts/Gameplay/Weapons/ParticleChargeEffect.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ParticleChargeEffect : WeaponChargeEffect
|
||||
{
|
||||
public ParticleSystem ChargeEffect;
|
||||
public ParticleSystem OverchargeEffect;
|
||||
public ParticleSystem FailureEffect;
|
||||
|
||||
private float _charge;
|
||||
private bool _overloaded;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ChargeEffect.Stop(true);
|
||||
OverchargeEffect.Stop(true);
|
||||
FailureEffect.Stop(true);
|
||||
ChargeEffect.Clear(true);
|
||||
OverchargeEffect.Clear(true);
|
||||
FailureEffect.Clear(true);
|
||||
ChargeEffect.Play(true);
|
||||
ChargeEffect.enableEmission = true;
|
||||
|
||||
_overloaded = false;
|
||||
_charge = 0;
|
||||
}
|
||||
|
||||
public override void StopCharging()
|
||||
{
|
||||
if (_overloaded)
|
||||
OverchargeEffect.enableEmission = false;
|
||||
else
|
||||
ChargeEffect.enableEmission = false;
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
|
||||
public override void Charged()
|
||||
{
|
||||
ChargeEffect.enableEmission = false;
|
||||
OverchargeEffect.Play(true);
|
||||
OverchargeEffect.enableEmission = true;
|
||||
_overloaded = true;
|
||||
}
|
||||
|
||||
public override void Failed()
|
||||
{
|
||||
OverchargeEffect.enableEmission = false;
|
||||
FailureEffect.Play(true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Weapon == null) return;
|
||||
_charge = Weapon.Charge;
|
||||
|
||||
if (!_overloaded)
|
||||
{
|
||||
ChargeEffect.playbackSpeed = _charge;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Kill()
|
||||
{
|
||||
while (ChargeEffect.particleCount > 0 || OverchargeEffect.particleCount > 0 || FailureEffect.particleCount > 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/Weapons/ParticleChargeEffect.cs.meta
Normal file
11
Assets/Scripts/Gameplay/Weapons/ParticleChargeEffect.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d17593d3a68cb7b48905eb55ea270238
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -55,13 +55,6 @@ public class Projectile : MonoBehaviour
|
|||
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit, Velocity.normalized);
|
||||
transform.position = hit.point;
|
||||
StartCoroutine(Kill());
|
||||
if (HitEffect != null)
|
||||
{
|
||||
var t = HitEffect.Instantiate<Transform>();
|
||||
t.SetParent(hit.collider.transform);
|
||||
t.position = hit.point;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else// if (hit.transform.gameObject.layer == 1)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
|||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: 60
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
|
|||
10
Assets/Scripts/Gameplay/Weapons/WeaponChargeEffect.cs
Normal file
10
Assets/Scripts/Gameplay/Weapons/WeaponChargeEffect.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using UnityEngine;
|
||||
|
||||
public abstract class WeaponChargeEffect : MonoBehaviour
|
||||
{
|
||||
public ChargedWeapon Weapon { get; set; }
|
||||
|
||||
public abstract void StopCharging();
|
||||
public abstract void Charged();
|
||||
public abstract void Failed();
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 788d655faf774be58c5918914b610e01
|
||||
timeCreated: 1611952470
|
||||
|
|
@ -220,6 +220,18 @@ public class SectorRenderer : MonoBehaviour
|
|||
|
||||
instantWeapon.OnFire += () =>
|
||||
_instantWeaponManagers[data].Fire(data, item, instance, entity.Target.Value != null ? EntityInstances[entity.Target.Value] : null);
|
||||
|
||||
if (behavior is ChargedWeapon chargedWeapon)
|
||||
{
|
||||
var chargeManager = _instantWeaponManagers[data].GetComponent<ChargeEffectManager>();
|
||||
if (chargeManager)
|
||||
{
|
||||
chargedWeapon.OnStartCharging += () => chargeManager.StartCharging(chargedWeapon, item, instance);
|
||||
chargedWeapon.OnStopCharging += () => chargeManager.StopCharging(chargedWeapon);
|
||||
chargedWeapon.OnCharged += () => chargeManager.Charged(chargedWeapon);
|
||||
chargedWeapon.OnFailed += () => chargeManager.Failed(chargedWeapon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (behavior is ConstantWeapon constantWeapon)
|
||||
|
|
|
|||
|
|
@ -9,19 +9,19 @@ using static Unity.Mathematics.math;
|
|||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class ChargedWeaponData : InstantWeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("chargeTime"), Key(13), RuntimeInspectable]
|
||||
[InspectableField, JsonProperty("chargeTime"), Key(16), RuntimeInspectable]
|
||||
public PerformanceStat ChargeTime = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("chargeEnergy"), Key(14), RuntimeInspectable]
|
||||
[InspectableField, JsonProperty("chargeEnergy"), Key(17), RuntimeInspectable]
|
||||
public PerformanceStat ChargeEnergy = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("canFireEarly"), Key(15)]
|
||||
[InspectableField, JsonProperty("canFireEarly"), Key(18)]
|
||||
public bool CanFireEarly;
|
||||
|
||||
[InspectableField, JsonProperty("failureCharge"), Key(16)]
|
||||
[InspectableField, JsonProperty("failureCharge"), Key(19)]
|
||||
public float FailureCharge;
|
||||
|
||||
[InspectableField, JsonProperty("failureDamage"), Key(17)]
|
||||
[InspectableField, JsonProperty("failureDamage"), Key(20)]
|
||||
public float FailureDamage;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
|
|
@ -38,6 +38,8 @@ public class ChargedWeapon : InstantWeapon
|
|||
private float _charge;
|
||||
private float _progress;
|
||||
|
||||
public event Action OnStartCharging;
|
||||
public event Action OnStopCharging;
|
||||
public event Action OnCharged;
|
||||
public event Action OnFailed;
|
||||
|
||||
|
|
@ -63,10 +65,12 @@ public class ChargedWeapon : InstantWeapon
|
|||
_charged = true;
|
||||
OnCharged?.Invoke();
|
||||
}
|
||||
if (_charge > _data.FailureCharge)
|
||||
if (_data.FailureCharge > 1 && _charge > _data.FailureCharge)
|
||||
{
|
||||
_charging = false;
|
||||
_cooldown = 1;
|
||||
_coolingDown = true;
|
||||
_charge = 0;
|
||||
OnFailed?.Invoke();
|
||||
Item.EquippableItem.Durability -= _data.FailureDamage;
|
||||
}
|
||||
|
|
@ -76,8 +80,9 @@ public class ChargedWeapon : InstantWeapon
|
|||
|
||||
public override void Activate()
|
||||
{
|
||||
if(_cooldown < 0)
|
||||
if(!_coolingDown)
|
||||
{
|
||||
OnStartCharging?.Invoke();
|
||||
_charging = true;
|
||||
_charged = false;
|
||||
}
|
||||
|
|
@ -85,10 +90,15 @@ public class ChargedWeapon : InstantWeapon
|
|||
|
||||
public override void Deactivate()
|
||||
{
|
||||
if (_charging && (_data.CanFireEarly || _charge > 1))
|
||||
if (_charging)
|
||||
{
|
||||
Trigger();
|
||||
_charge = 0;
|
||||
if (_data.CanFireEarly || _charge > 1)
|
||||
{
|
||||
Trigger();
|
||||
_charge = 0;
|
||||
}
|
||||
OnStopCharging?.Invoke();
|
||||
_charging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class InstantWeapon : Weapon, IProgressBehavior
|
|||
private float _burstInterval;
|
||||
protected float _cooldown; // Normalized
|
||||
private int _ammo = 1;
|
||||
private bool _coolingDown;
|
||||
protected bool _coolingDown;
|
||||
|
||||
public override int Ammo
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue