| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import { sys } from "cc";
- // VibrationManager.ts
- export class VibrationManager {
- private static instance: VibrationManager;
- private _switch_vibration: boolean = true;
- /**
- * 获取震动开关值
- */
- get switchVibration(): boolean {
- return this._switch_vibration;
- }
- /**
- * 设置震动开关值
- * @param value 开关值
- */
- set switchVibration(value: boolean) {
- this._switch_vibration = value;
- }
- private constructor() {}
- // 获取AdManager的单例对象
- public static getInstance(): VibrationManager {
- if (!VibrationManager.instance) {
- VibrationManager.instance = new VibrationManager();
- }
- return VibrationManager.instance;
- }
- // 震动(短)
- vibrateShort() {
- if(!this.switchVibration)return
- if (sys.platform === sys.Platform.WECHAT_GAME) {
- // 微信小游戏环境
- wx.vibrateShort({
- success: () => console.log("Vibrate short success"),
- fail: () => console.error("Vibrate short failed"),
- });
- } else if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) {
- // 抖音小游戏环境
- tt.vibrateShort({
- success: () => console.log("Vibrate short success"),
- fail: () => console.error("Vibrate short failed"),
- });
- } else {
- console.log("Vibrate short called in unsupported platform");
- }
- }
- // 震动(长)
- vibrateLong() {
- if (sys.platform === sys.Platform.WECHAT_GAME) {
- // 微信小游戏环境
- wx.vibrateLong({
- success: () => console.log("Vibrate long success"),
- fail: () => console.error("Vibrate long failed"),
- });
- } else if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) {
- // 抖音小游戏环境
- tt.vibrateLong({
- success: () => console.log("Vibrate long success"),
- fail: () => console.error("Vibrate long failed"),
- });
- } else {
- console.log("Vibrate long called in unsupported platform");
- }
- }
- }
|