import { _decorator, Component, Node } from 'cc'; const { ccclass, property } = _decorator; type SingletonConstructor = { new (...args: any[]): T; } export class Singleton { private static instances: Map = new Map(); private constructor() {} public static getInstance(cls: SingletonConstructor): T { if (!this.instances.has(cls)) { this.instances.set(cls, new cls()); } return this.instances.get(cls); } }