消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

5 days ago
import { PhysicsSystem2D } from 'cc';
/**
* 2D
*
* 广 / / `enable = false` wasEnabled
*
*
* reason / beginBattle/endBattle
*/
export class Physics2DGate {
private static _reasons = new Set<string>();
static readonly VideoAd = 'videoAd';
5 days ago
static readonly ViewportResize = 'viewportResize';
5 days ago
static suspend(reason: string): void {
if (!reason) return;
this._reasons.add(reason);
PhysicsSystem2D.instance.enable = false;
}
static resume(reason: string): void {
if (!reason) return;
this._reasons.delete(reason);
this._applyEnable();
}
static isSuspended(reason?: string): boolean {
if (reason) return this._reasons.has(reason);
return this._reasons.size > 0;
}
private static _applyEnable(): void {
const on = this._reasons.size === 0;
PhysicsSystem2D.instance.enable = on;
if (on) PhysicsSystem2D.instance.maxSubSteps = 1;
}
/** 进入战斗:清空挂起并开物理 */
static beginBattle(): void {
this._reasons.clear();
PhysicsSystem2D.instance.enable = true;
PhysicsSystem2D.instance.maxSubSteps = 1;
}
/** 离开战斗:清空其它挂起并关物理(避免离局后广告回调误开) */
static endBattle(): void {
this._reasons.clear();
PhysicsSystem2D.instance.enable = false;
}
}