27 lines
567 B
TypeScript
27 lines
567 B
TypeScript
import { _decorator, Component, Node, Prefab } from 'cc';
|
|
|
|
const { ccclass, property, executionOrder } = _decorator;
|
|
|
|
@ccclass('Factory')
|
|
export abstract class Factory<T> {
|
|
@property(Prefab)
|
|
protected prefab: Prefab;
|
|
|
|
public init() {}
|
|
public abstract create(parent: Node): T;
|
|
}
|
|
|
|
@ccclass('FactoryComponent')
|
|
export abstract class FactoryComponent<T> extends Component {
|
|
@property(Prefab)
|
|
protected prefab: Prefab;
|
|
|
|
protected onLoad(): void {
|
|
this.init();
|
|
}
|
|
|
|
public init() {}
|
|
|
|
public abstract create(parent: Node): T;
|
|
}
|