2019-08-03 18:14:47 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Saltosion.OneWeapon {
|
|
|
|
|
public class BloodLauncher : MonoBehaviour {
|
|
|
|
|
private static BloodLauncher Singleton;
|
2019-08-04 16:14:48 +02:00
|
|
|
|
public GameObject StructuralParticlePrefab;
|
2019-08-03 18:14:47 +02:00
|
|
|
|
public GameObject BloodParticlePrefab;
|
2019-08-04 01:45:32 +02:00
|
|
|
|
public GameObject CensoredBloodParticlePrefab;
|
2019-08-03 18:14:47 +02:00
|
|
|
|
public Transform ParticleRoot;
|
|
|
|
|
public int MaxParticles;
|
2019-08-04 00:48:41 +02:00
|
|
|
|
public bool DebugLaunch = false;
|
2019-08-03 18:14:47 +02:00
|
|
|
|
|
|
|
|
|
public static void Splatter(Vector2 origin, Vector2 direction, int particleCount, float force, float degrees) {
|
2019-08-04 16:14:48 +02:00
|
|
|
|
LaunchParticles(Singleton.GetGorePrefab(), origin, direction, particleCount, force, degrees);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void DebrisExplode(Vector2 origin, Vector2 direction, int particleCount, float force, float degrees) {
|
|
|
|
|
LaunchParticles(Singleton.StructuralParticlePrefab, origin, direction, particleCount, force, degrees);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void LaunchParticles(GameObject prefab, Vector2 origin, Vector2 direction, int particleCount, float force, float degrees) {
|
2019-08-04 01:45:32 +02:00
|
|
|
|
for (int i = 0; i < (int)(particleCount * Singleton.GetParticleCountMultiplier()); i++) {
|
2019-08-03 18:14:47 +02:00
|
|
|
|
if (Singleton.ParticleRoot.childCount >= Singleton.MaxParticles) {
|
|
|
|
|
Destroy(Singleton.ParticleRoot.GetChild((int)(Random.value * Singleton.ParticleRoot.childCount)).gameObject);
|
|
|
|
|
}
|
2019-08-04 16:14:48 +02:00
|
|
|
|
GameObject Obj = Instantiate(prefab, origin, new Quaternion(), Singleton.ParticleRoot);
|
2019-08-03 18:14:47 +02:00
|
|
|
|
BloodParticle Particle = Obj.GetComponent<BloodParticle>();
|
|
|
|
|
float Intensity = Mathf.Pow(Random.value * force, 1.1f);
|
|
|
|
|
float Cone = degrees / 360.0f;
|
|
|
|
|
float Offset = Mathf.Atan2(direction.y, direction.x);
|
2019-08-04 19:08:13 +02:00
|
|
|
|
float Radians = Offset + Mathf.Pow(Cone * (Random.value - 0.5f) * 2f, 2f) * Mathf.PI * 2.0f;
|
2019-08-03 18:14:47 +02:00
|
|
|
|
Particle.LaunchForce = new Vector2(Mathf.Cos(Radians), Mathf.Sin(Radians)) * Intensity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Start() {
|
|
|
|
|
Singleton = this;
|
|
|
|
|
}
|
2019-08-04 01:45:32 +02:00
|
|
|
|
|
|
|
|
|
private GameObject GetGorePrefab() {
|
|
|
|
|
return Options.CensorGore ? CensoredBloodParticlePrefab : BloodParticlePrefab;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private float GetParticleCountMultiplier() {
|
|
|
|
|
return Options.CensorGore ? 0.1f : 1f;
|
|
|
|
|
}
|
2019-08-03 18:14:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|