babylon.actionManager.ts 2.9 KB

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