51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { _decorator, Node, AudioClip, AudioSource, director, PhysicsSystem2D, EPhysics2DDrawFlags, Vec2, PHYSICS_2D_PTM_RATIO, v2 } from "cc";
|
|
import PlayerDataManager from "./PlayerDataManager";
|
|
import ResManager from "./ResManager";
|
|
import Resource from "../Config/Resource";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
//物理系统管理器
|
|
//通过编辑器主菜单中的 项目 -> 项目设置 -> 功能裁剪 切换物理模块的使用。轻量 Builtin 物理系统和强大的 Box2D 物理系统
|
|
@ccclass('PhysicsManager')
|
|
export default class PhysicsManager {
|
|
|
|
private static _I: PhysicsManager = null;
|
|
public static get I(): PhysicsManager {
|
|
if (!PhysicsManager._I) {
|
|
PhysicsManager._I = new PhysicsManager();
|
|
PhysicsManager._I.init();
|
|
}
|
|
return PhysicsManager._I;
|
|
}
|
|
|
|
private init(){
|
|
// const system = PhysicsSystem2D.instance;
|
|
// system.fixedTimeStep = 1/30;// 物理步长,默认 fixedTimeStep 是 1/60
|
|
// system.velocityIterations = 8;// 每次更新物理系统处理速度的迭代次数,默认为 10
|
|
// system.positionIterations = 8;// 每次更新物理系统处理位置的迭代次数,默认为 10
|
|
|
|
// this.setPhysicsEnable(false)
|
|
}
|
|
|
|
|
|
//设置是否开启物理系统
|
|
public setPhysicsEnable(swt: boolean) {
|
|
PhysicsSystem2D.instance.enable = swt; //是否启用物理系统
|
|
}
|
|
|
|
//设置物理调试信息是否显示
|
|
public setDrawFalgEnable(swt: boolean) {
|
|
if (swt) {
|
|
this.setPhysicsEnable(true);
|
|
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Shape | EPhysics2DDrawFlags.Joint
|
|
} else {
|
|
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.None;
|
|
}
|
|
}
|
|
|
|
//设置重力方向
|
|
public setPhysicsGravity(dir: Vec2) {
|
|
PhysicsSystem2D.instance.gravity = v2(dir.x * PHYSICS_2D_PTM_RATIO, dir.y * PHYSICS_2D_PTM_RATIO);
|
|
}
|
|
} |