35 lines
1006 B
TypeScript
35 lines
1006 B
TypeScript
import { _decorator, Component, instantiate, Node, Prefab } from 'cc'
|
|
import PrefabLoader from '../../engine/utils/PrefabLoader'
|
|
import { GameConfig } from '../config/GameConfig'
|
|
|
|
const { ccclass, property } = _decorator
|
|
|
|
@ccclass('ResourcePrefab')
|
|
export default class ResourcePrefab extends Component {
|
|
private static prefab: Prefab | null = null
|
|
public static instance: Node
|
|
@property({ type: Prefab })
|
|
private scorePrefab: Prefab | null = null
|
|
public static preLoad(): Promise<void> {
|
|
return new Promise((resolve, reject) => {
|
|
PrefabLoader.loadPrefab(
|
|
GameConfig.GameName + '/' + 'game/prefab/ResourcePrefab',
|
|
(loadedResource: Prefab) => {
|
|
ResourcePrefab.prefab = loadedResource
|
|
ResourcePrefab.instance = instantiate(loadedResource)
|
|
resolve()
|
|
}
|
|
)
|
|
})
|
|
}
|
|
|
|
public static clear() {
|
|
ResourcePrefab.instance = null
|
|
ResourcePrefab.prefab = null
|
|
}
|
|
|
|
public static getScorePrefab() {
|
|
return ResourcePrefab.instance.getComponent(ResourcePrefab).scorePrefab
|
|
}
|
|
}
|