6c2572f5afb4c489989c2e9d5101b8d5e19d8305 3.5 KB

12345
  1. {
  2. "code": "export class Mathf {\r\n static GetData(value) {\r\n var theTime = Math.floor(value);\r\n var theTime1 = 0;\r\n var theTime2 = 0;\r\n var theTime3 = 0;\r\n if (theTime > 60) {\r\n theTime1 = Math.floor(theTime / 60);\r\n theTime = theTime % 60;\r\n if (theTime1 > 60) {\r\n theTime2 = Math.floor(theTime1 / 60);\r\n theTime1 = theTime1 % 60;\r\n if (theTime2 > 24) {\r\n theTime3 = Math.floor(theTime2 / 24);\r\n theTime2 = theTime2 % 24;\r\n }\r\n }\r\n }\r\n var result = '';\r\n result = \"\" + theTime1 + \"分\" + result;\r\n result = \"\" + theTime2 + \"时\" + result;\r\n result = \"\" + theTime3 + \"天\" + result;\r\n return result;\r\n }\r\n static GetNumAccuracy(num) {\r\n var b = Math.ceil(num * 10) / 10;\r\n if (Math.abs(b - num) < 0.0001) {\r\n return b;\r\n }\r\n var a = Math.floor(num * 10) / 10;\r\n if (Math.abs(a - num) < 0.0001) {\r\n return a;\r\n }\r\n return num;\r\n }\r\n static get VecZero() {\r\n return new Laya.Vector3();\r\n }\r\n static RandomNumber(from, to) {\r\n if (from >= to) {\r\n return 0;\r\n }\r\n var size = to - from;\r\n var curNumber = Math.random() * size + from;\r\n return curNumber;\r\n }\r\n static SpToCam(v3) {\r\n v3.x = -v3.x;\r\n v3.y = v3.y - 180;\r\n v3.z = -v3.z;\r\n return v3;\r\n }\r\n static get Gravity() {\r\n return new Laya.Vector3(0, -10, 0);\r\n }\r\n static MixVector3(from, to, t, res = null) {\r\n if (res == null) {\r\n res = this.m_mixVector;\r\n }\r\n res.x = Mathf.MixNumber(from.x, to.x, t);\r\n res.y = Mathf.MixNumber(from.y, to.y, t);\r\n res.z = Mathf.MixNumber(from.z, to.z, t);\r\n return res;\r\n }\r\n static MixVector4(from, to, t, res) {\r\n res.x = Mathf.MixNumber(from.x, to.x, t);\r\n res.y = Mathf.MixNumber(from.y, to.y, t);\r\n res.z = Mathf.MixNumber(from.z, to.z, t);\r\n res.w = Mathf.MixNumber(from.w, to.w, t);\r\n return res;\r\n }\r\n static MixNumber(from, to, t) {\r\n t = Mathf.Clamp(t, 0, 1);\r\n from = (to - from) * t + from;\r\n return from;\r\n }\r\n static Clamp(value, from, to) {\r\n if (value < from) {\r\n value = from;\r\n }\r\n if (value > to) {\r\n value = to;\r\n }\r\n return value;\r\n }\r\n}\r\nMathf.m_mixVector = new Laya.Vector3();\r\nexport class FollowNumber {\r\n constructor(t, from = 0, to = 0, tiny = 0) {\r\n this.m_t = 0;\r\n this.target = 0;\r\n this.follow = 0;\r\n this.m_tiny = 0;\r\n this.m_t = t;\r\n this.target = to;\r\n this.follow = from;\r\n this.m_tiny = tiny;\r\n }\r\n ChangeT(value) {\r\n this.m_t = value;\r\n }\r\n get t() { return this.m_t; }\r\n update() {\r\n this.follow = Mathf.MixNumber(this.follow, this.target, this.m_t);\r\n if (this.m_tiny != 0 && this.target != this.follow) {\r\n if (Math.abs(this.target - this.follow) <= this.m_tiny) {\r\n this.follow = this.target;\r\n }\r\n }\r\n }\r\n}\r\n",
  3. "references": []
  4. }