|
@@ -0,0 +1,175 @@
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+export default class Game_Tool {
|
|
|
|
+
|
|
|
|
+ public static GetObjKey(obj: any) {
|
|
|
|
+ if (obj == null) return null;
|
|
|
|
+ for (const key in obj) {
|
|
|
|
+ if (obj.hasOwnProperty(key)) {
|
|
|
|
+ return key;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //返回一个随机整数[min,max]
|
|
|
|
+ public static randomInt(min: any, max: any): number {
|
|
|
|
+ return parseInt(Math.random() * (max - min + 1) + min);
|
|
|
|
+ }
|
|
|
|
+ //p1 左向量 p2
|
|
|
|
+ public static getAng(xx: number, yy: number, obl: number): number {
|
|
|
|
+ return 180 / Math.PI * this.getRad(xx, yy, obl);
|
|
|
|
+ }
|
|
|
|
+ //返回角度
|
|
|
|
+ public static getRad(xx: number, yy: number, obl: number): number {
|
|
|
|
+ // 方法一:asin()
|
|
|
|
+ // var rad:Number = xx > 0 ? ((Math.PI * 3)/2 + Math.asin(-yy/obl)) : (Math.PI / 2 - Math.asin(-yy/obl));
|
|
|
|
+ // 方法二:acos()
|
|
|
|
+ var rad: number = yy < 0 ? Math.acos(xx / obl) : (Math.PI * 2 - Math.acos(xx / obl));
|
|
|
|
+ // 方法三:atan2()
|
|
|
|
+ // var rad:Number = yy < 0 ? Math.atan2(-yy, xx) : Math.PI * 2 + Math.atan2(-yy, xx);
|
|
|
|
+ return rad;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static getM_Vector(v1: Laya.Vector3, v2: Laya.Vector3): Laya.Vector3 {
|
|
|
|
+ let temp = new Laya.Vector3();
|
|
|
|
+ Laya.Vector3.add(v1, v2, temp);
|
|
|
|
+ return new Laya.Vector3(temp.x * 0.5, temp.y * 0.5, temp.z * 0.5);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static random_1to1():number{
|
|
|
|
+ var iszheng=Math.random()>0.5?-1:1;
|
|
|
|
+ return Math.random()*iszheng;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static get64Encode(str): string {
|
|
|
|
+ var c1, c2, c3;
|
|
|
|
+ var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
+ var i = 0, len = str.length, string = '';
|
|
|
|
+ while (i < len) {
|
|
|
|
+ c1 = str.charCodeAt(i++) & 0xff;
|
|
|
|
+ if (i == len) {
|
|
|
|
+ string += base64EncodeChars.charAt(c1 >> 2);
|
|
|
|
+ string += base64EncodeChars.charAt((c1 & 0x3) << 4);
|
|
|
|
+ string += "==";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ c2 = str.charCodeAt(i++);
|
|
|
|
+ if (i == len) {
|
|
|
|
+ string += base64EncodeChars.charAt(c1 >> 2);
|
|
|
|
+ string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
|
|
|
|
+ string += base64EncodeChars.charAt((c2 & 0xF) << 2);
|
|
|
|
+ string += "=";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ c3 = str.charCodeAt(i++);
|
|
|
|
+ string += base64EncodeChars.charAt(c1 >> 2);
|
|
|
|
+ string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
|
|
|
|
+ string += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
|
|
|
|
+ string += base64EncodeChars.charAt(c3 & 0x3F)
|
|
|
|
+ }
|
|
|
|
+ return string;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // public static SetHuTuiList(list:Laya.List,data?,scrol:number=1,type:number=0){ //scrol 1:竖的 2横的
|
|
|
|
+ // var arr=data?data:FYHD_Sdk.pushData;
|
|
|
|
+ // list.selectEnable = false;
|
|
|
|
+ // scrol==1?list.vScrollBarSkin = "":list.hScrollBarSkin = "";
|
|
|
|
+ // list.renderHandler = Laya.Handler.create(this, this.updateItem, [type], false);
|
|
|
|
+ // list.array = arr;
|
|
|
|
+ // list.refresh();
|
|
|
|
+ // }
|
|
|
|
+ // private static updateItem(type,cell: Laya.Box, index: number){
|
|
|
|
+ // var aditem=cell.getComponent(HuiTuiItem)as HuiTuiItem;
|
|
|
|
+ // aditem.Refresh(type);
|
|
|
|
+ // }
|
|
|
|
+ public static makeRandomArr(arrList,num){
|
|
|
|
+ if(num>arrList.length){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ var tempArr=arrList.slice(0);
|
|
|
|
+ var newArrList=[];
|
|
|
|
+ for(var i=0;i<num;i++){
|
|
|
|
+ var random=Math.floor(Math.random()*(tempArr.length-1));
|
|
|
|
+ var arr=tempArr[random];
|
|
|
|
+ tempArr.splice(random, 1);
|
|
|
|
+ newArrList.push(arr);
|
|
|
|
+ }
|
|
|
|
+ return newArrList;
|
|
|
|
+ }
|
|
|
|
+ public static CopyArr(o):any{
|
|
|
|
+ var arr=[];
|
|
|
|
+ for (let index = 0; index < o.length; index++) {
|
|
|
|
+ const element = o[index];
|
|
|
|
+ arr.push(element);
|
|
|
|
+ }
|
|
|
|
+ return arr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // public static ShowQianDao(): boolean {
|
|
|
|
+ // let todayZero = new Date(UserModel.Instance.CurModel.ServerTime * 1000);
|
|
|
|
+ // todayZero.setHours(0, 0, 0, 0);
|
|
|
|
+ // if(!PlayerManager.Instance.sign)return true;
|
|
|
|
+ // var lastTime = Number(PlayerManager.Instance.sign["sign_time"]) * 1000;
|
|
|
|
+ // let lastSignTime = new Date(lastTime);
|
|
|
|
+ // if (lastTime == 0) {
|
|
|
|
+ // return true;
|
|
|
|
+ // }
|
|
|
|
+ // if (lastSignTime.valueOf() < todayZero.valueOf()) {
|
|
|
|
+ // return true;
|
|
|
|
+ // }
|
|
|
|
+ // return false;
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ public static TweenGoldAward(_num:number,_pos:Laya.Vector2 = null,_completeHandle:Laya.Handler = null)
|
|
|
|
+ {
|
|
|
|
+ if(_num == 0)return;
|
|
|
|
+ var parent = new Laya.Box;
|
|
|
|
+ parent.width = 400;
|
|
|
|
+ parent.height = 100;
|
|
|
|
+ parent.pivotX = parent.width/2;
|
|
|
|
+ parent.pivotY = parent.height/2;
|
|
|
|
+ if(_pos == null)
|
|
|
|
+ {
|
|
|
|
+ _pos = new Laya.Vector2(Laya.stage.width/2,Laya.stage.height/2);
|
|
|
|
+ }
|
|
|
|
+ parent.pos(_pos.x,_pos.y);
|
|
|
|
+
|
|
|
|
+ var _Image = new Laya.Image;
|
|
|
|
+ _Image.skin = "main_res/sign_icon.png";
|
|
|
|
+ _Image.width = 60;
|
|
|
|
+ _Image.height = 60;
|
|
|
|
+ _Image.left = 50;
|
|
|
|
+ _Image.y = 10;
|
|
|
|
+ parent.addChild(_Image);
|
|
|
|
+
|
|
|
|
+ var curText = new Laya.Text;
|
|
|
|
+ curText.width = 300;
|
|
|
|
+ curText.height = 50;
|
|
|
|
+
|
|
|
|
+ curText.align = "center";
|
|
|
|
+ curText.valign = "middle";
|
|
|
|
+ curText.font = "Microsoft YaHei";
|
|
|
|
+ curText.fontSize = 35;
|
|
|
|
+ curText.color = "#ff8e00";
|
|
|
|
+ curText.bold = true;
|
|
|
|
+ curText.font = "Microsoft YaHei";
|
|
|
|
+ curText.text = "金币 +" + _num;
|
|
|
|
+ curText.x = 60;
|
|
|
|
+ curText.y = 10;
|
|
|
|
+ parent.addChild(curText);
|
|
|
|
+ parent.zOrder=2;
|
|
|
|
+ Laya.stage.addChild(parent);
|
|
|
|
+ var tween = Laya.Tween.to(parent,{y:parent.y - 200},1000,Laya.Ease.expoInOut,Laya.Handler.create(this,()=>
|
|
|
|
+ {
|
|
|
|
+ tween.clear();
|
|
|
|
+ parent.destroy();
|
|
|
|
+ if(_completeHandle)
|
|
|
|
+ {
|
|
|
|
+ _completeHandle.run();
|
|
|
|
+ }
|
|
|
|
+ }),100);
|
|
|
|
+ }
|
|
|
|
+}
|