18 lines
580 B
TypeScript
18 lines
580 B
TypeScript
import { _decorator, Component, Node, instantiate, Prefab, resources } from 'cc';
|
|
|
|
export class HeroManager {
|
|
static async createHero(parent: Node) {
|
|
const prefab = await this.loadPrefab('prefabs/Hero');
|
|
const hero = instantiate(prefab);
|
|
parent.addChild(hero);
|
|
return hero;
|
|
}
|
|
|
|
private static loadPrefab(path: string): Promise<Prefab> {
|
|
return new Promise((resolve, reject) => {
|
|
resources.load(path, Prefab, (err, prefab) => {
|
|
err ? reject(err) : resolve(prefab!);
|
|
});
|
|
});
|
|
}
|
|
}
|