Parcourir la source

Merge pull request #5904 from sebavan/master

Add register/unregister Actions to base Manager
David Catuhe il y a 6 ans
Parent
commit
33d0e74bd5
3 fichiers modifiés avec 38 ajouts et 10 suppressions
  1. 22 7
      src/Actions/abstractActionManager.ts
  2. 13 0
      src/Actions/action.ts
  3. 3 3
      src/Actions/actionManager.ts

+ 22 - 7
src/Actions/abstractActionManager.ts

@@ -1,7 +1,8 @@
-import { IDisposable } from '../scene';
-import { IActionEvent } from './actionEvent';
-import { IAction } from './action';
+import { IDisposable } from "../scene";
+import { IActionEvent } from "./actionEvent";
+import { IAction } from "./action";
 import { Constants } from "../Engines/constants";
+import { Nullable } from "../types";
 
 /**
  * Abstract class used to decouple action Manager from scene and meshes.
@@ -71,13 +72,27 @@ export abstract class AbstractActionManager implements IDisposable {
     public abstract hasSpecificTrigger(trigger: number, parameterPredicate?: (parameter: any) => boolean): boolean;
 
     /**
-         * Serialize this manager to a JSON object
-         * @param name defines the property name to store this manager
-         * @returns a JSON representation of this manager
-         */
+     * Serialize this manager to a JSON object
+     * @param name defines the property name to store this manager
+     * @returns a JSON representation of this manager
+     */
     public abstract serialize(name: string): any;
 
     /**
+     * Registers an action to this action manager
+     * @param action defines the action to be registered
+     * @return the action amended (prepared) after registration
+     */
+    public abstract registerAction(action: IAction): Nullable<IAction>;
+
+    /**
+     * Unregisters an action to this action manager
+     * @param action defines the action to be unregistered
+     * @return a boolean indicating whether the action has been unregistered
+     */
+    public abstract unregisterAction(action: IAction): Boolean;
+
+    /**
      * Does exist one action manager with at least one trigger
      **/
     public static get HasTriggers(): boolean {

+ 13 - 0
src/Actions/action.ts

@@ -2,6 +2,7 @@ import { Observable } from "../Misc/observable";
 import { Vector2, Vector3, Color3, Color4 } from "../Maths/math";
 import { Condition } from "./condition";
 import { _TypeStore } from '../Misc/typeStore';
+import { AbstractActionManager } from './abstractActionManager';
 
 declare type Scene = import("../scene").Scene;
 declare type ActionManager = import("./actionManager").ActionManager;
@@ -41,6 +42,18 @@ export interface IAction {
      * @returns the serialized object
      */
     serialize(parent: any): any;
+
+     /**
+     * Internal only
+     * @hidden
+     */
+    _prepare(): void;
+
+    /**
+     * Internal only - manager for action
+     * @hidden
+     */
+    _actionManager: AbstractActionManager;
 }
 
 /**

+ 3 - 3
src/Actions/actionManager.ts

@@ -4,7 +4,7 @@ import { Scene } from "../scene";
 import { Vector3, Vector4, Color3, Color4 } from "../Maths/math";
 
 import { Condition, ValueCondition } from "./condition";
-import { Action } from "./action";
+import { Action, IAction } from "./action";
 import { DoNothingAction } from "./directActions";
 
 import { EngineStore } from "../Engines/engineStore";
@@ -260,7 +260,7 @@ export class ActionManager extends AbstractActionManager {
      * @param action defines the action to be registered
      * @return the action amended (prepared) after registration
      */
-    public registerAction(action: Action): Nullable<Action> {
+    public registerAction(action: IAction): Nullable<IAction> {
         if (action.trigger === ActionManager.OnEveryFrameTrigger) {
             if (this.getScene().actionManager !== this) {
                 Logger.Warn("OnEveryFrameTrigger can only be used with scene.actionManager");
@@ -288,7 +288,7 @@ export class ActionManager extends AbstractActionManager {
      * @param action defines the action to be unregistered
      * @return a boolean indicating whether the action has been unregistered
      */
-    public unregisterAction(action: Action): Boolean {
+    public unregisterAction(action: IAction): Boolean {
         var index = this.actions.indexOf(action);
         if (index !== -1) {
             this.actions.splice(index, 1);