//该组件主要食用方法:通过RequestChangeControlStatus判断能否执行下一个状态,如果可以,通过RequestMove申请移动 //请求执行下一个状态,switch-case分支列举了不同状态下,能够转换成哪些状态的规则(考虑表示成状态转移矩阵) //同时会改变can系列参数,控制在某种状态下能够接受哪些移动,不能接受哪些移动 //Time参数表示该状态最多持续多长时间,如果时间到了则会转移成Normal状态 //当status == 0时,表示单帧申请状态改变,现在只有申请持续施法会这样做 public bool RequestChangeControlStatus(float statusTime, PlayerControlStatus status) { if (status == PlayerControlStatus.Crouch) { if (controlStatus == PlayerControlStatus.Normal || controlStatus == PlayerControlStatus.Crouch) { isRequestCrouch = true; return(true); } } switch (controlStatus) { case PlayerControlStatus.Normal: if (isOnFloor || isInWater) { ChangeControlStatus(statusTime, status); return(true); } else { if (status == PlayerControlStatus.Crouch) { return(false); } else { ChangeControlStatus(statusTime, status); return(true); } } //case PlayerControlStatus.InWater: // if(status == PlayerControlStatus.Normal || // status == PlayerControlStatus.Crouch || // status == PlayerControlStatus.AbilityNeedControl || // status == PlayerControlStatus.AbilityWithMovement || // status == PlayerControlStatus.Stun || // status == PlayerControlStatus.Interrupt) // { // ChangeControlStatus(statusTime, status); // return true; // } // return false; case PlayerControlStatus.Crouch: if (status == PlayerControlStatus.Normal || status == PlayerControlStatus.Interrupt || status == PlayerControlStatus.Stun || status == PlayerControlStatus.Crouch) { ChangeControlStatus(statusTime, status); return(true); } return(false); case PlayerControlStatus.Casting: if (status == PlayerControlStatus.Normal || status == PlayerControlStatus.Stun || status == PlayerControlStatus.AbilityWithMovement || status == PlayerControlStatus.AbilityNeedControl) { ChangeControlStatus(statusTime, status); return(true); } return(false); case PlayerControlStatus.AbilityNeedControl: case PlayerControlStatus.AbilityWithMovement: if (status == PlayerControlStatus.Normal || status == PlayerControlStatus.Stun) { ChangeControlStatus(statusTime, status); return(true); } return(false); //暂时设定打断\眩晕状态下不允许被打断,眩晕状态下眩晕允许且时间刷新 case PlayerControlStatus.Interrupt: case PlayerControlStatus.Stun: if (status == PlayerControlStatus.Normal || status == PlayerControlStatus.Stun) { ChangeControlStatus(statusTime, status); return(true); } return(false); } return(false); }
//修改当前状态的私有方法;在修改当前状态的同时,把Can系列的状态为设置,保证在某些状态下屏蔽掉低优先级的请求 //(比如在眩晕的时候请求释放技能);同时,将低优先级的计时器状态设置为false(is系列状态位),保证进行高优先级计时器是 //低优先级计时器不在工作(比如0.5s眩晕状态会终止1s的技能释放状态,否则0.5s眩晕结束后,技能没有被打断,仍然处在技能移动状态下) private void ChangeControlStatus(float statusTime, PlayerControlStatus status) { //如果是需要计时的状态,则重置计时器 if (status != PlayerControlStatus.Normal && status != PlayerControlStatus.Crouch) { isInAbnormalStatus = true; controlStatusTotalTime = statusTime; controlStatusCurTime = 0f; } //否则不需要重置计时器 else { isInAbnormalStatus = false; controlStatusTotalTime = 0f; controlStatusCurTime = 0f; } controlStatus = status; //只有状态改变时才告诉动画机转换状态 playerAnim.SetStatus(controlStatus); switch (status) { case PlayerControlStatus.Normal: canPassiveTransport = true; canActiveTransport = true; canAbilityMovement = true; canPassiveMovement = true; canControllorMovement = true; isAbilityMovement = false; isPassiveMovement = false; isInAbnormalStatus = false; break; case PlayerControlStatus.Crouch: canPassiveMovement = true; canActiveTransport = false; canAbilityMovement = false; canPassiveMovement = true; canControllorMovement = true; isAbilityMovement = false; isPassiveMovement = false; isInAbnormalStatus = false; break; case PlayerControlStatus.Casting: canPassiveMovement = true; canActiveTransport = true; canAbilityMovement = true; canPassiveMovement = true; canControllorMovement = true; isPassiveMovement = false; isControllorMovement = false; isInAbnormalStatus = true; break; case PlayerControlStatus.AbilityWithMovement: canPassiveMovement = true; canActiveTransport = true; canAbilityMovement = true; canPassiveMovement = true; canControllorMovement = false; isPassiveMovement = false; isControllorMovement = false; isInAbnormalStatus = true; break; case PlayerControlStatus.AbilityNeedControl: canPassiveMovement = true; canActiveTransport = true; canAbilityMovement = true; canPassiveMovement = true; canControllorMovement = true; isPassiveMovement = false; isInAbnormalStatus = true; break; case PlayerControlStatus.Interrupt: case PlayerControlStatus.Stun: canPassiveMovement = true; canActiveTransport = false; canAbilityMovement = false; canPassiveMovement = true; canControllorMovement = false; isAbilityMovement = false; isPassiveMovement = false; isControllorMovement = false; isInAbnormalStatus = true; break; } }