using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Saltosion.OneWeapon { public class BloodLauncher : MonoBehaviour { private static BloodLauncher Singleton; public GameObject StructuralParticlePrefab; public GameObject BloodParticlePrefab; public GameObject CensoredBloodParticlePrefab; public Transform ParticleRoot; public int MaxParticles; public bool DebugLaunch = false; public static void Splatter(Vector2 origin, Vector2 direction, int particleCount, float force, float degrees, bool sticky = true) { LaunchParticles(Singleton.GetGorePrefab(), origin, direction, particleCount, force, degrees, sticky); } public static void DebrisExplode(Vector2 origin, Vector2 direction, int particleCount, float force, float degrees, bool sticky = true) { LaunchParticles(Singleton.StructuralParticlePrefab, origin, direction, particleCount, force, degrees, sticky); } private static void LaunchParticles(GameObject prefab, Vector2 origin, Vector2 direction, int particleCount, float force, float degrees, bool sticky) { for (int i = 0; i < (int)(particleCount * Singleton.GetParticleCountMultiplier()); i++) { if (Singleton.ParticleRoot.childCount >= Singleton.MaxParticles) { Destroy(Singleton.ParticleRoot.GetChild((int)(Random.value * Singleton.ParticleRoot.childCount)).gameObject); } GameObject Obj = Instantiate(prefab, origin, new Quaternion(), Singleton.ParticleRoot); BloodParticle Particle = Obj.GetComponent(); float Intensity = Mathf.Pow(Random.value, 0.8f) * force; float Cone = degrees / 360.0f; float Offset = Mathf.Atan2(direction.y, direction.x); float Radians = Offset + Mathf.Pow(Cone * (Random.value - 0.5f) * 2f, 2f) * Mathf.PI * 2.0f; Particle.LaunchForce = new Vector2(Mathf.Cos(Radians), Mathf.Sin(Radians)) * Intensity; Particle.GetsStuck = sticky && Random.value < 0.5; } } private void Start() { Singleton = this; } private GameObject GetGorePrefab() { return Options.CensorGore ? CensoredBloodParticlePrefab : BloodParticlePrefab; } private float GetParticleCountMultiplier() { return Options.CensorGore ? 0.1f : 1.5f; } } }