123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import { Prefab, UITransform, resources, v3 } from "cc";
- import CountDownSchedule from "./CountDownSchedule";
- export class Global {
- //是否开发环境
- public static IsDevelop = false;
- //事件类型
- public static EventType_AddScore = "AddScore";
- public static EventType_MinusScore = "MinusScore";
- public static EventType_ShowTips = "ShowTips";
- public static EventType_GameOver = "GameOver";
- //音效
- public static Audio_Bg = "/audio/bg"
- public static Audio_Success = "/audio/success"
- public static Audio_GameFail = "/audio/gameFail"
- public static Audio_TimeOutFail = "/audio/timeOutFail"
- public static Audio_right = "/audio/right"
- public static Audio_wrong = "/audio/wrong"
- public static Audio_MinusScore = "/audio/wrong"
- public static Audio_AddScore = "/audio/addScore"
- public static Audio_achieve = "/audio/achieve"
- public static Audio_nextLev = "audio/achieve";
- //游戏
- public static StartLv = 1;
- public static MaxLv = 5;
- public static GameSetTime = 60;
- public static DifficultyRate = 1; //游戏难度系数
- //全局定时器
- public static cdSchedule: CountDownSchedule = new CountDownSchedule();
- /**
- * 获取xxx-xxx之间的随机数
- * @param min 最小数
- * @param max 最大数
- * @returns 随机数字
- */
- public static getRandom(min, max): number {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- /**
- * 获取两个数字之差
- * @param num1
- * @param num2
- * @returns
- */
- public static getDifference(num1, num2): number {
- return Math.abs(num1 - num2);
- }
- /**
- * 数组乱序
- * @param a 数组
- * @returns
- */
- public static randomSort(a) {
- return a.sort(() => Math.random() - 0.5);
- }
- /**
- * 节点间坐标转换
- * @param s
- * @param o
- * @returns
- */
- public static nodeToOtherPos(s, o) {
- return Global.worldConvertLocalPointAR(s, Global.localConvertWorldPointAR(o))
- }
- /**
- * 得到一个节点的世界坐标
- * node的原点在中心
- * @param {*} node
- */
- public static localConvertWorldPointAR(node) {
- if (node) {
- return node.getComponent(UITransform).convertToWorldSpaceAR(v3());
- }
- return null;
- }
- /**
- * 把一个世界坐标的点,转换到某个节点下的坐标
- * 原点在node中心
- * @param {*} node
- * @param {*} worldPoint
- */
- public static worldConvertLocalPointAR(node, worldPoint) {
- if (node) {
- return node.getComponent(UITransform).convertToNodeSpaceAR(worldPoint);
- }
- return null;
- }
- /**
- * resources读取Prefab
- * @param {*} prename prefab地址
- */
- public static async LoadPrefab(prename: string): Promise<Prefab> {
- let res = (r) => {
- return r;
- }
- return new Promise((res) => {
- resources.load(prename, Prefab, (err, node) => {
- res(node);
- });
- });
- }
- }
|