ecc3ab1b20d506048c6339919169a75061d04de0.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, Node, Vec3, v3, _dec, _dec2, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _crd, ccclass, property, v3_1, v3_2, ROTATION_STRENGTH, ThirdPersonCamera;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. return {
  8. setters: [function (_cc) {
  9. _cclegacy = _cc.cclegacy;
  10. __checkObsolete__ = _cc.__checkObsolete__;
  11. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  12. _decorator = _cc._decorator;
  13. Component = _cc.Component;
  14. Node = _cc.Node;
  15. Vec3 = _cc.Vec3;
  16. v3 = _cc.v3;
  17. }],
  18. execute: function () {
  19. _crd = true;
  20. _cclegacy._RF.push({}, "009c0UpynlBxpEXbqz4RJ4H", "ThirdPersonCamera", undefined);
  21. __checkObsolete__(['_decorator', 'Component', 'Node', 'Vec3', 'v3']);
  22. ({
  23. ccclass,
  24. property
  25. } = _decorator);
  26. v3_1 = v3();
  27. v3_2 = v3();
  28. ROTATION_STRENGTH = 20.0;
  29. _export("ThirdPersonCamera", ThirdPersonCamera = (_dec = ccclass('ThirdPersonCamera'), _dec2 = property(Node), _dec(_class = (_class2 = class ThirdPersonCamera extends Component {
  30. constructor() {
  31. super(...arguments);
  32. _initializerDefineProperty(this, "target", _descriptor, this);
  33. _initializerDefineProperty(this, "lookAtOffset", _descriptor2, this);
  34. _initializerDefineProperty(this, "zoomSensitivity", _descriptor3, this);
  35. _initializerDefineProperty(this, "lenMin", _descriptor4, this);
  36. _initializerDefineProperty(this, "lenMax", _descriptor5, this);
  37. //值越大镜头越远
  38. _initializerDefineProperty(this, "len", _descriptor6, this);
  39. _initializerDefineProperty(this, "rotateVHSeparately", _descriptor7, this);
  40. _initializerDefineProperty(this, "tweenTime", _descriptor8, this);
  41. this._targetLen = 0;
  42. this._targetAngles = v3();
  43. }
  44. start() {
  45. this._targetLen = this.len;
  46. this._targetAngles.set(this.node.eulerAngles);
  47. }
  48. setLenFactor(factor) {
  49. var len = (this.lenMax - this.lenMin) * factor + this.lenMin;
  50. this._targetLen = len;
  51. }
  52. setTargetAngles(x, y, z) {
  53. this._targetAngles.set(x, y, z);
  54. }
  55. lateUpdate(deltaTime) {
  56. if (!this.target) {
  57. return;
  58. }
  59. var t = Math.min(deltaTime / this.tweenTime, 1.0); //rotation
  60. v3_1.set(this.node.eulerAngles);
  61. Vec3.lerp(v3_1, v3_1, this._targetAngles, t);
  62. this.node.setRotationFromEuler(v3_1); //lookat
  63. v3_1.set(this.target.worldPosition);
  64. v3_1.add(this.lookAtOffset); //len and position
  65. this.len = this.len * (1.0 - t) + this._targetLen * t;
  66. v3_2.set(this.node.forward);
  67. v3_2.multiplyScalar(this.len);
  68. v3_1.subtract(v3_2);
  69. this.node.setPosition(v3_1);
  70. }
  71. onCameraRotate(deltaX, deltaY) {
  72. var eulerAngles = this.node.eulerAngles;
  73. if (this.rotateVHSeparately) {
  74. if (Math.abs(deltaX) > Math.abs(deltaY)) {
  75. deltaY = 0;
  76. } else {
  77. deltaX = 0;
  78. }
  79. }
  80. this._targetAngles.set(eulerAngles.x + deltaX * ROTATION_STRENGTH, eulerAngles.y + deltaY * ROTATION_STRENGTH, eulerAngles.z);
  81. }
  82. onCameraZoom(view) {
  83. // this._targetLen += delta * this.zoomSensitivity;
  84. this._targetLen = view;
  85. if (this._targetLen < this.lenMin) {
  86. this._targetLen = this.lenMin;
  87. }
  88. if (this._targetLen > this.lenMax) {
  89. this._targetLen = this.lenMax;
  90. }
  91. }
  92. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "target", [_dec2], {
  93. configurable: true,
  94. enumerable: true,
  95. writable: true,
  96. initializer: null
  97. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "lookAtOffset", [property], {
  98. configurable: true,
  99. enumerable: true,
  100. writable: true,
  101. initializer: function initializer() {
  102. return v3();
  103. }
  104. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "zoomSensitivity", [property], {
  105. configurable: true,
  106. enumerable: true,
  107. writable: true,
  108. initializer: function initializer() {
  109. return 1.0;
  110. }
  111. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "lenMin", [property], {
  112. configurable: true,
  113. enumerable: true,
  114. writable: true,
  115. initializer: function initializer() {
  116. return 10.0;
  117. }
  118. }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "lenMax", [property], {
  119. configurable: true,
  120. enumerable: true,
  121. writable: true,
  122. initializer: function initializer() {
  123. return 100.0;
  124. }
  125. }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "len", [property], {
  126. configurable: true,
  127. enumerable: true,
  128. writable: true,
  129. initializer: function initializer() {
  130. return 5;
  131. }
  132. }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "rotateVHSeparately", [property], {
  133. configurable: true,
  134. enumerable: true,
  135. writable: true,
  136. initializer: function initializer() {
  137. return false;
  138. }
  139. }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "tweenTime", [property], {
  140. configurable: true,
  141. enumerable: true,
  142. writable: true,
  143. initializer: function initializer() {
  144. return 0.2;
  145. }
  146. })), _class2)) || _class));
  147. _cclegacy._RF.pop();
  148. _crd = false;
  149. }
  150. };
  151. });
  152. //# sourceMappingURL=ecc3ab1b20d506048c6339919169a75061d04de0.js.map