12345678 |
- {
- "code": "var Vector3 = Laya.Vector3;\r\nimport { SceneManager } from \"../Main/SceneManager\";\r\nimport { GameUtils } from \"./GameUtils\";\r\nexport class RigObj {\r\n constructor(_target, _complete = null, autocleartime = 2.5, rottime = 0) {\r\n this.awake = false;\r\n this.minhight = 0;\r\n this.mforce = 0;\r\n this.starty = 0;\r\n this.offestY = 0;\r\n this.g = 0.1;\r\n this.m_time = 0;\r\n this.curPos = new Vector3();\r\n this.screenhit = new Laya.HitResult();\r\n this.enter = false;\r\n this.completecallback = _complete;\r\n Laya.timer.frameLoop(1, this, this.LifeLoop);\r\n if (rottime < autocleartime)\r\n rottime = 0;\r\n this.rottime = rottime;\r\n if (autocleartime > 0) {\r\n var lifetime = autocleartime > rottime ? autocleartime : rottime;\r\n Laya.timer.once(1000 * lifetime, this, this.Destory);\r\n }\r\n this.msprite = _target;\r\n this.starty = _target.transform.position.y;\r\n this.minhight = this.starty;\r\n }\r\n AddForce(_dir, _force, _rotSpeed = 1) {\r\n this.awake = true;\r\n this.curdir = new Vector3();\r\n Vector3.normalize(_dir, this.curdir);\r\n Vector3.scale(this.curdir, _force, this.curdir);\r\n var xr = Math.random() > 0.5 ? 1 : -1;\r\n var yr = Math.random() > 0.5 ? 1 : -1;\r\n var zr = Math.random() > 0.5 ? 1 : -1;\r\n this.currotdir = new Vector3(Math.random() * 0.02 * xr * _rotSpeed, Math.random() * 0.02 * yr * _rotSpeed, Math.random() * 0.02 * zr * _rotSpeed);\r\n }\r\n LifeLoop() {\r\n if (!this.awake)\r\n return;\r\n var checkdis = this.PlaneCheck;\r\n if (checkdis != null && checkdis <= 0) {\r\n this.Destory();\r\n return;\r\n }\r\n ;\r\n var mpos = this.msprite.transform.position;\r\n this.m_time += 0.005;\r\n this.offestY -= this.g * this.m_time * this.m_time;\r\n Vector3.add(mpos, this.curdir, this.curPos);\r\n Vector3.lerp(mpos, this.curPos, 0.12, this.curPos);\r\n this.msprite.transform.rotate(this.currotdir);\r\n if (this.msprite.transform.position.y >= this.minhight) {\r\n var curoffestx = this.curPos.x - mpos.x;\r\n var curoffesty = this.curPos.y - mpos.y + this.offestY;\r\n var curoffextz = this.curPos.z - mpos.z;\r\n Vector3.add(mpos, new Vector3(curoffestx, curoffesty, curoffextz), this.curPos);\r\n this.msprite.transform.position = this.curPos;\r\n }\r\n if (curoffesty < 0 && this.msprite.transform.position.y < this.minhight && this.rottime > 0) {\r\n this.msprite.transform.position = new Vector3(mpos.x, this.minhight, mpos.z);\r\n this.Destory();\r\n }\r\n }\r\n Destory() {\r\n this.Clear();\r\n this.FallDown(() => {\r\n if (this.completecallback != null) {\r\n this.completecallback();\r\n }\r\n });\r\n }\r\n Clear() {\r\n Laya.timer.clearAll(this);\r\n Laya.timer.clear(this, this.LifeLoop);\r\n }\r\n FallDown(_cb) {\r\n var mpos = this.msprite.transform.position.clone();\r\n var targetpos = new Vector3(mpos.x, mpos.y - 2, mpos.z);\r\n GameUtils.TweenMove(this.msprite.transform, targetpos, 0.8, Laya.Handler.create(this, () => {\r\n _cb();\r\n }));\r\n }\r\n get PlaneCheck() {\r\n var centerpos = this.msprite.transform.position;\r\n var curray = new Laya.Ray(centerpos, new Vector3(0, -1, 0));\r\n if (SceneManager.mainscene.physicsSimulation.rayCast(curray, this.screenhit, 100)) {\r\n if (this.screenhit) {\r\n var dis = this.msprite.transform.position.y - this.screenhit.point.y;\r\n if (dis > 0) {\r\n return dis;\r\n }\r\n }\r\n return null;\r\n }\r\n else {\r\n return null;\r\n }\r\n }\r\n}\r\n",
- "references": [
- "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/SceneManager.ts",
- "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Util/GameUtils.ts"
- ]
- }
|