示例#1
0
        private void Update()
        {
            _countdown -= Time.deltaTime;

            if (!(_countdown <= 0f))
            {
                return;
            }
            OnExplode?.Invoke();
            Destroy(gameObject);
        }
示例#2
0
        IEnumerator AnimateExplosion()
        {
            var explosionsLeft = animationParameters.explosionsCount.GetRandomValue();

            while (explosionsLeft > 0)
            {
                OnExplode.Dispatch();
                MakeSingleExplosion();
                explosionsLeft--;
                yield return(new WaitForSecondsRealtime(animationParameters.delaysBetweenExplosions.GetRandomValue()));
            }
        }
示例#3
0
        public IEnumerable <SpacialElement> Explode()
        {
            var ret = new List <SpacialElement>();

            if (Lifetime.IsExpired)
            {
                return(ret);
            }

            this.Lifetime.Dispose();
            var shrapnelSet = new List <Projectile>();

            for (float angle = 0; angle < 360; angle += AngleIncrement)
            {
                var effectiveRange = Range;

                if ((angle > 200 && angle < 340) || (angle > 20 && angle < 160))
                {
                    effectiveRange = Range / 3;
                }

                var shrapnel = SpaceTime.CurrentSpaceTime.Add(new Projectile(this.Weapon, ExplosiveProjectileSpeed, angle, autoLocate: false)
                {
                    Range = effectiveRange
                });
                shrapnel.AddTag(nameof(Explosive));
                shrapnel.MoveTo(this.Left, this.Top, this.ZIndex);
                OnProjectileAdded.Fire(shrapnel);
                if (ProjectilePen != null)
                {
                    shrapnel.Pen = ProjectilePen;
                }

                shrapnelSet.Add(shrapnel);
                shrapnel.AddTag("hot");
                ret.Add(shrapnel);
            }

            foreach (var shrapnel in shrapnelSet)
            {
                shrapnel.Velocity.HitDetectionExclusions.AddRange(shrapnelSet.Where(s => s != shrapnel));
            }

            Exploded.Fire();
            OnExplode.Fire(this);
            return(ret);
        }
示例#4
0
        public void Explode()
        {
            var shrapnelSet = new List <Projectile>();

            for (float angle = 0; angle < 360; angle += AngleIncrement)
            {
                var effectiveRange = Range;

                if ((angle > 200 && angle < 340) || (angle > 20 && angle < 160))
                {
                    effectiveRange = Range / 3;
                }

                var shrapnel = SpaceTime.CurrentSpaceTime.Add(new Projectile(this.Weapon, this.Left, this.Top, angle)
                {
                    Range = effectiveRange
                });
                shrapnel.MoveTo(shrapnel.Left, shrapnel.Top, this.ZIndex);
                OnProjectileAdded.Fire(shrapnel);
                if (ProjectilePen != null)
                {
                    shrapnel.Pen = ProjectilePen;
                }

                shrapnelSet.Add(shrapnel);
                shrapnel.Tags.Add("hot");
            }

            foreach (var shrapnel in shrapnelSet)
            {
                shrapnel.Speed.HitDetectionExclusions.AddRange(shrapnelSet.Where(s => s != shrapnel));
            }

            Exploded.Fire();
            OnExplode.Fire(this);
            this.Lifetime.Dispose();
        }
    public void Explode()
    {
        var hitted = new HashSet <Destructable>();
        var pos    = transform.position;

        foreach (var damage in damages)
        {
            var colliders = Physics.OverlapSphere(pos, damage.radius);

            foreach (var collider in colliders)
            {
                var dest = collider.GetComponent <Destructable>();
                if (dest != null && !hitted.Contains(dest))
                {
                    hitted.Add(dest);
                    dest.Hit(damage.hitPower);
                }
            }
        }

        gameObject.SetActive(false);

        OnExplode?.Invoke();
    }
示例#6
0
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(gameTime);
            if (counter > 0)
            {
                counter -= gameTime.ElapsedGameTime.Milliseconds;

                ledSegment[0].SetValue((uint)((counter % 1000) / 100));
                ledSegment[1].SetValue((uint)((counter % 10000) / 1000));
                if (counter < 10000)
                {
                    ledSegment[2].Visible = false;
                }
                else
                {
                    ledSegment[2].SetValue((uint)((counter % 100000) / 10000));
                }

                if (counter <= 0)
                {
                    OnExplode.Invoke(this);
                }
            }
        }
示例#7
0
 private void Explode()
 {
     OnExplode?.Invoke();
     Destroy(gameObject);
 }
示例#8
0
 protected void explode()
 {
     explosion.Explode();
     OnExplode?.Invoke(this);
 }
        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);
                }
            }

            //---------------------------------------------------------------
        }
示例#10
0
 public void Explode()
 {
     //Create Explosion
     OnExplode?.Invoke();
     Destroy(gameObject);
 }
 private void Explode()
 {
     //effect.GetComponent<Light>().enabled = false;
     effect.GetComponentInChildren <ParticleSystem>().Stop();
     OnExplode?.Invoke();
 }