Example #1
0
        public static void CreateExplosion(Vector3 position, float radius, float power, float heat, Vessel sourceVessel, Vector3 direction, string explModelPath, string soundPath, bool fireExplosionHooks)
        {
            if (fireExplosionHooks)
            {
                ExplosionObject explosionObj = new ExplosionObject(position, radius, power, heat, sourceVessel, direction, explModelPath, soundPath);
                HitManager.FireExplosionHooks(explosionObj);
            }
            GameObject go;
            AudioClip soundClip;

            go = GameDatabase.Instance.GetModel(explModelPath);
            soundClip = GameDatabase.Instance.GetAudioClip(soundPath);

            Quaternion rotation = Quaternion.LookRotation(VectorUtils.GetUpDirection(position));
            GameObject newExplosion = (GameObject)GameObject.Instantiate(go, position, rotation);
            newExplosion.SetActive(true);
            ExplosionFX eFx = newExplosion.AddComponent<ExplosionFX>();
            eFx.exSound = soundClip;
            eFx.audioSource = newExplosion.AddComponent<AudioSource>();
            eFx.audioSource.minDistance = 200;
            eFx.audioSource.maxDistance = 5500;
            eFx.range = radius;

            if(power <= 5)
            {
                eFx.audioSource.minDistance = 4f;
                eFx.audioSource.maxDistance = 3000;
                eFx.audioSource.priority = 9999;
            }
            foreach(KSPParticleEmitter pe in newExplosion.GetComponentsInChildren<KSPParticleEmitter>())
            {
                pe.emit = true;
            }

            DoExplosionDamage(position, power, heat, radius, sourceVessel);
        }
Example #2
0
 public static void FireExplosionHooks(ExplosionObject explosion)
 {
     foreach (Action<ExplosionObject> explosionHook in explosionHooks)
     {
         explosionHook(explosion);
     }
 }