babylon.actionManager.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. module BABYLON {
  2. export class ActionManager {
  3. // Statics
  4. public static AlwaysTrigger = 0;
  5. public static OnPickTrigger = 1;
  6. public static SceneTarget = 0;
  7. public static MeshTarget = 1;
  8. public static LightTarget = 2;
  9. public static CameraTarget = 3;
  10. public static MaterialTarget = 4;
  11. // Members
  12. public actions = new Array<Action>();
  13. private _scene: Scene;
  14. constructor(scene: Scene) {
  15. this._scene = scene;
  16. }
  17. // Methods
  18. public getScene(): Scene {
  19. return this._scene;
  20. }
  21. public registerAction(action: Action): Action {
  22. this.actions.push(action);
  23. action._actionManager = this;
  24. action._prepare();
  25. return action;
  26. }
  27. public processTrigger(trigger: number): void {
  28. for (var index = 0; index < this.actions.length; index++) {
  29. var action = this.actions[index];
  30. if (action.trigger === trigger) {
  31. action._executeCurrent();
  32. }
  33. }
  34. }
  35. public _getTarget(targetType: number, targetName: string): any {
  36. var scene = this._scene;
  37. switch (targetType) {
  38. case ActionManager.SceneTarget:
  39. return scene;
  40. case ActionManager.MeshTarget:
  41. return scene.getMeshByName(targetName);
  42. case ActionManager.LightTarget:
  43. return scene.getLightByName(targetName);
  44. case ActionManager.CameraTarget:
  45. return scene.getCameraByName(targetName);
  46. case ActionManager.MaterialTarget:
  47. return scene.getMaterialByName(targetName);
  48. }
  49. return null;
  50. }
  51. public _getEffectiveTarget(target: any, propertyPath: string): any {
  52. var properties = propertyPath.split(".");
  53. for (var index = 0; index < properties.length - 1; index++) {
  54. target = target[properties[index]];
  55. }
  56. return target;
  57. }
  58. public _getProperty(propertyPath: string): string {
  59. var properties = propertyPath.split(".");
  60. return properties[properties.length - 1];
  61. }
  62. }
  63. }