babylon.behavior.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. module BABYLON {
  2. /**
  3. * Interface used to define a behavior
  4. */
  5. export interface Behavior<T> {
  6. /** gets or sets behavior's name */
  7. name: string;
  8. /**
  9. * Function called when the behavior needs to be initialized (after attaching it to a target)
  10. */
  11. init(): void
  12. /**
  13. * Called when the behavior is attached to a target
  14. * @param target defines the target where the behavior is attached to
  15. */
  16. attach(target: T): void;
  17. /**
  18. * Called when the behavior is detached from its target
  19. */
  20. detach(): void;
  21. }
  22. /**
  23. * Interface implemented by classes supporting behaviors
  24. */
  25. export interface IBehaviorAware<T> {
  26. /**
  27. * Attach a behavior
  28. * @param behavior defines the behavior to attach
  29. * @returns the current host
  30. */
  31. addBehavior(behavior: Behavior<T>): T
  32. /**
  33. * Remove a behavior from the current object
  34. * @param behavior defines the behavior to detach
  35. * @returns the current host
  36. */
  37. removeBehavior(behavior: Behavior<T>): T;
  38. /**
  39. * Gets a behavior using its name to search
  40. * @param name defines the name to search
  41. * @returns the behavior or null if not found
  42. */
  43. getBehaviorByName(name: string): Nullable<Behavior<T>>;
  44. }
  45. }