import AssetsBundleMgr from "./AssetsBundleMgr";

export default class AssetMgr {
    // setParent 立刻绑到父节点上
    static instantiate(parentNode: cc.Node, prefab: cc.Prefab | cc.Node, setParent: boolean = true): cc.Node {
        let _node: cc.Node = <cc.Node>cc.instantiate(prefab)
        if (setParent) { _node.parent = parentNode }
        return _node
    }

    // setParent 立刻绑到父节点上
    static instantiateUE<UE>(cls: UEClass<UE>): UE {
        let prefab: cc.Prefab = AssetsBundleMgr.get(cls.BundleKey, cls.PrefabUrl, cc.Prefab);
        let _node: cc.Node = <cc.Node>cc.instantiate(prefab);
        let comp = ((_node.getComponent(cls.CLS) || _node.addComponent(cls as any)) as any);
        return comp
    }
}