public override void Filter(IAdaptiveContainer <IFsmInputCommand> commands) { for (int i = 0; i < commands.Length; ++i) { Filter(commands[i]); } }
public void FromAvatarAnimToWeaponAnimProgress(IAdaptiveContainer <IFsmInputCommand> commands, GameObject weaponP1, GameObject weaponP3, IWeaponAnimProgress progress) { progress.FirstPersonAnimName = string.Empty; progress.ThirdPersonAnimName = string.Empty; for (int i = 0; i < commands.Length; ++i) { var cmd = commands[i]; string animName; if (MonitoredWeaponAnimP3.TryGetValue(cmd.Type, out animName) && weaponP3 != null && IsAnimationExist(weaponP3, animName)) { progress.ThirdPersonAnimName = animName; progress.ThirdPersonAnimProgress = cmd.AdditioanlValue; } if (MonitoredWeaponAnimP1.TryGetValue(cmd.Type, out animName) && weaponP1 != null && IsAnimationExist(weaponP1, animName)) { progress.FirstPersonAnimName = animName; progress.FirstPersonAnimProgress = cmd.AdditioanlValue; } } }
private void UpdateWeaponAnimation(IAdaptiveContainer <IFsmInputCommand> commandsContainer, PlayerEntity playerEntity) { try { SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.StateUpdateWeaponAnimation); // 更新武器动画 _weaponAnim.FromAvatarAnimToWeaponAnimProgress(commandsContainer, playerEntity.appearanceInterface.Appearance.GetWeaponP1InHand(), playerEntity.appearanceInterface.Appearance.GetWeaponP3InHand(), playerEntity.networkWeaponAnimation); _weaponAnim.FromWeaponAnimProgressToWeaponAnim( playerEntity.appearanceInterface.Appearance.GetWeaponP1InHand(), playerEntity.appearanceInterface.Appearance.GetWeaponP3InHand(), playerEntity.networkWeaponAnimation); // 武器动画结束 _weaponAnim.WeaponAnimFinishedUpdate(commandsContainer, playerEntity.appearanceInterface.Appearance.GetWeaponP1InHand(), playerEntity.appearanceInterface.Appearance.GetWeaponP3InHand(), playerEntity.networkWeaponAnimation); } finally { SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.StateUpdateWeaponAnimation); } }
private void UpdateStateResponseToAnimation(ICharacterState stateManager, IAdaptiveContainer <IFsmInputCommand> commandsContainer, AnimatorClipManager animatorClipManager, PlayerEntity playerEntity) { try { SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.StateUpdateResponseToAnimation); _fsmOutputs.ResetOutput(); // 更新状态机 stateManager.Update(commandsContainer, 0, _fsmOutputs.AddOutput, FsmUpdateType.ResponseToAnimation, playerEntity.fsmInputRelateInterface.Relate.GetFsmInputLimits()); // 更新Clip速率 animatorClipManager.Update(_fsmOutputs.AddOutput, playerEntity.thirdPersonAnimator.UnityAnimator, playerEntity.firstPersonAnimator.UnityAnimator, playerEntity.WeaponController().HeldWeaponAgent.ConfigId); // 更新Animator的Param _fsmOutputs.SetOutput(playerEntity); } finally { SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.StateUpdateResponseToAnimation); } }
private void UpdateStateResponseToInput(IUserCmd cmd, ICharacterState stateManager, IAdaptiveContainer <IFsmInputCommand> commandsContainer, PlayerEntity playerEntity) { try { SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.StateUpdateResponseToInput); _fsmOutputs.ResetOutput(); // 更新状态机 stateManager.Update(commandsContainer, cmd.FrameInterval, _fsmOutputs.AddOutput, FsmUpdateType.ResponseToInput, playerEntity.fsmInputRelateInterface.Relate.GetFsmInputLimits()); // 更新手臂动画 playerEntity.characterBoneInterface.CharacterBone.SetWeaponPitch(_fsmOutputs.AddOutput, playerEntity.characterBone.WeaponPitch); // 更新一、三人称Animator _fsmOutputs.SetOutput(playerEntity); if (!SharedConfig.IsServer && playerEntity.thirdPersonAnimator.UnityAnimator.cullingMode != AnimatorCullingMode.AlwaysAnimate) { _logger.WarnFormat("wrong culling mode: {0}", playerEntity.thirdPersonAnimator.UnityAnimator.cullingMode); } } finally { SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.StateUpdateResponseToInput); } }
private void SprintDisableTest(ICharacterState state, IAdaptiveContainer <IFsmInputCommand> commands) { int slowDown = NoLimit; int prevSlowDown = state.GetSteepSlowDown(); if (IsLimitRun(state.GetSteepAngle(), prevSlowDown)) { for (int i = 0; i < commands.Length; ++i) { var v = commands[i]; if (v.Type == FsmInput.Sprint || v.Type == FsmInput.Run) { v.Type = FsmInput.Walk; _logger.DebugFormat("sprint to Walk due to move in water or is steep slope!, angle:{0}", state.GetSteepAngle()); slowDown = LimitRun; } } } else if (state.IsMoveInWater() || IsLimitSprint(state.GetSteepAngle(), prevSlowDown)) { for (int i = 0; i < commands.Length; ++i) { var v = commands[i]; if (v.Type == FsmInput.Sprint) { v.Type = FsmInput.Run; _logger.DebugFormat("sprint to run due to move in water or is steep slope!, angle:{0}", state.GetSteepAngle()); slowDown = LimitSprint; } } } state.SetSteepSlowDown(slowDown); }
public void MonitorBeforeFsmUpdate(IAdaptiveContainer <IFsmInputCommand> commands, Animator animator, bool land) { var layerCount = animator.layerCount; for (int i = 0; i < layerCount; i++) { _animatorClipInfos.Clear(); animator.GetCurrentAnimatorClipInfo(i, _animatorClipInfos); if (_animatorClipInfos.Count > 0) { var animState = animator.GetCurrentAnimatorStateInfo(i); var inTransition = animator.IsInTransition(i); var type = _matcher.Match(GetAnimationClipName(animState, _animatorClipInfos[0].clip)); if (FsmInputRelate.AnimationFinished.ContainsKey(type) && !inTransition) { FsmInputRelate.AnimationFinished[type].Value = true; } // 不在在transition的时候,才进行Land检测,因为在transiton的时候可能是下一个状态 if (_animationProgressBeforeUpdate.ContainsKey(type) && !inTransition) { SetCommand(commands, _animationProgressBeforeUpdate[type]); } if (_animationLoopCount.ContainsKey(type)) { _animationLoopCount[type].Value = (int)Math.Ceiling(animState.normalizedTime); } } } PostProcess(commands, land); }
private void ChangeRoleTest(PlayerEntity playerEntity, IAdaptiveContainer <IFsmInputCommand> commands) { if (playerEntity.hasGamePlay && playerEntity.gamePlay.IsVariant() && playerEntity.hasStateInterface) { var state = playerEntity.stateInterface.State.GetNextPostureState(); if (state == PostureInConfig.Stand) { var characterInfo = playerEntity.characterInfo.CharacterInfoProviderContext; float targetHeight = characterInfo.GetStandCapsule().Height; GameObject gameObject = playerEntity.RootGo(); Vector3 startPoint = gameObject.transform.position; RaycastHit outHit; startPoint.y += CastRadius; if (PhysicsCastHelper.SphereCast(startPoint, CastRadius, Vector3.up, out outHit, targetHeight - 2 * CastRadius, UnityLayers.AllCollidableLayerMask, QueryTriggerInteraction.Ignore, LiftUp)) { //var item = commands.GetAvailableItem(command => { return command.Type == FsmInput.None; }); //item.Type = FsmInput.Crouch; playerEntity.stateInterface.State.SetPostureCrouch(); } } } }
// 拦截需要销毁的input(打断不触发) private void InterruptAnimationCallBack(IAdaptiveContainer <IFsmInputCommand> commands) { if (_interruptInputs.Count <= 0) { return; } for (int i = 0; i < _interruptInputs.Count; ++i) { var input = _interruptInputs[i]; for (int j = 0; j < commands.Length; ++j) { var cmd = commands[j]; if (cmd.Type == input) { _callBackRegister.TryRemoveCallBack(cmd.Type); _animationCallBackCommand.Add(new AnimationCallBackCommand { CommandType = (int)AnimationCallBackCommandType.Interrupt, FsmType = (int)cmd.Type }); } } } _interruptInputs.Clear(); }
public void Update(IAdaptiveContainer <IFsmInputCommand> commands, int frameInterval, Action <FsmOutput> addOutput, FsmUpdateType updateType, List <FsmInput> limits) { if (_needReset) { _needReset = false; RebindAnimator(addOutput); _posture.Reset(addOutput); _movement.Reset(addOutput); _action.Reset(addOutput); } if ((updateType & FsmUpdateType.ResponseToInput) != 0) { ApplyNewCommand(commands, addOutput, limits); } _posture.Update(commands, frameInterval, addOutput, updateType, limits); _movement.Update(commands, frameInterval, addOutput, updateType, limits); _action.Update(commands, frameInterval, addOutput, updateType, limits); UpdateFullBodySpeedScale(addOutput); }
private void SetCommand(IAdaptiveContainer <IFsmInputCommand> commands, FsmInput type, float additionalValue = float.NaN, float alterAdditionalValue = float.NaN) { var item = commands.GetAvailableItem(command => (command.Type == FsmInput.None || command.Type == type)); SetCommandParam(item, type, additionalValue, alterAdditionalValue); }
private void MoveJumpTest(PlayerEntity playerEntity, IAdaptiveContainer <IFsmInputCommand> commandsContainer) { var state = playerEntity.stateInterface.State.GetNextPostureState(); var moveState = playerEntity.stateInterface.State.GetNextMovementState(); if (!((state == PostureInConfig.Land || state == PostureInConfig.Stand) && (moveState == MovementInConfig.Sprint || moveState == MovementInConfig.Run))) { return; } IFsmInputCommand jumpCommand = null; bool forthExist = false; bool leftExist = false; bool rightExist = false; for (int i = 0; i < commandsContainer.Length; i++) { var v = commandsContainer[i]; if (v.Type == FsmInput.Jump) { jumpCommand = v; } else if (v.Type == FsmInput.Forth) { forthExist = true; } else if (v.Type == FsmInput.Left) { leftExist = true; } else if (v.Type == FsmInput.Right) { rightExist = true; } } if (jumpCommand != null && forthExist && CheckJumpSpeed(playerEntity)) { jumpCommand.AdditioanlValue = AnimatorParametersHash.Instance.JumpStateMove; if (leftExist) { jumpCommand.AlternativeAdditionalValue = AnimatorParametersHash.Instance.MoveJumpStateLF; } else if (rightExist) { jumpCommand.AlternativeAdditionalValue = AnimatorParametersHash.Instance.MoveJumpStateRF; } else { jumpCommand.AlternativeAdditionalValue = AnimatorParametersHash.Instance.MoveJumpStateNormal; } } }
public void Update(IAdaptiveContainer <IFsmInputCommand> commands, Action <FsmOutput> addOutput, Animator thirdAnimator, Animator firstAnimator, int weaponId, bool needRewind) { _thirdClipMonitor.UpdateClipBehavior(thirdAnimator); _thirdClipMonitor.Update(addOutput, CharacterView.ThirdPerson, _reloadSpeedBuff); _firstClipMonitor.UpdateClipBehavior(firstAnimator); _firstClipMonitor.Update(addOutput, CharacterView.FirstPerson, _reloadSpeedBuff); GetAnimatorClipTimesByWeaponId(commands, needRewind, weaponId); }
private void JumpDisableTest(PlayerEntity playerEntity, IAdaptiveContainer <IFsmInputCommand> commandsContainer) { var state = playerEntity.stateInterface.State.GetNextPostureState(); if (state != PostureInConfig.Stand || playerEntity.playerMove.IsGround) { return; } testCommand.Clear(); for (int i = 0; i < commandsContainer.Length; i++) { var v = commandsContainer[i]; if (v.Type == FsmInput.Jump) { testCommand.Add(v); } } if (testCommand.Count == 0) { return; } var gameObject = playerEntity.RootGo(); var prevLayer = gameObject.layer; IntersectionDetectTool.SetColliderLayer(gameObject, UnityLayers.TempPlayerLayer); var startPoint = gameObject.transform.position; //UnityLayers. // a shift lift up startPoint.y += CastRadius; RaycastHit outHit; // DebugDraw.DebugWireSphere(startPoint, Color.red, CastRadius, 1f); // DebugDraw.DebugWireSphere(startPoint + new Vector3(0,targetHeight - CastRadius - LiftUp,0), Color.magenta, CastRadius, 1f); if (!Physics.SphereCast(startPoint, CastRadius, Vector3.down, out outHit, CastRadius + CastRadius, UnityLayers.AllCollidableLayerMask)) { foreach (IFsmInputCommand command in testCommand) { _logger.InfoFormat("chang command:{0} to none, because current state:{1} can not jump because ground is empty!", command.Type, state); command.Type = FsmInput.None; } //Debug.DrawLine(outHit.point, outHit.normal, Color.red, 5000.0f); } IntersectionDetectTool.SetColliderLayer(gameObject, prevLayer); testCommand.Clear(); }
private void ClearActionByCmd(IAdaptiveContainer <IFsmInputCommand> commands, FsmInput cmd, FsmInput clearAction) { for (int i = 0; i < commands.Length; ++i) { if (commands[i].Type == cmd) { ClearActionByCmdHelper(commands, clearAction); return; } } }
public static void ClimbStateFreeFallTest(PlayerEntity player, IAdaptiveContainer <IFsmInputCommand> commands) { if (!CanTestFreeFall(player) || OverlapCapsuleTest(player) || IsHitGround(player, ProbeDist)) { return; } var item = commands.GetAvailableItem(command => command.Type == FsmInput.None); item.Type = FsmInput.Freefall; }
private void ClearActionByCmdHelper(IAdaptiveContainer <IFsmInputCommand> commands, FsmInput clearAction) { for (int i = 0; i < commands.Length; ++i) { if (commands[i].Type == clearAction) { commands[i].Type = FsmInput.None; commands[i].Handled = false; return; } } }
public void Update(IAdaptiveContainer <IFsmInputCommand> commands, int frameInterval, Action <FsmOutput> addOutput, FsmUpdateType updateType) { if ((_commonUpdateType & updateType) != 0) { _commonFsm.Update(commands, frameInterval, addOutput); } if ((_leanUpdateType & updateType) != 0) { _leanFsm.Update(commands, frameInterval, addOutput); } }
public void Update(IAdaptiveContainer <IFsmInputCommand> commands, int frameInterval, Action <FsmOutput> addOutput, FsmUpdateType updateType) { if ((updateType & _directionUpdateType) != 0) { UpdateDirection(commands, addOutput); } if ((updateType & _movementUpdateType) != 0) { _commonFsm.Update(commands, frameInterval, addOutput); } }
public override void Filter(IAdaptiveContainer <IFsmInputCommand> commands) { for (int i = 0; i < commands.Length; ++i) { Filter(commands[i]); } for (int i = 0; i < commands.Length; ++i) { if (TransferMap.ContainsKey(commands[i].Type)) { commands[i].Type = TransferMap[commands[i].Type]; } } }
public void WeaponAnimFinishedUpdate(IAdaptiveContainer <IFsmInputCommand> commands, GameObject weaponP1, GameObject weaponP3) { for (int i = 0; i < commands.Length; ++i) { var cmd = commands[i]; if (MonitoredWeaponAnimFinish.ContainsKey(cmd.Type)) { FinishedWeaponAnimation(weaponP1); FinishedWeaponAnimation(weaponP3); return; } } }
public override void Filter(IAdaptiveContainer <IFsmInputCommand> commands) { bool isFilter = false; for (int i = 0; i < commands.Length; ++i) { isFilter |= Filter(commands[i]); } if (!isFilter) { var item = commands.GetAvailableItem(); item.Type = FsmInput.Idle; //Logger.InfoFormat("create Idle because no idle"); } }
protected void ApplyNewCommand(IAdaptiveContainer <IFsmInputCommand> commands, Action <FsmOutput> addOutput) { for (int i = 0; i < commandsContainer.Length; ++i) { var newCommand = commandsContainer[i]; if (newCommand.Type != FsmInput.None) { var item = commands.GetAvailableItem(); item.Type = newCommand.Type; item.AdditioanlValue = newCommand.AdditionalValue; } } ClearAction(commands); commandsContainer.Reset(); _directOutputs.Apply(addOutput); }
private void GetAnimatorClipTimesByWeaponId(IAdaptiveContainer <IFsmInputCommand> commands, bool needRewind, int weaponId) { int lenght = commands.Length; for (int i = 0; i < lenght; ++i) { var cmd = commands[i]; if (needRewind || FsmInput.PickUpProgressP3 == cmd.Type || FsmInput.SelectProgressP3 == cmd.Type || FsmInput.HolsterProgressP3 == cmd.Type ) { _thirdClipMonitor.SetAnimatorClipsTime(weaponId); _firstClipMonitor.SetAnimatorClipsTime(weaponId); } } }
public void Update(IAdaptiveContainer <IFsmInputCommand> commands, int frameInterval, Action <FsmOutput> addOutput, FsmUpdateType updateType, List <FsmInput> limits) { if ((updateType & _commonUpdateType) != 0) { _commonFsm.Update(commands, frameInterval, addOutput); } if ((updateType & _keepUpdateType) != 0) { _keepFsm.Update(commands, frameInterval, addOutput); _transfigurationFsm.Update(commands, frameInterval, addOutput); } }
private void AnimationTest(PlayerEntity playerEntity, IAdaptiveContainer <IFsmInputCommand> commandsContainer) { try { SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.StateUpdateTest); SprintDisableTest(playerEntity.stateInterface.State, commandsContainer); StandCrouchDisableTest(playerEntity, commandsContainer); ProneDisableTest(playerEntity, commandsContainer); FreeFallTest(playerEntity, commandsContainer); WaterPostureDownDisableTest(playerEntity, commandsContainer); JumpDisableTest(playerEntity, commandsContainer); } finally { SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.StateUpdateTest); } }
public void TryAnimationBasedCallBack(IAdaptiveContainer <IFsmInputCommand> commands) { InterruptAnimationCallBack(commands); for (int i = 0; i < commands.Length; ++i) { var cmd = commands[i]; if (cmd.Type != FsmInput.None) { _callBackRegister.TryInvokeCallBack(cmd.Type); _callBackRegister.TryRemoveCallBack(cmd.Type); _animationCallBackCommand.Add(new AnimationCallBackCommand { CommandType = (int)AnimationCallBackCommandType.Apply, FsmType = (int)cmd.Type }); } } }
private void FreeFallTest(PlayerEntity player, IAdaptiveContainer <IFsmInputCommand> commands) { if ((!player.playerMove.IsGround && !(player.stateInterface.State.GetActionState() == ActionInConfig.Gliding || player.stateInterface.State.GetActionState() == ActionInConfig.Parachuting)) && player.playerMove.Velocity.y < -SpeedManager.Gravity) { for (int i = 0; i < commands.Length; ++i) { var v = commands[i]; if (v.Type == FsmInput.None) { v.Type = FsmInput.Freefall; break; } } } }
private void SprintDisableTest(ICharacterState state, IAdaptiveContainer <IFsmInputCommand> commands) { bool slowDown = false; if (state.IsMoveInWater() || state.IsSteepSlope()) { for (int i = 0; i < commands.Length; ++i) { var v = commands[i]; if (v.Type == FsmInput.Sprint) { v.Type = FsmInput.Run; slowDown = true; } } } state.SetBeenSlowDown(slowDown); }
// update based public void Update(IAdaptiveContainer <IFsmInputCommand> commands, int frameInterval, Action <FsmOutput> addOutput) { _currentStateChanged = false; _currentState.Update(frameInterval, addOutput); int lenght = commands.Length; for (int i = 0; i < lenght; ++i) { var command = commands[i]; if (command.Type != FsmInput.None) { // _currentState will not the same if FsmStateResponseType.Reenter is returned while (_currentState.HandleInput(command, addOutput) == FsmStateResponseType.Reenter) { } } } }