Exemplo n.º 1
0
        void IExplosionModule.OnExplode(ExplosionSystem parent)
        {
            float sqrDistanceToListener = (transform.position - Camera.main.transform.position).sqrMagnitude;

            if (sqrDistanceToListener < nearSoundDistanceThreshold * nearSoundDistanceThreshold)
            {
                if (nearSounds != null && nearSounds.Length > 0)
                {
                    GetComponent <AudioSource>().PlayOneShot(Helpers.RandomFromArray(nearSounds), volume);
                }
            }
            else if (sqrDistanceToListener < mediumSoundDistanceThreshold * mediumSoundDistanceThreshold)
            {
                if (mediumSounds != null && mediumSounds.Length > 0)
                {
                    GetComponent <AudioSource>().PlayOneShot(Helpers.RandomFromArray(mediumSounds), volume);
                }
            }
            else if (sqrDistanceToListener < farSoundDistanceThreshold * farSoundDistanceThreshold)
            {
                if (farSounds != null && farSounds.Length > 0)
                {
                    GetComponent <AudioSource>().PlayOneShot(Helpers.RandomFromArray(farSounds), volume);
                }
            }
        }
Exemplo n.º 2
0
 void IExplosionModule.OnExplode(ExplosionSystem parent)
 {
     if (fxToSpawn != null)
     {
         StartCoroutine(SpawnFX());
     }
 }
Exemplo n.º 3
0
 void IExplosionModule.OnExplode(ExplosionSystem parent)
 {
     if (decal != null)
     {
         instance       = Instantiate(decal, transform.position, transform.rotation) as PyroTechnixDecal;
         initialOpacity = instance.Opacity;
         timer          = 0;
         Destroy(instance.gameObject, fadeDuration);
     }
 }
Exemplo n.º 4
0
        void IExplosionModule.OnExplode(ExplosionSystem parent)
        {
            int amount = Random.Range(minDebrisToSpawn, maxDebrisToSpawn);

            for (int i = 0; i < amount; i++)
            {
                Rigidbody debris = Instantiate(Helpers.RandomFromArray(debrisList), transform.position + Random.onUnitSphere, Random.rotation) as Rigidbody;
                debris.AddExplosionForce(explosiveForce, transform.position, 10);

                float expectedLife = Random.Range(minLifetime, maxLifetime);
                Destroy(debris.gameObject, expectedLife);
            }
        }
Exemplo n.º 5
0
        void IExplosionModule.OnExplode(ExplosionSystem parent)
        {
            GameObject explosionLightObject = new GameObject("light");

            explosionLightObject.transform.parent        = transform;
            explosionLightObject.transform.localPosition = Vector3.zero;
            explosionLightObject.transform.localRotation = Quaternion.identity;

            explosionLight       = explosionLightObject.AddComponent <Light>();
            explosionLight.type  = LightType.Point;
            explosionLight.color = lightColour;
            explosionLight.range = lightRadius;

            StartCoroutine(DoLightingFX());
        }
Exemplo n.º 6
0
        public void OnExplode(ExplosionSystem me)
        {
            lifeExpectancy = Random.Range(minLife, maxLife);

            if (explosionPrefab != null)
            {
                explosionInstance = Instantiate(explosionPrefab, transform.position, transform.rotation) as PyroTechnixExplosion;
                explosionInstance.transform.parent = transform;
            }

            Destroy(gameObject, lifeExpectancy);

            foreach (IExplosionModule module in gameObject.GetInterfaces <IExplosionModule>())
            {
                if (module == this)
                {
                    continue;
                }

                module.OnExplode(this);
            }
        }
Exemplo n.º 7
0
        void IExplosionModule.OnExplode(ExplosionSystem parent)
        {
            if (shockwaveShader == null)
            {
                shockwaveShader = Shader.Find("Hidden/PyroTechnix/Shockwave");
            }

            if (meshInstance == null)
            {
                meshInstance = Helpers.CreateRing(40);
            }

            shockwave = new GameObject("Shockwave");
            shockwave.transform.parent        = transform;
            shockwave.transform.localPosition = Vector3.zero;
            shockwave.transform.localRotation = Quaternion.identity;

            shockwave.AddComponent <MeshFilter>().sharedMesh       = meshInstance;
            shockwave.AddComponent <MeshRenderer>().sharedMaterial = material = new Material(shockwaveShader);
            shockwave.AddComponent <ShockwaveInstance>();

            Destroy(shockwave, duration);
        }
Exemplo n.º 8
0
 void IExplosionModule.OnExplode(ExplosionSystem parent)
 {
     cameraShakeProperties.OriginatingPosition = transform.position;
     Camera.main.SendMessage("MakeMeShake", cameraShakeProperties, SendMessageOptions.DontRequireReceiver);
 }
Exemplo n.º 9
0
        void IExplosionModule.OnExplode(ExplosionSystem parent)
        {
            UpdateOcclusionType();

            var explosionPosition = transform.position;

            offendingColliders = Physics.OverlapSphere(explosionPosition, outerRadius, affectedLayers);
            Collider[] criticalColliders = Physics.OverlapSphere(explosionPosition, criticalRadius);

            foreach (Collider hit in criticalColliders)
            {
                if (!hit)
                {
                    continue;
                }

                hit.SendMessage("OnCriticalExplosionHit", explosionPosition, SendMessageOptions.DontRequireReceiver);
            }

            foreach (Collider hit in offendingColliders)
            {
                if (!hit)
                {
                    continue;
                }

                hit.SendMessage("OnExplosionHit", explosionPosition, SendMessageOptions.DontRequireReceiver);

                if (hit.GetComponent <Rigidbody>())
                {
                    float hitPower = OcclusionAlgorithm(explosionPosition, power, hit);
                    //int numRays = 1;

                    //// Get some points on a circle in the plane tangential to the line between explosion and target (!)
                    //Vector3 forwardDirection = hit.transform.position - explosionPosition;
                    //for (int i = 0; i < NumRaysToCast - 1; i++)
                    //{
                    //    Vector3 relativePosition = Vector3.one;
                    //    Vector3.OrthoNormalize(ref forwardDirection, ref relativePosition);
                    //    relativePosition = Quaternion.AngleAxis(360f * i / NumRaysToCast, forwardDirection) * relativePosition;
                    //    relativePosition *= criticalRadius;

                    //    // If the line from us to the point is clear (otherwise we can get around obstacles by going through the ground etc.)
                    //    if (!Physics.Linecast(explosionPosition, explosionPosition + relativePosition, 1 << LayerMask.NameToLayer("Environment/World")))
                    //    {
                    //        hitPower += OcclusionAlgorithm(explosionPosition + relativePosition, power, hit);
                    //        numRays++;
                    //        Debug.DrawLine(explosionPosition + relativePosition, hit.transform.position, new Color(.3f, .05f, .45f), 0.4f);
                    //    }
                    //}

                    //hitPower = hitPower / numRays;

                    //if (hitPower <= 0.1f) continue;

                    Vector4 explosionInfo = new Vector4(explosionPosition.x, explosionPosition.y, explosionPosition.z, hitPower);
                    SendMessage("OnExplosionForceHit", explosionInfo, SendMessageOptions.DontRequireReceiver);
                    hit.GetComponent <Rigidbody>().AddExplosionForce(hitPower, explosionPosition, outerRadius, 0);
                }
            }
        }
Exemplo n.º 10
0
 void IExplosionModule.OnExplode(ExplosionSystem parent)
 {
     this.parent = parent;
 }