feat: add game director

main
tiendat3699 2024-04-17 15:47:13 +07:00
parent 9a42d59c30
commit a29e6b62af
5 changed files with 34193 additions and 18 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
{"ver":"1.1.43","importer":"scene","imported":true,"uuid":"aa17106a-0b45-4280-a91c-9650d0c417b3","files":[".json"],"subMetas":{},"userData":{}}

View File

@ -0,0 +1,126 @@
import {
Node,
AnimationState,
director,
TweenSystem,
PhysicsSystem2D,
PhysicsSystem,
AnimationManager,
Animation,
} from 'cc';
export class pauseConfig {
exclude?: Node[];
recuExclude?: Node[];
}
export default class GameDirector {
public static pauseData = new (class {
state = false;
physics2D: boolean;
physics3D: boolean;
scheduler: any[];
anim: AnimationState[] = [];
tweenTarget: any[];
})();
private static recuNodeList(node: Node, result: Node[] = []): Node[] {
if (!node) {
return result;
}
result.push(node);
node.children.forEach((v1) => {
result.push(v1);
this.recuNodeList(v1);
});
return result;
}
public static pause(config?: pauseConfig): void {
if (GameDirector.pauseData.state) {
return;
}
GameDirector.pauseData.scheduler = director.getScheduler().pauseAllTargets();
let animSystem = director.getSystem(AnimationManager.ID);
GameDirector.pauseData.anim.splice(0, GameDirector.pauseData.anim.length, ...animSystem['_anims'].array);
GameDirector.pauseData.anim.forEach((v1) => {
v1.pause();
});
GameDirector.pauseData.tweenTarget = TweenSystem.instance.ActionManager.pauseAllRunningActions();
{
if (PhysicsSystem2D && PhysicsSystem2D.instance.enable) {
GameDirector.pauseData.physics2D = PhysicsSystem2D.instance.enable;
PhysicsSystem2D.instance.enable = false;
}
if (PhysicsSystem && PhysicsSystem.instance.enable) {
GameDirector.pauseData.physics3D = PhysicsSystem.instance.enable;
PhysicsSystem.instance.enable = false;
}
}
if (config) {
let exclude: Node[] = [];
exclude.push(...config.exclude);
config.recuExclude?.forEach((v1) => {
exclude.push(...GameDirector.recuNodeList(v1));
});
exclude.forEach((v1) => {
GameDirector.resumeNode(v1);
});
}
GameDirector.pauseData.state = true;
}
public static resume(): void {
director.getScheduler().resumeTargets(GameDirector.pauseData.scheduler);
GameDirector.pauseData.anim.forEach((v1) => {
if (v1.isPlaying && v1.isPaused) {
v1.play();
}
});
TweenSystem.instance.ActionManager.resumeTargets(GameDirector.pauseData.tweenTarget);
if (GameDirector.pauseData.physics2D) {
PhysicsSystem2D.instance.enable = GameDirector.pauseData.physics2D;
}
if (GameDirector.pauseData.physics3D) {
PhysicsSystem.instance.enable = GameDirector.pauseData.physics3D;
}
GameDirector.pauseData.state = false;
}
public static pauseNode(node: Node): void;
public static pauseNode(node: Node[]): void;
public static pauseNode(args: Node | Node[]): void {
let node: Node[];
if (Array.isArray(args)) {
node = args;
} else {
node = [args];
}
node.forEach((v1) => {
director.getScheduler().pauseTarget(v1);
v1.getComponent(Animation)?.pause();
TweenSystem.instance.ActionManager.pauseTarget(v1);
});
}
public static resumeNode(node: Node): void;
public static resumeNode(node: Node[]): void;
public static resumeNode(args: Node | Node[]): void {
let node: Node[];
if (Array.isArray(args)) {
node = args;
} else {
node = [args];
}
node.forEach((v1) => {
director.getScheduler().resumeTarget(v1);
v1.getComponent(Animation)?.resume();
TweenSystem.instance.ActionManager.resumeTarget(v1);
});
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bc911ddc-f6b6-45ed-bdf9-ae20f48dfd80",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -126,12 +126,8 @@ export class GameOverPanel extends Component {
const obj = this._pool.get(this._scoreUI);
obj.setWorldPosition(this._scoreUI.worldPosition);
tween(obj)
.to(randomRange(0.2, 0.3), { worldPosition: target }, { easing: 'sineIn' })
.to(0.3, { worldPosition: target }, { easing: 'sineIn' })
.call(() => this._pool.release(obj))
.call(() => {
Tween.stopAllByTarget(this.yourScore);
tween(this.yourScore.node)
.to(0.1, { scale: new Vec3(1.3, 1.3, 1.3) })
.call(async () => {
if (i == items - 1) {
this.yourScore.string = totalScore.toString();
@ -143,9 +139,6 @@ export class GameOverPanel extends Component {
this.yourScore.string = score.toString();
}
})
.set({ scale: Vec3.ONE })
.start();
})
.start();
SoundManager.instance.playSfx(this._soundCollectCoinFx);
await Utilities.delay(time);