private IEnumerator Fire(IBulletModel model)
    {
        while (GameStateModel.Single.GameState == GameState.NULL)
        {
            yield return(new WaitForSeconds(0.2f));
        }

        var audioName = model.AudioName.ToString();

        AudioMgr.Single.Play(audioName, true);
        var start = DateTime.Now;

        while (true)
        {
            yield return(new WaitForSeconds(model.FireTime));

            model.Trajectory(data =>
            {
                for (int i = 0; i < data.Length; i++)
                {
                    Spawn(i, data.Length, model, data[i]);
                }
            });

            //开火暂停时间
            if ((DateTime.Now - start).TotalSeconds >= Const.FIRE_DURATION)
            {
                AudioMgr.Single.PauseDelay(audioName);
                yield return(new WaitForSeconds(Const.FIRE_CD_TIME));

                start = DateTime.Now;
                AudioMgr.Single.Replay(audioName);
            }
        }
    }
 public void Init(IBulletModel model)
 {
     if (model is IEnemyBossBulletModel)
     {
         _bulletModel = model as IEnemyBossBulletModel;
         MsgMgr.AddListener(MsgEvent.EVENT_HP, ReceiveLifeMsg);
     }
 }
    private void Spawn(int index, int count, IBulletModel model, ITrajectory trajectory)
    {
        if (PoolMgr.Single == null)
        {
            return;
        }
        var bulletGo = PoolMgr.Single.Spawn(Paths.PREFAB_BULLET);
        var bullet   = bulletGo.AddOrGet <Bullet>();

        bullet.Init(model, trajectory, _pointMgr.GetPoints(count, transform.position)[index]);
    }
    private void Init(IBulletModel model)
    {
        if (model == null)
        {
            return;
        }
        _model = model;
        if (GetAttack() > 0)
        {
            _id = CoroutineMgr.Single.ExecuteOnce(Fire(model));
        }

        InitComponent();

        InitPos(model);
    }
    private void InitPos(IBulletModel model)
    {
        model.Trajectory((trajectorys) =>
        {
            var bulletDirection   = trajectorys[0].GetDirection();
            Vector2 selfDirection = transform.position - transform.parent.position;
            var angle             = Vector2.Angle(selfDirection, bulletDirection);

            var pos = transform.localPosition;
            if (angle > 90)
            {
                pos.y = -pos.y;
            }

            transform.localPosition = pos;
        });
    }
Esempio n. 6
0
    public void Init(IBulletModel model, ITrajectory trajectory, Vector3 pos)
    {
        if (_renderer == null)
        {
            _renderer = GetComponent <SpriteRenderer>();
        }
        _model           = model;
        _renderer.sprite = model.Sprite();
        _trajectory      = trajectory;
        SetPos(pos);

        if (_effectMgr == null)
        {
            _effectMgr = gameObject.AddComponent <BulletEffectMgr>();
        }
        _effectMgr.Init(model.Type);

        _model.GetBulletSpeed(value =>
        {
            _move = gameObject.AddOrGet <MoveComponent>();
            _move.Init(value);
        });
    }
    public void Init(BulletType type)
    {
        IBulletModel model = BulletUtil.GetBulletModel(type);

        Init(model);
    }