Created
July 26, 2011 12:02
-
-
Save AngryAnt/1106593 to your computer and use it in GitHub Desktop.
Examples of Behave repeat decorator implementations (untested).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Dictionary<string, int> activeRepeats = new Dictionary<string, float> (); | |
private Dictionary<string, float> activeTimers = new Dictionary<string, float> (); | |
// The repeat decorator works more or less like a for loop // | |
public BehaveResult InitRepeatDecorator (Tree sender, string name, float repeats, IAgent agent, object data) | |
{ | |
activeRepeats[name] = 0; | |
return BehaveResult.Success; | |
} | |
public BehaveResult TickRepeatDecorator (Tree sender, string name, float repeats, IAgent agent, object data) | |
{ | |
return activeRepeats[name] += 1 > (int)repeats ? BehaveResult.Failure : BehaveResult.Running; | |
} | |
public void ResetRepeatDecorator(Tree sender, string name, float repeats, IAgent agent, object data) | |
{ | |
activeRepeats.Remove (name); | |
} | |
// The timed repeat decorator works like the repeat decorator, but on a timeout in stead of an iteration count // | |
public BehaveResult InitTimedRepeatDecorator (Tree sender, string name, float timeout, IAgent agent, object data) | |
{ | |
activeTimers[name] = Time.time; | |
return BehaveResult.Success; | |
} | |
public BehaveResult TickTimedRepeatDecorator (Tree sender, string name, float timeout, IAgent agent, object data) | |
{ | |
return Time.time - activeTimers[name] > timeout ? BehaveResult.Failure : BehaveResult.Running; | |
} | |
public void ResetTimedRepeatDecorator(Tree sender, string name, float timeout, IAgent agent, object data) | |
{ | |
activeTimers.Remove (name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment