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.
67 lines
2.0 KiB
67 lines
2.0 KiB
/*
|
|
* @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);
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|