What’s the greatest recommendation on importing a customisable class to make use of its strategies right into a script ?
I would love as an illustration to have Controller.ts in a single prefab and that this class can entry strategies from a generic Actions.ts in several cases.
// as ES5 import ?
import { ES5Movements } from "./Velocity/Actions";
const { ccclass, property } = _decorator;
@ccclass("Controller")
export class Controller extends Part {
actions: Actions;
// As property ?
@property({ kind: Script })
ScriptMovements: Script;
onLoad() {
// or as element ?
this.actions = this.getComponent(Actions);
}
// ... later
onKeyDown(occasion: EventKeyboard) {
this.actions.moveLeft();
}
The factor is that I wish to have a unique Actions class for each prefab occasion, so importing will trigger duplication of Controller.js. As property appears to not work and getComponent is flaky
I is perhaps incorrect with what you need however possibly verify this put up out to see if it helps together with your understanding. Common entry to variables – #3 by iDevGames
Thanks in your reply, that is what I lastly did
import { ForceMovement } from "./ForceMovement";
import { VelocityMovements } from "./VelocityMovements";
import { ImpulseMovements } from "./ImpulseMovements";
import { PositionMovement } from "./PositionMovement";
@ccclass("Controller")
export class Controller extends Part {
actions: ForceMovement;
onLoad()
this.getComponent(VelocityMovements)
onKeyDown(occasion: EventKeyboard) {
change (occasion.keyCode) {
case KeyCode.ARROW_LEFT:
this.actions.moveLeft();
break;
case KeyCode.ARROW_RIGHT:
this.actions.moveRight();
break;
case KeyCode.ARROW_UP:
this.actions.moveUp();
break;
case KeyCode.ARROW_DOWN:
this.actions.moveDown();
break;
in order that I can seek advice from a generic kind of motion like
or
in order that this.actions.moveLeft()
has a unique implementation relying on what file is chosen.
I exploit this in some prefabs to check completely different behaviours of transfer interplay