Exemple #1
0
    //切换武器是, 更换武器的类型, 取消之前的监听, 注册监听新的事件
    public void SwitchWeapon()
    {
        switch (dropDown.value)
        {
        case 0:
            inputController.SetStrategy(InputType.Normal);
            StrategyNormal strategyNormal = (StrategyNormal)inputController.currentStrategy;
            strategyNormal.inputFire.fireAction += PlayerFire;
            break;

        case 1:
            inputController.SetStrategy(InputType.Fire);
            StrategyFire strategyFire = (StrategyFire)inputController.currentStrategy;
            strategyFire.inputFire.fireAction  += PlayerFire;
            strategyFire.inputThrow.dragAction += PlayerDrag;
            break;

        case 2:
            inputController.SetStrategy(InputType.Charge);
            StrategyCharge strategyCharge = (StrategyCharge)inputController.currentStrategy;
            strategyCharge.inputCharge.fireAction += PlayerFire;
            strategyCharge.inputThrow.dragAction  += PlayerDrag;
            break;

        case 3:
            inputController.SetStrategy(InputType.Throw);
            StrategyThrow strategyThrow = (StrategyThrow)inputController.currentStrategy;
            strategyThrow.inputThrow.dragAction += PlayerDrag;
            break;
        }
    }
Exemple #2
0
    private void Start()
    {
        //初始化每个输入模块
        inputController.InitInputController();
        //设置默认模块
        inputController.SetStrategy(InputType.Normal);
        //注册和监听相关事件
        StrategyNormal strategy = (StrategyNormal)inputController.currentStrategy;

        strategy.inputFire.fireAction += PlayerFire;
        //初始化攻击模式的UI显示
    }