/// <summary> /// Execute the movement of the current motion state /// </summary> public void Execute(ACharacterSystem cs, MotionInformation mi) { if (_currentMotionState != null) { _currentMotionState.Move(cs, mi, _motionType); } }
public override void UpdateAction(ACharacterSystem characterSystem, InputInformation inputInformation) { var human = characterSystem as HumanSystem; human.transform.Rotate(0f , inputInformation.GetLocomotionInformation.MovementDirection.x * human.GetLocomotionProfile.AngularSpeed * Time.deltaTime , 0f, Space.Self); human.transform.Translate(0f, 0f, inputInformation.GetLocomotionInformation.MovementDirection.z * human.GetLocomotionProfile.WalkSpeed * Time.deltaTime, Space.Self); }
//////////////////////////// ////////// Method ////////// //////////////////////////// ///////////////////////// ////////// API ////////// /// <summary> /// Initialize the motion state machine /// </summary> public void Initialize(ACharacterSystem cs) { if (_entryMotionState == null) { Debug.LogError("[MSM] There is no entry motion state to the motion state machine!"); } else { _currentMotionState = _entryMotionState; } _motionType = cs.GetType().IsSubclassOf(typeof(ACharacterSystem3D)) ? EMotionType.Motion3D : EMotionType.Motion2D; }
//////////////////////////// ////////// Method ////////// //////////////////////////// ///////////////////////// ////////// API ////////// /// <summary> /// Attempt to get the next motion state base on the motion transition of the current motion state /// </summary> public AMotionState AttemptToGetNextMotionState(ACharacterSystem cs, MotionInformation mi, EMotionType motionType) { foreach (var mt in _motionTransitions) { var nextMotionState = mt.GetResultingMotionState(cs, mi, motionType); if (nextMotionState != null) { return(nextMotionState); } } return(null); }
//////////////////////////// ////////// Method ////////// //////////////////////////// ///////////////////////// ////////// API ////////// /// <summary> /// Verify if the condition is complete /// </summary> public bool IsComplete(ACharacterSystem cs, MotionInformation mi, EMotionType motionType) { switch (motionType) { case EMotionType.Motion2D: return(IsComplete2D(cs as ACharacterSystem2D, mi)); case EMotionType.Motion3D: return(IsComplete3D(cs as ACharacterSystem3D, mi)); default: throw new ArgumentOutOfRangeException("motionType", motionType, null); } }
/// <summary> /// Execute the movemement of the motion state /// </summary> public void Move(ACharacterSystem cs, MotionInformation mi, EMotionType motionType) { switch (motionType) { case EMotionType.Motion2D: Move2D(cs as ACharacterSystem2D, mi); break; case EMotionType.Motion3D: Move3D(cs as ACharacterSystem3D, mi); break; default: throw new ArgumentOutOfRangeException("motionType", motionType, null); } }
/// <summary> /// Update the current motion state /// </summary> public void Update(ACharacterSystem cs, MotionInformation mi) { if (_currentMotionState == null) { return; } var nextMotionState = _currentMotionState.AttemptToGetNextMotionState(cs, mi, _motionType); if (nextMotionState != null) { _previousMotionState = _currentMotionState; _currentMotionState = nextMotionState; if (ShouldDisplayDebugTransitionLog) { DisplayDebugTransitionLog(); } } }
/// <summary> /// Update the action /// </summary> /// <remarks> /// Call every FixedUpdate /// </remarks> public abstract void UpdateAction(ACharacterSystem characterSystem, InputInformation inputInformation);
////////////////////////////// ////////// Callback ////////// /// <summary> /// Launch the action /// </summary> /// <remarks> /// Call when the action state is loaded /// </remarks> public abstract void BeginAction(ACharacterSystem characterSystem, InputInformation inputInformation);
public override void UpdateAction(ACharacterSystem characterSystem, InputInformation inputInformation) { var human = characterSystem as HumanSystem; human.GetRigidbody.AddForce(0f, human.GetLocomotionProfile.JumpForce, 0f, ForceMode.Impulse); }
public override void EndAction(ACharacterSystem characterSystem, InputInformation inputInformation) { }
//////////////////////////////////////////// ////////// MonoBehaviour Callback ////////// protected virtual void Awake() { _characterSystem = GetComponent <ACharacterSystem>(); LoadInformationComponents(); InitializeInformation(); }
//////////////////////////////////////////// ////////// MonoBehaviour Callback ////////// protected virtual void Awake() { _characterSystem = GetComponent <ACharacterSystem>(); Initialize(); SetupMotionConfiguration(ref _characterSystem.MotionInformation.Configuration); }
///////////////////////////// ////////// Service ////////// /// <summary> /// Check if all the conditions are met /// </summary> private bool AreConditionsMet(ACharacterSystem cs, MotionInformation mi, EMotionType motionType) { return(_motionConditions.All(mc => mc.IsComplete(cs, mi, motionType))); }
//////////////////////////// ////////// Method ////////// //////////////////////////// ///////////////////////// ////////// API ////////// /// <summary> /// Return either the motionStateOnSuccess or the motionStateOnFailure depending on the conditions result /// </summary> public AMotionState GetResultingMotionState(ACharacterSystem cs, MotionInformation mi, EMotionType motionType) { return(AreConditionsMet(cs, mi, motionType) ? _motionStateOnSuccess : _motionStateOnFailure); }