Esempio n. 1
0
 public void Explode()
 {
     //SoundManager.Instance.Play(audioSource,SoundManager.Sound.PlayerExplode);
     SoundManager.Instance.Play(SoundManager.Sound.PlayerExplode);
     Debug.Assert(GameManager.Instance.playerSpaceshipHp <= 0, "HP is more than zero");
     Destroy(gameObject);
     OnExploded?.Invoke();
 }
 public void Explode()
 {
     SoundManager.Instance.Play(SoundManager.Sound.EnemyExplode);
     Debug.Assert(Hp <= 0, "HP is more than zero");
     gameObject.SetActive(false);
     Destroy(gameObject);
     OnExploded?.Invoke();
 }
Esempio n. 3
0
 public void Explode()
 {
     SoundManager.Instance.Play(SoundManager.Sound.Planet);
     Debug.Assert(Hp <= 0, "HP is more than zero");
     gameObject.SetActive(false);
     OnExploded?.Invoke();
     GameManager.Instance.playerSpaceshipHp += 40;
     Destroy(gameObject);
 }
Esempio n. 4
0
 private void T_Exploded(object sender, EventArgs e)
 {
     timer.Stop();
     foreach (var item in Tiles)
     {
         item.Reveal();
     }
     ExplodedTile = sender as Tile;
     OnExploded?.Invoke(sender, null);
 }
        private IEnumerator explodey(explosionType explosiontype, Vector3 position, float power, float radius)
        {
            if (StatMaster.isClient)
            {
                yield break;
            }

            if (isExplodey)
            {
                yield break;
            }
            else
            {
                fireEffect = getExplodeEffectObject(explosiontype);
                if (ExplosionType == explosionType.Big)
                {
                    fireEffect.transform.FindChild("Debris").localRotation = Quaternion.AngleAxis(UnityEngine.Random.Range(0f, 360f), Vector3.up);
                }
                fireEffect.transform.position = position;

                if (!StatMaster.isClient)
                {
                    var message = ExplodyMessage.CreateMessage((int)explosiontype, position);
                    ModNetworking.SendToAll(message);
                }
            }

            yield return(new WaitForFixedUpdate());

            isExplodey = true;
            fireEffect.SetActive(true);
            OnExplode?.Invoke();

            //定义爆炸位置为炸弹位置
            Vector3 explosionPos = position;

            //这个方法用来返回球型半径之内(包括半径)的所有碰撞体collider[]
            Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);

            //遍历返回的碰撞体,如果是刚体,则给刚体添加力
            foreach (Collider hit in colliders)
            {
                if (hit.attachedRigidbody != null)
                {
                    float force = UnityEngine.Random.Range(30000f, 50000f) * power * (Vector3.Distance(hit.transform.position, explosionPos) / (radius + 0.25f));
                    hit.attachedRigidbody.AddExplosionForce(force, explosionPos, radius);
                    hit.attachedRigidbody.AddTorque(force * Vector3.Cross((hit.transform.position - explosionPos), Vector3.up));

                    reduceBlockHealth(hit.attachedRigidbody.gameObject);
                }
            }

            OnExploded?.Invoke(colliders);
            yield return(new WaitForSeconds(3f));

            fireEffect.SetActive(false);
            OnExplodeFinal?.Invoke();
            //-------------------------------------------------------------
            void reduceBlockHealth(GameObject gameObject)
            {
                var bhb = gameObject.GetComponent <BlockHealthBar>();

                if (bhb != null)
                {
                    bhb.DamageBlock(1);
                }
            }

            //---------------------------------------------------------------
        }
Esempio n. 6
0
        /// <summary>
        /// Explodes the sprite after a delay.
        /// </summary>
        /// <param name="explosionCenter">The center position of the explosion. Vector3.zero is the center of the sprite.</param>
        /// <returns></returns>
        IEnumerator ExplodeCoroutine(Vector3 explosionCenter)
        {
            yield return(new WaitForSeconds(delaySeconds)); // Wait for delay seconds

            // If the explosion has already occurred, break the coroutine.
            if (isExploded)
            {
                yield break;
            }
            isExploded = true;

            // If the max particle count is only one, then complete explosion.
            int maxParticleCount = GetMaxParticleCount();

            if (maxParticleCount <= 1)
            {
                LocalSpriteRenderer.enabled = false;
                OnExploded?.Invoke();
                yield break;
            }

            // Set the amount of x and y subdivisions will be used. Similar to defining
            // the size of a grid.
            int subdivisionCountX = GetSubdivisionCountX();
            int subdivisionCountY = GetSubdivisionCountY();

            // Disable the sprite renderer so that particle textures will be seen instead.
            LocalSpriteRenderer.enabled = false;

            // Get a reference to the sprite renderer sprite and set bound size values.
            Sprite sprite         = LocalSpriteRenderer.sprite;
            float  boundSizeX     = sprite.bounds.size.x;
            float  boundSizeY     = sprite.bounds.size.y;
            float  halfBoundSizeX = boundSizeX * 0.5f;
            float  halfBoundSizeY = boundSizeY * 0.5f;

            // Set the flip values the particles will use.
            float flipX = LocalSpriteRenderer.flipX ? -1.0f : 1.0f;
            float flipY = LocalSpriteRenderer.flipY ? -1.0f : 1.0f;

            // Set the max particle size. We want the particles to be square.
            // So, this grabs the biggest size from either the width of height values.
            float particleSizeMax = GetMaxParticleSize();

            // Set the amount of particles that will generated.
            int particleCount = GetMaxParticleCount();

            // Set the base particle offset values.
            float offsetX = -halfBoundSizeX * (1.0f - (1.0f / subdivisionCountX));
            float offsetY = -halfBoundSizeY * (1.0f - (1.0f / subdivisionCountY));

            // Define tile coordinate vars.
            int tileX;
            int tileY;

            // Create particle emission paramaters.
            ParticleSystem.EmitParams emitParams = new ParticleSystem.EmitParams();

            // Define custom particle data var.
            List <Vector4> custom1ParticleDatas = new List <Vector4>(particleCount);

            // Define the base velocity var.
            Vector3 baseVelocity = Vector3.zero;

            // Set base velocity values from the attached rigid body if it exists.
            Rigidbody2D rigidbody2d = GetComponent <Rigidbody2D>();

            if (rigidbody2d != null)
            {
                Vector2 rigidbodyVelocity = rigidbody2d.velocity;
                baseVelocity.x = rigidbodyVelocity.x;
                baseVelocity.y = rigidbodyVelocity.y;
            }

            // Set the local scale value.
            Vector3 lossyScale = transform.lossyScale;

            // Emit all the particle tiles in a for loop.
            for (int tileIndex = 0; tileIndex < particleCount; tileIndex++)
            {
                // Set the tile coordinates based on index and the number of subdivisions.
                tileX = GetTileX(tileIndex, subdivisionCountX);
                tileY = GetTileY(tileIndex, subdivisionCountY);

                // Set the tile position and then apply rotation to the values.
                Vector3 localPosition = new Vector3();
                localPosition.x = (tileX * lossyScale.x * particleSizeMax) + offsetX * lossyScale.x;
                localPosition.y = (tileY * lossyScale.y * particleSizeMax) + offsetY * lossyScale.y;
                localPosition   = transform.rotation * localPosition;

                // Set the emit params position with local position offset plus the world position.
                Vector3 worldPosition = localPosition + transform.position;
                emitParams.position = worldPosition;

                // Set a random outward velocity to apply to the particle tile.
                Vector3 outwardVelocity = localPosition - explosionCenter;
                if (collisionMode == SpriteExploderCollisionMode.Collision3D)
                {
                    outwardVelocity.z = UnityEngine.Random.Range(-halfBoundSizeX * 0.5f, halfBoundSizeX * 0.5f);
                }
                outwardVelocity *= UnityEngine.Random.Range(MinExplosiveStrength, MaxExplosiveStrength);

                // Set the emit params velocity with the base velocity of the rigid body plus the outward explosion velocity.
                emitParams.velocity = baseVelocity + outwardVelocity;

                // Emit the particle tile.
                LocalParticleSystem.Emit(emitParams, 1);

                // Add to the custom particle data array.
                // This is used to pass the tile index to the shader.
                // A Vector4 is required to pass this type of data.
                // In this case, we only need to use the first value since we only have one index value to pass.
                custom1ParticleDatas.Add(new Vector4(tileIndex, 0.0f, 0.0f, 0.0f));
            }

            // Set the custom particle data for all the particles.
            LocalParticleSystem.SetCustomParticleData(custom1ParticleDatas, ParticleSystemCustomData.Custom1);

            // Invoke exploded event
            OnExploded?.Invoke();
        }
 private void Exploded(Collider[] colliders)
 {
     OnExploded?.Invoke();
 }