Deozaan

attachBehavior for TGB

Apr 6th, 2010
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. /********************************************************************************
  2. * This function makes it easy to attach a behavior to an object dynamically and
  3. *     also provides an easy reference to that behavior so that the values can
  4. *     also be tweaked dynamically.
  5. *
  6. * %obj: The object to attach the behavior to.
  7. * %behavior: The behavior name (not friendly) you want attached to %obj
  8. * %behaviorRef: This gets saved as %obj.%behaviorRef for easy reference to the
  9. *               behavior.
  10. *******************************************************************************/
  11. function attachBehavior(%obj, %behavior, %behaviorRef)
  12. {
  13.    %template = %behavior.createInstance();
  14.    %obj.addBehavior(%template);
  15.    %template = %obj.getBehavior(%behavior);
  16.    %str = %obj @ "." @ %behaviorRef @ " = " @ %template @ ";";
  17.    eval(%str); // this line says (%obj.%behaviorRef = %template;)
  18. }
Advertisement
Add Comment
Please, Sign In to add comment