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.
81 lines
2.5 KiB
81 lines
2.5 KiB
import { AssetManager, assetManager } from "cc";
|
|
import { EDITOR, PREVIEW } from "cc/env";
|
|
import { EGlobalEvent } from "../MesEvent/EGlobalEvent";
|
|
import { GameTotalType } from "../const/GameEnum";
|
|
import { IData, ProgressInfo, IDataArray } from "../const/GameInterface";
|
|
import MesMgr from "../MesEvent/MesMgr";
|
|
|
|
|
|
export default class CocosUtils {
|
|
|
|
/**获取进度信息 */
|
|
static GetProgress(data: IData): ProgressInfo {
|
|
let value: ProgressInfo = {
|
|
mType: data.type,
|
|
mNeedID: data.id,
|
|
mCan: false,
|
|
mCur: 0,
|
|
mNeed: data.num,
|
|
}
|
|
value.mCur = MesMgr.ExecuteType(EGlobalEvent.GET_CONDITION_VALUE_EVENT,data) || 0 ;
|
|
value.mCan = value.mCur >= value.mNeed;
|
|
return value;
|
|
}
|
|
|
|
/**获取进度列表 */
|
|
static GetProgressList(list: IDataArray): ProgressInfo[] {
|
|
let infolist: ProgressInfo[] = [];
|
|
for (let i = 0; i < list?.length; i++) {
|
|
const tData = list[i];
|
|
infolist.push(this.GetProgress(tData));
|
|
}
|
|
return infolist;
|
|
}
|
|
|
|
/**检测是否完成 */
|
|
static CheckIfCompleted(list: IDataArray) {
|
|
if (!list) { return true }
|
|
let infolist: ProgressInfo[] = this.GetProgressList(list);
|
|
for (let i = 0; i < infolist.length; i++) {
|
|
const element = infolist[i];
|
|
if (!element.mCan) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**获取匹配的类型数据 */
|
|
public static GetIData(type: GameTotalType | number, datalist: IDataArray) {
|
|
for (let i = 0; i < datalist?.length; i++) {
|
|
const element = datalist[i];
|
|
if (element.type == type) {
|
|
return element;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**根据UUID获取所在Bundle */
|
|
public static GetResBundle(uuid: string): AssetManager.Bundle {
|
|
const map = assetManager.bundles["_map"]
|
|
for (let bundle in map) {
|
|
//如果用uuid 判断
|
|
if (map[bundle]._config.assetInfos._map[uuid]) return map[bundle]
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**根据UUID获取所在Bundle */
|
|
public static GetResBundlePath(uuid: string): string {
|
|
let bundle = this.GetResBundle(uuid);
|
|
EDITOR && ConsoleEx.Log("调用", bundle);
|
|
if (!bundle) return "";
|
|
return bundle.getAssetInfo(uuid)["path"];
|
|
}
|
|
|
|
}
|
|
|
|
if (PREVIEW) {
|
|
window["CocosUtils"] = CocosUtils;
|
|
}
|