Beispiel #1
0
 void AddCommand(Id id, WaitingCommand command)
 {
     if (!_commandsById.TryAdd(id, command))
     {
         throw new Exception($"Cannot reuse command identifier {id}");
     }
 }
Beispiel #2
0
        async Task <TResponse> WaitForResponse <TResponse>(Id id, IEnumerable <ICommandWhen <TResponse> > whens)
        {
            var command = new WaitingCommand <TResponse>(whens);

            AddCommand(id, command);

            try
            {
                return(await command.Task);
            }
            finally
            {
                RemoveCommand(id);
            }
        }
Beispiel #3
0
    //行動状態変数を初期化
    public void Initialize(GameObject usingObj)
    {
        PlayerCommandBase[] command = new PlayerCommandBase[15];
        waitingCommand             = usingObj.AddComponent <WaitingCommand>();
        runningCommand             = usingObj.AddComponent <RunningCommand>();
        slideRunningCommand        = usingObj.AddComponent <SlideRunningCommand>();
        jumpingFirstCommand        = usingObj.AddComponent <JumpingFirstCommand>();
        jumpingSecondCommand       = usingObj.AddComponent <JumpingSecondCommand>();
        jumpingWithUpToDownCommand = usingObj.AddComponent <JumpingWithUpToDownCommand>();
        slideJumpingCommand        = usingObj.AddComponent <SlideJumpingCommand>();
        wallJumpingCommand         = usingObj.AddComponent <WallJumpingCommand>();
        cliffHoldingCommand        = usingObj.AddComponent <CliffHoldingCommand>();
        attackingFirstCommand      = usingObj.AddComponent <AttackingFirstCommand>();
        attackingSecondCommand     = usingObj.AddComponent <AttackingSecondCommand>();
        attackingThirdCommand      = usingObj.AddComponent <AttackingThirdCommand>();
        attackingInAirCommand      = usingObj.AddComponent <AttackingInAirlialCommand>();
        nockBackingCommand         = usingObj.AddComponent <NockBackingCommand>();
        dyingCommand = usingObj.AddComponent <DyingCommand>();
        command[0]   = waitingCommand;
        command[1]   = runningCommand;
        command[2]   = slideRunningCommand;
        command[3]   = jumpingFirstCommand;
        command[4]   = jumpingSecondCommand;
        command[5]   = jumpingWithUpToDownCommand;
        command[6]   = slideJumpingCommand;
        command[7]   = wallJumpingCommand;
        command[8]   = cliffHoldingCommand;
        command[9]   = attackingFirstCommand;
        command[10]  = attackingSecondCommand;
        command[11]  = attackingThirdCommand;
        command[12]  = attackingInAirCommand;
        command[13]  = nockBackingCommand;
        command[14]  = dyingCommand;
        for (int i = 0; i < command.Length; i++)
        {
            command[i].Initialize(usingObj);
        }

        PlayerStateEntry[] move = new PlayerStateEntry[3];
        waiting      = usingObj.AddComponent <Waiting>();
        running      = usingObj.AddComponent <Running>();
        slideRunning = usingObj.AddComponent <SlideRunning>();
        move[0]      = waiting;
        move[1]      = running;
        move[2]      = slideRunning;
        for (int i = 0; i < move.Length; i++)
        {
            move[i].SubInitialize(usingObj);
        }

        PlayerStateEntry[] jump = new PlayerStateEntry[6];
        jumpingFirst        = usingObj.AddComponent <JumpingFirst>();
        jumpingSecond       = usingObj.AddComponent <JumpingSecond>();
        jumpingWithUpToDown = usingObj.AddComponent <JumpingWithUpToDown>();
        slideJumping        = usingObj.AddComponent <SlideJumping>();
        wallJumping         = usingObj.AddComponent <WallJumping>();
        cliffHolding        = usingObj.AddComponent <CliffHolding>();
        jump[0]             = jumpingFirst;
        jump[1]             = jumpingSecond;
        jump[2]             = jumpingWithUpToDown;
        jump[3]             = slideJumping;
        jump[4]             = wallJumping;
        jump[5]             = cliffHolding;
        for (int i = 0; i < jump.Length; i++)
        {
            jump[i].SubInitialize(usingObj);
        }

        PlayerStateEntry[] damage = new PlayerStateEntry[2];
        nockBacking = usingObj.AddComponent <NockBacking>();
        dying       = usingObj.AddComponent <Dying>();
        damage[0]   = nockBacking;
        damage[1]   = dying;
        for (int i = 0; i < damage.Length; i++)
        {
            damage[i].SubInitialize(usingObj);
        }

        PlayerStateEntry[] attack = new PlayerStateEntry[4];
        attackingFirst  = usingObj.AddComponent <AttackingFirst>();
        attackingSecond = usingObj.AddComponent <AttackingSecond>();;
        attackingThird  = usingObj.AddComponent <AttackingThird>();;
        attackingInAir  = usingObj.AddComponent <AttackingInAirlial>();;
        attack[0]       = attackingFirst;
        attack[1]       = attackingSecond;
        attack[2]       = attackingThird;
        attack[3]       = attackingInAir;
        for (int i = 0; i < attack.Length; i++)
        {
            attack[i].SubInitialize(usingObj);
        }

        PlayerStateEntry[] main = new PlayerStateEntry[4];
        moving    = usingObj.AddComponent <PlayerMovingStateMachine>();
        jumping   = usingObj.AddComponent <PlayerJumpingStateMachine>();
        attacking = usingObj.AddComponent <PlayerAttackingStateMachine>();
        damaging  = usingObj.AddComponent <PlayerDamagingStateMachine>();
        main[0]   = moving;
        main[1]   = jumping;
        main[2]   = attacking;
        main[3]   = damaging;
        for (int i = 0; i < main.Length; i++)
        {
            main[i].SubInitialize(usingObj);
        }

        usingObj.GetComponent <PlayerStateMachine>().SubInitialize(usingObj);
    }