コード例 #1
0
 /// <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);
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        ////////////////////////////
        ////////// 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;
        }
コード例 #4
0
        ////////////////////////////
        ////////// 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);
        }
コード例 #5
0
        ////////////////////////////
        ////////// 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);
            }
        }
コード例 #6
0
        /// <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);
            }
        }
コード例 #7
0
        /// <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();
                }
            }
        }
コード例 #8
0
 /// <summary>
 /// Update the action
 /// </summary>
 /// <remarks>
 /// Call every FixedUpdate
 /// </remarks>
 public abstract void UpdateAction(ACharacterSystem characterSystem, InputInformation inputInformation);
コード例 #9
0
        //////////////////////////////
        ////////// Callback //////////

        /// <summary>
        /// Launch the action
        /// </summary>
        /// <remarks>
        /// Call when the action state is loaded
        /// </remarks>
        public abstract void BeginAction(ACharacterSystem characterSystem, InputInformation inputInformation);
コード例 #10
0
        public override void UpdateAction(ACharacterSystem characterSystem, InputInformation inputInformation)
        {
            var human = characterSystem as HumanSystem;

            human.GetRigidbody.AddForce(0f, human.GetLocomotionProfile.JumpForce, 0f, ForceMode.Impulse);
        }
コード例 #11
0
 public override void EndAction(ACharacterSystem characterSystem, InputInformation inputInformation)
 {
 }
コード例 #12
0
        ////////////////////////////////////////////
        ////////// MonoBehaviour Callback //////////

        protected virtual void Awake()
        {
            _characterSystem = GetComponent <ACharacterSystem>();
            LoadInformationComponents();
            InitializeInformation();
        }
コード例 #13
0
        ////////////////////////////////////////////
        ////////// MonoBehaviour Callback //////////

        protected virtual void Awake()
        {
            _characterSystem = GetComponent <ACharacterSystem>();
            Initialize();
            SetupMotionConfiguration(ref _characterSystem.MotionInformation.Configuration);
        }
コード例 #14
0
        /////////////////////////////
        ////////// 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)));
        }
コード例 #15
0
        ////////////////////////////
        ////////// 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);
        }