private void CancelConflicts(Command command) { for (int i = 0; i < m_children.Count; i++) { Command child = m_children[i].command; foreach (var requirement in command.GetRequirements()) { if (child.DoesRequire(requirement)) { child._Cancel(); child.Removed(); m_children.RemoveAt(i--); } } } }
/// <inheritdoc/> protected internal override void _End() { if (m_currentCommandIndex != -1 && m_currentCommandIndex < m_commands.Count) { Command cmd = m_commands[m_currentCommandIndex].command; cmd._Cancel(); cmd.Removed(); } foreach (var s in m_children) { Command cmd = s.command; cmd._Cancel(); cmd.Removed(); } m_children.Clear(); }
/// <inheritdoc/> internal override void _Execute() { Entry entry = null; Command cmd = null; bool firstRun = false; if (m_currentCommandIndex == -1) { firstRun = true; m_currentCommandIndex = 0; } while (m_currentCommandIndex < m_commands.Count()) { if (cmd != null) { if (entry.IsTimedOut()) { cmd._Cancel(); } if (cmd.Run()) { break; } else { cmd.Removed(); m_currentCommandIndex++; firstRun = true; cmd = null; continue; } } entry = m_commands[m_currentCommandIndex]; cmd = null; switch (entry.state) { case Entry.IN_SEQUENCE: cmd = entry.command; if (firstRun) { cmd.StartRunning(); CancelConflicts(cmd); } firstRun = false; break; case Entry.BRANCH_PEER: m_currentCommandIndex++; entry.command.Start(); break; case Entry.BRANCH_CHILD: m_currentCommandIndex++; CancelConflicts(entry.command); entry.command.StartRunning(); m_children.Add(entry); break; } } for (int i = 0; i < m_children.Count; i++) { entry = m_children[i]; Command child = entry.command; if (entry.IsTimedOut()) { child._Cancel(); } if (!child.Run()) { child.Removed(); m_children.RemoveAt(i--); } } }