消除我特牛
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

4 weeks ago
/*
* @Descripttion:
* @version: 1.0.0
* @Author: YeeChan
* @Date: 2020-07-21 16:48:23
*/
export default class Common {
static Type = 0;
static SpeTip = "";
static subLevel = 0;
static GameSubTipConfigs = null;
static GameSubAnswerConfigs = null;
static GameSubChooseArray = null;
static GameguizeArray = null;
/**
*
* @param prefab
* @param type
* @param parent null Canvas
*/
public static createPrefab_custom<T extends cc.Component>(prefab: cc.Prefab, type: { prototype: T }, parent?: cc.Node,): T {
let node = cc.instantiate(prefab);
if (parent) {
parent.addChild(node);
} else {
cc.director.getScene().getChildByName('Canvas').addChild(node);
}
let src = node.getComponent(type);
return src;
}
/**
*
* @param bundlename
* @param url
* @param parentNode
* @param callback
*/
public static getPrefabFromBundle(bundlename = "subRes_resources", url: string, parentNode: cc.Node =null, callback = null) {
let subres = cc.assetManager.getBundle(bundlename);
if (subres) {
subres.load(url, cc.Prefab, (err, prefab: cc.Prefab) => {
if (err) {
console.log('加载预制体错误>:', err)
return null;
}
console.log("加载成功:", prefab.name);
var prefabNode = cc.instantiate(prefab);
if(parentNode !=null){
parentNode.addChild(prefabNode)
}else{
cc.director.getScene().getChildByName("Canvas").addChild(prefabNode);;
}
// prefabNode.parent = parentNode;
if (callback) {
callback(prefabNode);
}
})
}
}
}