public SecuenceTransition(SecuenceNode source, SecuenceNode dest, float duration, Func <SecuenceTransition, bool> trigger) { _sourceNode = source; _destNode = dest; _transitionTime = duration; _trigger = trigger; }
public SecuenceStateMachine WithState(string name, Action <SecuenceNode> action) { SecuenceNode node = new SecuenceNode(name); WithState(node); action(node); return(this); }
public bool RemoveTransitions(SecuenceNode node) { List <SecuenceTransition> tempTransitions = new List <SecuenceTransition>(); foreach (var item in _transitions) { if (item.DestNode == node) { tempTransitions.Add(item); } } foreach (var item in tempTransitions) { _transitions.Remove(item); } return(tempTransitions.Count > 0); }
public void Update(float elapsedTime) { if (_nodes.Count == 0) { return; } if (_currentNode == null) { _currentNode = _nodes[0]; } SecuenceNode next = null; while ((next = _currentNode.Update(elapsedTime)) != null) { _currentNode.OnDeactivating(); next.OnActivating(); _currentNode = next; } }
public SecuenceNode Update(float deltaT) { if (_currentTransition == null) { foreach (var tr in _transitions) { if (tr.IsTriggered()) { _currentTransition = tr; } } } SecuenceNode next = null; if (_currentTransition != null) { //it's in transition if (!_currentTransition.Blend(deltaT)) { //the transition has ended //move to the next state next = _currentTransition.DestNode; _currentTransition = null; } } else { OnBeforeUpdate(deltaT); //its playing the state and there aren't any transitions triggered UpdateAnimations(deltaT, _animations.Count == 1 ? -1 : 1, 1); OnAfterUpdate(deltaT); } return(next); }
public SecuenceTransition(SecuenceNode dest, float duration, Func <SecuenceTransition, bool> trigger = null) : this(null, dest, duration, trigger) { }
public SecuenceStateMachine WithState(SecuenceNode node) { _nodes.Add(node); node.Id = _nodes.Count - 1; return(this); }