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
|
||||
Loading…
Reference in a new issue