50817ea21eda8accc724ac06e490684c3e190150 12 KB

123456789
  1. {
  2. "code": "var Vector3 = Laya.Vector3;\r\nimport { SceneManager } from \"../Main/SceneManager\";\r\nexport class GameUtils {\r\n static ScaleVector3(v3, f) {\r\n return new Vector3(v3.x * f, v3.y * f, v3.z * f);\r\n }\r\n static getConverseVector3(_vector3) {\r\n return new Vector3(-_vector3.x, -_vector3.y, -_vector3.z);\r\n }\r\n static angleToEangle(_angle) {\r\n return _angle * Math.PI / 180;\r\n }\r\n static absEangle(_angle) {\r\n var x = _angle.x;\r\n if (x == -0) {\r\n x = 0;\r\n }\r\n var y = _angle.y;\r\n if (y == -0) {\r\n y = 0;\r\n }\r\n var z = _angle.z;\r\n if (z == -0) {\r\n z = 0;\r\n }\r\n return new Vector3(x, y, z);\r\n }\r\n static debugVector3(_vector3) {\r\n console.log(_vector3.x + \" \" + _vector3.y + \" \" + _vector3.z);\r\n }\r\n static getRandomInt(left, right) {\r\n if (left > right) {\r\n return 0;\r\n }\r\n var size = right - left + 1;\r\n var curNumber = Math.random() * size + left;\r\n return Math.floor(curNumber);\r\n }\r\n static getRandomfloat(left, right) {\r\n if (left >= right) {\r\n return 0;\r\n }\r\n var size = right - left;\r\n var curNumber = Math.random() * size + left;\r\n return curNumber;\r\n }\r\n static Vector2Length(_pos1, _pos2) {\r\n var offestx = _pos1.x - _pos2.x;\r\n var offestz = _pos1.y - _pos2.y;\r\n var v1 = Math.pow(offestx, 2);\r\n var v2 = Math.pow(offestz, 2);\r\n var dis = Math.sqrt(v1 + v2);\r\n return dis;\r\n }\r\n static Vector32Length(_pos1, _pos2) {\r\n var offestx = _pos1.x - _pos2.x;\r\n var offestz = _pos1.z - _pos2.z;\r\n var v1 = Math.pow(offestx, 2);\r\n var v2 = Math.pow(offestz, 2);\r\n var dis = Math.sqrt(v1 + v2);\r\n return dis;\r\n }\r\n static Vector3Angle(_dir1, _dir2) {\r\n var v = Vector3.dot(_dir1, _dir2);\r\n var av = Vector3.scalarLength(_dir1);\r\n var bv = Vector3.scalarLength(_dir2);\r\n var vv = av * bv;\r\n var cosa = v / vv;\r\n var angle = Math.acos(cosa) * 180 / Math.PI;\r\n return angle;\r\n }\r\n static Angle(ma, mb) {\r\n var v1 = (ma.x * mb.x) + (ma.y * mb.y) + (ma.z * mb.z);\r\n var ma_val = Math.sqrt(ma.x * ma.x + ma.y * ma.y + ma.z * ma.z);\r\n var mb_val = Math.sqrt(mb.x * mb.x + mb.y * mb.y + mb.z * mb.z);\r\n var cosM = v1 / (ma_val * mb_val);\r\n var angleAMB = Math.acos(cosM) * 180 / Math.PI;\r\n return angleAMB;\r\n }\r\n static SetColliderLay(_node, _lay) {\r\n var childNumber = _node.numChildren;\r\n var PhysicsCollider = _node.getComponent(Laya.PhysicsCollider);\r\n if (PhysicsCollider) {\r\n PhysicsCollider.collisionGroup = _lay;\r\n PhysicsCollider.friction = 1;\r\n PhysicsCollider.restitution = 0;\r\n }\r\n for (var i = 0; i < childNumber; i++) {\r\n var eChildNumber = _node.getChildAt(i).numChildren;\r\n if (eChildNumber > 0) {\r\n this.SetColliderLay(_node.getChildAt(i), _lay);\r\n }\r\n var PhysicsCollider = _node.getChildAt(i).getComponent(Laya.PhysicsCollider);\r\n if (PhysicsCollider) {\r\n PhysicsCollider.collisionGroup = _lay;\r\n PhysicsCollider.friction = 1;\r\n PhysicsCollider.restitution = 0;\r\n }\r\n }\r\n }\r\n static TweenButton(_btn, _complete) {\r\n _btn.mouseEnabled = false;\r\n if (_btn.anchorX != 0.5) {\r\n _btn.anchorX = 0.5;\r\n _btn.anchorY = 0.5;\r\n _btn.x += _btn.width / 2;\r\n _btn.y += _btn.height / 2;\r\n }\r\n Laya.Tween.to(_btn, { scaleX: 1.2, scaleY: 1.2 }, 150, Laya.Ease.quadOut, Laya.Handler.create(this, () => {\r\n Laya.Tween.to(_btn, { scaleX: 1, scaleY: 1 }, 100, Laya.Ease.quadIn, Laya.Handler.create(this, () => {\r\n _btn.mouseEnabled = true;\r\n _complete();\r\n }));\r\n }));\r\n }\r\n static TweenMove(targetTransform, TargetPos, duration, _completeHandle = null, ease = null, lookPos = null) {\r\n var curPos = targetTransform.position;\r\n var tween = Laya.Tween.to(curPos, { x: TargetPos.x, y: TargetPos.y, z: TargetPos.z, update: new Laya.Handler(this, function () {\r\n if (lookPos)\r\n targetTransform.lookAt(lookPos, new Laya.Vector3(0, 1, 0));\r\n targetTransform.position = curPos;\r\n }) }, duration * 1000, ease, Laya.Handler.create(this, function () {\r\n tween.clear();\r\n if (_completeHandle != null) {\r\n _completeHandle.run();\r\n }\r\n }));\r\n return tween;\r\n }\r\n static TweenERot(targetTransform, TargetRot, duration, _completeHandle = null, ease = null) {\r\n var curPos = targetTransform.rotationEuler;\r\n var tween = Laya.Tween.to(curPos, { x: TargetRot.x, y: TargetRot.y, z: TargetRot.z, update: new Laya.Handler(this, function () {\r\n targetTransform.rotationEuler = curPos;\r\n }) }, duration * 1000, ease, Laya.Handler.create(this, function () {\r\n tween.clear();\r\n if (_completeHandle != null) {\r\n _completeHandle.run();\r\n }\r\n }));\r\n return tween;\r\n }\r\n static TweenProgress(_progress, _fromValue, _tovalue, _duration, _completeHandle = null) {\r\n _progress.value = _fromValue;\r\n var tween = Laya.Tween.to(_progress, { value: _tovalue }, _duration * 1000, null, _completeHandle);\r\n return tween;\r\n }\r\n static lerp(form, to, t) {\r\n if (t <= 0) {\r\n return form;\r\n }\r\n else if (t >= 1) {\r\n return to;\r\n }\r\n var a = t * to + (1 - t) * form;\r\n return a;\r\n }\r\n static DelayToDo(_delayDuration, _doFunction) {\r\n Laya.timer.once(_delayDuration * 1000, this, _doFunction);\r\n }\r\n static ArrayContainsItem(_array, _item) {\r\n let index = _array.indexOf(_item);\r\n if (index != -1) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n static PathangleLength(pts) {\r\n var le = 0;\r\n var r = 5;\r\n for (var i = 0; i < pts.length - 1; i++) {\r\n var dis = Vector3.distance(pts[i], pts[i + 1]);\r\n le += dis;\r\n }\r\n return le;\r\n }\r\n static TweenText(message, _hight, _completeHandle = null, _duration = 1000) {\r\n var mes = new Laya.Text();\r\n mes.width = message.size.x;\r\n mes.height = message.size.y;\r\n mes.align = \"center\";\r\n mes.valign = \"middle\";\r\n mes.font = \"Microsoft YaHei\";\r\n mes.fontSize = message.fontSize;\r\n mes.pivotX = mes.width / 2;\r\n mes.pivotY = mes.height / 2;\r\n mes.color = \"#5ad122\";\r\n mes.bold = true;\r\n mes.stroke = 5;\r\n mes.strokeColor = \"#ffffff\";\r\n if (message.color) {\r\n message.color = message.color;\r\n }\r\n mes.text = message.message;\r\n mes.zOrder = 1;\r\n Laya.stage.addChildAt(mes, Laya.stage.numChildren - 1);\r\n mes.pos(message.pos.x, message.pos.y);\r\n var tween = Laya.Tween.to(mes, { y: mes.y - _hight, update: new Laya.Handler(this, function () {\r\n }) }, _duration, Laya.Ease.expoInOut, Laya.Handler.create(this, function () {\r\n tween.clear();\r\n mes.destroy();\r\n if (_completeHandle) {\r\n _completeHandle.run();\r\n }\r\n }));\r\n Laya.Tween.to(mes, { alpha: 0.4 }, _duration, Laya.Ease.backInOut);\r\n return mes;\r\n }\r\n static TweenGold(_vector3, _topos) {\r\n var viewpos = new Laya.Vector3();\r\n SceneManager.maincamera.worldToViewportPoint(_vector3, viewpos);\r\n var goldsprite = new Laya.Image;\r\n goldsprite.width = 51;\r\n goldsprite.height = 53;\r\n goldsprite.pivotX = goldsprite.width / 2;\r\n goldsprite.pivotY = goldsprite.height / 2;\r\n Laya.stage.addChild(goldsprite);\r\n goldsprite.x = viewpos.x;\r\n goldsprite.y = viewpos.y;\r\n goldsprite.skin = \"game/zhujiemian-1-7.png\";\r\n Laya.Tween.to(goldsprite, {\r\n x: _topos.x, y: _topos.y, alpha: 0.4\r\n }, 1000, null, Laya.Handler.create(this, () => {\r\n if (goldsprite)\r\n goldsprite.destroy();\r\n }), null, false);\r\n }\r\n static GetMoney(_num, _pos = null, _completeHandle = null) {\r\n if (_num == 0)\r\n return;\r\n var mbox = new Laya.Box;\r\n mbox.width = 400;\r\n mbox.height = 100;\r\n mbox.pivotX = mbox.width / 2;\r\n mbox.pivotY = mbox.height / 2;\r\n if (_pos == null) {\r\n _pos = new Laya.Vector2(Laya.stage.width / 2, Laya.stage.height / 2);\r\n }\r\n mbox.pos(_pos.x, _pos.y);\r\n var mimage = new Laya.Image;\r\n mimage.skin = \"game/jiesuan-1-6.png\";\r\n mimage.width = 81;\r\n mimage.height = 87;\r\n mimage.left = 50;\r\n mimage.y = 10;\r\n mbox.addChild(mimage);\r\n var mtext = new Laya.Text;\r\n mtext.width = 300;\r\n mtext.height = 50;\r\n mtext.align = \"left\";\r\n mtext.valign = \"middle\";\r\n mtext.font = \"Microsoft YaHei\";\r\n mtext.fontSize = 45;\r\n mtext.color = \"#FFFFFF\";\r\n mtext.bold = true;\r\n mtext.font = \"Microsoft YaHei\";\r\n mtext.text = \"金币 +\" + _num;\r\n mtext.x = 150;\r\n mtext.y = 25;\r\n mbox.addChild(mtext);\r\n Laya.stage.addChild(mbox);\r\n var curtween = Laya.Tween.to(mbox, { y: mbox.y - 200 }, 1500, Laya.Ease.expoInOut, Laya.Handler.create(this, () => {\r\n curtween.clear();\r\n mbox.destroy();\r\n if (_completeHandle) {\r\n _completeHandle.run();\r\n }\r\n }), 100);\r\n return mbox;\r\n }\r\n static DirToAngle(_dir) {\r\n var dir = new Vector3(Math.round(_dir.x * 10) / 10, Math.round(_dir.y * 10) / 10, Math.round(_dir.z * 10) / 10);\r\n if (dir.x == -0) {\r\n dir = new Vector3(0, dir.y, dir.z);\r\n }\r\n if (dir.y == -0) {\r\n dir = new Vector3(dir.x, 0, dir.z);\r\n }\r\n if (dir.z == -0) {\r\n dir = new Vector3(dir.x, dir.y, 0);\r\n }\r\n var reangle = Math.atan(dir.y / dir.z) * 180 / Math.PI;\r\n if (dir.z < 0)\r\n reangle += 180;\r\n reangle -= 90;\r\n var hangle = reangle * Math.PI / 180;\r\n return hangle;\r\n }\r\n static YNAngleToVe(_dir) {\r\n var hangle = this.DirToAngle(_dir);\r\n var dirx = Math.cos(hangle);\r\n var diry = Math.sin(hangle);\r\n return new Vector3(0, diry, dirx);\r\n }\r\n static DirRotYToDir(_dir, _angle) {\r\n var outdir = new Vector3();\r\n return outdir;\r\n }\r\n}\r\n",
  3. "references": [
  4. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/BezierCurve.ts",
  5. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/DataMaker.ts",
  6. "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/SceneManager.ts"
  7. ]
  8. }