Example #1
0
    //子弹爆炸,销毁子弹
    protected virtual void DoBulletBomb()
    {
        if (InCache)
        {
            return;
        }

        //播放爆炸特效
        if (Deploy.bombEffectId > 0)
        {
            var pos     = Renderer.transform.position;
            var forward = MoveData.Forward;
            var speed   = Deploy.bombEffectSpeed;
            TextureEffectFactroy.CreateEffect(Deploy.bombEffectId, SortingOrder.EnemyBullet, effect =>
            {
                effect.transform.position = pos;
                effect.AutoDestroy();
                if (speed > 0)
                {
                    effect.SetAutoMove(forward, speed);
                }
            });
        }

        //销毁子弹
        BulletFactory.DestroyBullet(this);
    }
Example #2
0
    public void FixUpdateShoot(bool isSlow, int layer, bool inShoot)
    {
        var shootFrame  = isSlow ? Deploy.slowFrame : Deploy.fastFrame;
        var bulletId    = isSlow ? Deploy.slowBulletId : Deploy.fastBulletId;
        var atk         = isSlow ? Deploy.slowAtk : Deploy.fastAtk;
        var bulletSpeed = isSlow ? Deploy.slowSpeed : Deploy.fastSpeed;

        if (_prevInSlow != isSlow)
        {
            _prevInSlow = isSlow;
            if (_currBullet != null)
            {
                BulletFactory.DestroyBullet(_currBullet);
                _currBullet = null;
            }
            _prevInLoopShoot = false;
            NextShootFrame   = GameSystem.FixedFrameCount + shootFrame;
        }

        _slowEffect?.SetActiveSafe(inShoot && isSlow);
        _fastEffect?.SetActiveSafe(inShoot && !isSlow);

        if (shootFrame > 0)
        {
            //正常类型,持续射击
            if (inShoot)
            {
                if (GameSystem.FixedFrameCount > NextShootFrame)
                {
                    NextShootFrame = GameSystem.FixedFrameCount + shootFrame;
                    BulletFactory.CreateBullet(bulletId, transform, layer, bullet =>
                    {
                        var data = MoveData.New(transform.position, MathUtility.SwapYZ(transform.forward), bulletSpeed);
                        bullet.Shoot(data, atk: atk);
                    });
                }
            }
        }
        else
        {
            //射击间隔为0的,表示激光类型,射击状态下持续显示,非射击销毁
            if (!_prevInLoopShoot && inShoot)
            {
                BulletFactory.CreateBullet(bulletId, transform, layer, bullet =>
                {
                    _currBullet = bullet;
                    bullet.Shoot(MoveData.New(transform.position, transform.up, bulletSpeed), atk: atk);
                });
            }
            if (_prevInLoopShoot && !inShoot)
            {
                if (_currBullet != null)
                {
                    BulletFactory.DestroyBullet(_currBullet);
                    _currBullet = null;
                }
            }
            _prevInLoopShoot = inShoot;
        }
    }
Example #3
0
 void RemoveLastProjectiles()
 {
     while (m_lastProjectiles.Count > 0)
     {
         BulletFactory.DestroyBullet(m_lastProjectiles[0]);
         //Destroy(m_lastProjectiles[0]);
         m_lastProjectiles.RemoveAt(0);
     }
 }
Example #4
0
 protected bool CheckBulletOutSide(Vector3 bulletCenter)
 {
     //超出边界销毁
     if (bulletCenter.x < -15f || bulletCenter.x > 5f || bulletCenter.y < -12f || bulletCenter.y > 12f)
     {
         BulletFactory.DestroyBullet(this);
         return(true);
     }
     return(false);
 }
Example #5
0
 public void Destroy()
 {
     if (_currBullet != null)
     {
         BulletFactory.DestroyBullet(_currBullet);
         _currBullet = null;
     }
     if (_slowEffect != null)
     {
         TextureEffectFactroy.DestroyEffect(_slowEffect);
         _slowEffect = null;
     }
     if (_fastEffect != null)
     {
         TextureEffectFactroy.DestroyEffect(_fastEffect);
         _fastEffect = null;
     }
     Destroy(gameObject);
 }
Example #6
0
    //检测玩家死亡时,是否需要自我销毁并播放特效
    private bool CheckBulletExplosion()
    {
        if (!BulletExplosion.InExplosion)
        {
            return(false);
        }
        var pos     = CacheTransform.position;
        var radius  = BulletExplosion.Radius;
        var sqrDist = MathUtility.SqrDistanceXY(pos, BulletExplosion.Center);

        if (sqrDist < radius * radius)
        {
            BulletFactory.DestroyBullet(this);
            TextureEffectFactroy.CreateEffect(501, SortingOrder.ShootEffect, effect =>
            {
                effect.Renderer.material.SetColor("_TintColor", ColorUtility.GetColor(Deploy.ExplosionColor));
                effect.transform.position = pos;
                effect.AutoDestroy();
            });
            return(true);
        }
        return(false);
    }
Example #7
0
    public void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Enemy")
        {
            //Debug.Log(gameObject.name + " collided with " + collision.gameObject.name);


            var rocketScript = collision.gameObject.GetComponent <Rocket>();
            if (rocketScript == null)
            {
                // ROCKET HIT BULLET
                BulletFactory.DestroyBullet(collision.gameObject);
                var thisRocketScript = gameObject.GetComponent <Rocket>();

                if (thisRocketScript != null)
                {
                    thisRocketScript.HitByOther();
                }
                return;
            }

            // BAT HIT ROCKET
            // OR ROCKET HIT ROCKET
            // reverse rocket direction
            // set explosion time
            collision.gameObject.GetComponent <Rocket>().HitByBat();

            audioSource.pitch = Random.Range(lowPitchRange, highPitchRange);
            float hitVol = collision.relativeVelocity.magnitude * velToVol;
            if (hitVol > 1f)
            {
                hitVol = 1f;
            }

            // don't play the bat sound if one has just started playing
            if (audioSource.isPlaying && audioSource.timeSamples < 3000)
            {
                return;
            }

            audioSource.PlayOneShot(SoundFX.BatHitFx, hitVol);

            CollectableTaken();

            //audioSource.pitch = Random.Range(0.8f, 1.2f);
            //audioSource.volume = hitVol;
            //RocketFactory.DestroyRocket(collision.gameObject);
        }
        else if (collision.gameObject.tag == "Other")
        {
            //Debug.Log("Collided with projectile");

            // reverse rocket direction
            // set explosion time
            collision.gameObject.GetComponent <Rocket>().HitByOther();

            audioSource.pitch = Random.Range(lowPitchRange, highPitchRange);
            float hitVol = collision.relativeVelocity.magnitude * velToVol;

            audioSource.PlayOneShot(SoundFX.MissileExplosion, hitVol);

            //audioSource.pitch = Random.Range(0.8f, 1.2f);
            //audioSource.volume = hitVol;
            //RocketFactory.DestroyRocket(collision.gameObject);
        }
    }
Example #8
0
    private void UpdateEventList()
    {
        if (EventList == null || EventList.Count == 0)
        {
            return;
        }

        for (int i = EventList.Count - 1; i >= 0; i--)
        {
            var e = EventList[i];
            switch (e.Type)
            {
            case EventData.EventType.Frame_Destroy:

                if (_totalFrame >= e.FrameCount)
                {
                    EventList.RemoveAt(i);
                    BulletFactory.DestroyBullet(this);
                }
                break;

            case EventData.EventType.Frame_ChangeSpeed:

                if (_totalFrame >= e.FrameCount)
                {
                    MoveData.EndSpeed     = e.SpeedData.EndSpeed;
                    MoveData.Acceleration = e.SpeedData.Acceleration;

                    if (e.SpeedData.Speed > 0f)
                    {
                        MoveData.Speed = e.SpeedData.Speed;
                    }
                    EventList.RemoveAt(i);
                }
                break;

            case EventData.EventType.Frame_ChangeForward:

                if (_totalFrame >= e.FrameCount)
                {
                    MoveData.Forward          = e.ForwardData.Forward;
                    MoveData.HelixRefretFrame = e.ForwardData.HelixRefretFrame;
                    MoveData.HelixToward      = e.ForwardData.HelixToward;
                    MoveData.EulurPerFrame    = e.ForwardData.EulurPerFrame;
                    EventList.RemoveAt(i);
                }
                break;

            case EventData.EventType.Distance_ChangeFoward:
                if (_movedDistance >= e.Distance)
                {
                    MoveData.Forward          = e.ForwardData.Forward;
                    MoveData.HelixRefretFrame = e.ForwardData.HelixRefretFrame;
                    MoveData.HelixToward      = e.ForwardData.HelixToward;
                    MoveData.EulurPerFrame    = e.ForwardData.EulurPerFrame;
                    EventList.RemoveAt(i);
                }
                break;
            }
        }
    }
Example #9
0
 public void DestroyProjectile()
 {
     BulletFactory.DestroyBullet(gameObject);
 }