/// <summary>
 /// Calls the process callback
 /// </summary>
 internal void Trigger(FsmStateData <T> data)
 {
     for (int i = 0, len = m_ProcessCallbacks.Count; i < len; i++)
     {
         m_ProcessCallbacks[i](data);
     }
 }
Exemple #2
0
 /// <summary>
 /// Calls the process callback
 /// </summary>
 internal void Trigger(FsmStateData <T> data)
 {
     foreach (var callback in m_ProcessCallbacks)
     {
         callback(data);
     }
 }
Exemple #3
0
        /// <summary>
        /// Processes the logic for the FSM.
        /// </summary>
        /// <param name="time">The time, expressed in seconds.</param>
        /// <exception cref="InvalidOperationException"></exception>
        public void Process(float time)
        {
            if (m_StateAge < 0f)
            {
                m_StateAge = time;
            }

            float totalTime     = time;
            float stateTime     = (totalTime - m_StateAge);
            float stateProgress = 0f;

            if (m_CurrentStateBehaviour == null)
            {
                throw new InvalidOperationException(string.Format("[FSM {0}] : Can't call 'Process' before setting the starting state.", m_FsmName));
            }

            if (m_CurrentStateBehaviour.Duration.HasValue)
            {
                stateProgress = Math.Max(0f, Math.Min(1f, stateTime / m_CurrentStateBehaviour.Duration.Value));
            }

            var data = new FsmStateData <T>()
            {
                Machine       = this,
                Behaviour     = m_CurrentStateBehaviour,
                State         = m_CurrentState,
                StateTime     = stateTime,
                AbsoluteTime  = totalTime,
                StateProgress = stateProgress
            };

            m_CurrentStateBehaviour.Trigger(data);

            if (stateProgress >= 1f && m_CurrentStateBehaviour.NextStateSelector != null)
            {
                CurrentState = m_CurrentStateBehaviour.NextStateSelector();
                m_StateAge   = time;
            }
        }