Exemplo n.º 1
0
 /// <summary>
 /// Constructor, pass in all the nodes you wish to execute concurrently,
 /// along with a function to sort out the state of this node.
 /// </summary>
 public Concurrent(System.Func <IEnumerable <bool>, bool> stateResolutionFunc, IEnumerable <ICoroutine> subBehaviours)
 {
     // Create our list, and initialize the running one with the behaviours we get passed
     _SubBehaviours         = new List <ICoroutine>(subBehaviours);
     _RunningResolutionFunc = stateResolutionFunc;
     _CurrentState          = ConcurrentState.Running;
 }
Exemplo n.º 2
0
 public void Reset()
 {
     for (int i = 0; i < _SubBehaviours.Count; ++i)
     {
         _SubBehaviours[i].Reset();
     }
     _CurrentState = ConcurrentState.Running;
 }
Exemplo n.º 3
0
 public void Dispose()
 {
     // Clean up
     if (_SubBehaviours != null)
     {
         foreach (var subroutine in _SubBehaviours)
         {
             subroutine.Dispose();
         }
         _SubBehaviours = null;
     }
     _CurrentState = ConcurrentState.Disposed;
 }
Exemplo n.º 4
0
        public void Update()
        {
            switch (_CurrentState)
            {
            case ConcurrentState.Running:
            {
                // Process all sub behaviours first
                for (int i = 0; i < _SubBehaviours.Count; ++i)
                {
                    _SubBehaviours[i].Update();
                }

                // Use the resolution method to determine if we should terminate
                if (!_RunningResolutionFunc(_SubBehaviours.Select(sb => sb.IsRunning)))
                {
                    _CurrentState = ConcurrentState.Complete;
                    // Reset any node that was running
                    for (int i = 0; i < _SubBehaviours.Count; ++i)
                    {
                        if (_SubBehaviours[i].IsRunning)
                        {
                            _SubBehaviours[i].Reset();
                        }
                    }
                }
            }
            break;

            case ConcurrentState.Complete:
                // Nothing to do
                break;

            case ConcurrentState.Disposed:
                throw new System.Exception("Concurrent node is disposed and should not be updated");
            }
        }