babylon.action.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. module BABYLON {
  2. export class Action {
  3. public trigger: number;
  4. public _actionManager: ActionManager;
  5. private _nextActiveAction: Action;
  6. private _child: Action;
  7. private _condition: Condition;
  8. private _triggerParameter: any;
  9. constructor(public triggerOptions: any, condition?: Condition) {
  10. if (triggerOptions.parameter) {
  11. this.trigger = triggerOptions.trigger;
  12. this._triggerParameter = triggerOptions.parameter;
  13. } else {
  14. this.trigger = triggerOptions;
  15. }
  16. this._nextActiveAction = this;
  17. this._condition = condition;
  18. }
  19. // Methods
  20. public _prepare(): void {
  21. }
  22. public getTriggerParameter(): any {
  23. return this._triggerParameter;
  24. }
  25. public _executeCurrent(evt: ActionEvent): void {
  26. if (this._condition) {
  27. var currentRenderId = this._actionManager.getScene().getRenderId();
  28. // We cache the current evaluation for the current frame
  29. if (this._condition._evaluationId === currentRenderId) {
  30. if (!this._condition._currentResult) {
  31. return;
  32. }
  33. } else {
  34. this._condition._evaluationId = currentRenderId;
  35. if (!this._condition.isValid()) {
  36. this._condition._currentResult = false;
  37. return;
  38. }
  39. this._condition._currentResult = true;
  40. }
  41. }
  42. this._nextActiveAction.execute(evt);
  43. if (this._nextActiveAction._child) {
  44. if (!this._nextActiveAction._child._actionManager) {
  45. this._nextActiveAction._child._actionManager = this._actionManager;
  46. }
  47. this._nextActiveAction = this._nextActiveAction._child;
  48. } else {
  49. this._nextActiveAction = this;
  50. }
  51. }
  52. public execute(evt: ActionEvent): void {
  53. }
  54. public then(action: Action): Action {
  55. this._child = action;
  56. action._actionManager = this._actionManager;
  57. action._prepare();
  58. return action;
  59. }
  60. public _getProperty(propertyPath: string): string {
  61. return this._actionManager._getProperty(propertyPath);
  62. }
  63. public _getEffectiveTarget(target: any, propertyPath: string): any {
  64. return this._actionManager._getEffectiveTarget(target, propertyPath);
  65. }
  66. }
  67. }