babylon.actionManager.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. module BABYLON {
  2. export class ActionManager {
  3. // Statics
  4. private static _NoneTrigger = 0;
  5. private static _OnPickTrigger = 1;
  6. private static _OnPointerOverTrigger = 2;
  7. private static _OnPointerOutTrigger = 3;
  8. private static _OnEveryFrameTrigger = 4;
  9. public static get NoneTrigger(): number {
  10. return ActionManager._NoneTrigger;
  11. }
  12. public static get OnPickTrigger(): number {
  13. return ActionManager._OnPickTrigger;
  14. }
  15. public static get OnPointerOverTrigger(): number {
  16. return ActionManager._OnPointerOverTrigger;
  17. }
  18. public static get OnPointerOutTrigger(): number {
  19. return ActionManager._OnPointerOutTrigger;
  20. }
  21. public static get OnEveryFrameTrigger(): number {
  22. return ActionManager._OnEveryFrameTrigger;
  23. }
  24. // Members
  25. public actions = new Array<Action>();
  26. private _scene: Scene;
  27. constructor(scene: Scene) {
  28. this._scene = scene;
  29. }
  30. // Methods
  31. public getScene(): Scene {
  32. return this._scene;
  33. }
  34. public registerAction(action: Action): Action {
  35. if (action.trigger === ActionManager.OnEveryFrameTrigger) {
  36. if (this.getScene().actionManager !== this) {
  37. Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager");
  38. return null;
  39. }
  40. }
  41. this.actions.push(action);
  42. action._actionManager = this;
  43. action._prepare();
  44. return action;
  45. }
  46. public processTrigger(trigger: number): void {
  47. for (var index = 0; index < this.actions.length; index++) {
  48. var action = this.actions[index];
  49. if (action.trigger === trigger) {
  50. action._executeCurrent();
  51. }
  52. }
  53. }
  54. public _getEffectiveTarget(target: any, propertyPath: string): any {
  55. var properties = propertyPath.split(".");
  56. for (var index = 0; index < properties.length - 1; index++) {
  57. target = target[properties[index]];
  58. }
  59. return target;
  60. }
  61. public _getProperty(propertyPath: string): string {
  62. var properties = propertyPath.split(".");
  63. return properties[properties.length - 1];
  64. }
  65. }
  66. }