54110ace-3702-4102-b34d-ade5c402b418.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. "use strict";
  2. cc._RF.push(module, '54110rONwJBArNNreXEArQY', 'TweenEffect');
  3. // scripts/Framework/TweenEffect.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. exports.EaseType = void 0;
  26. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, menu = _a.menu, executeInEditMode = _a.executeInEditMode;
  27. var EaseType;
  28. (function (EaseType) {
  29. EaseType[EaseType["none"] = 0] = "none";
  30. EaseType[EaseType["fade"] = 1] = "fade";
  31. EaseType[EaseType["easeIn"] = 2] = "easeIn";
  32. EaseType[EaseType["easeOut"] = 3] = "easeOut";
  33. EaseType[EaseType["easeInOut"] = 4] = "easeInOut";
  34. EaseType[EaseType["easeExponentialIn"] = 5] = "easeExponentialIn";
  35. EaseType[EaseType["easeExponentialOut"] = 6] = "easeExponentialOut";
  36. EaseType[EaseType["easeExponentialInOut"] = 7] = "easeExponentialInOut";
  37. EaseType[EaseType["easeSineIn"] = 8] = "easeSineIn";
  38. EaseType[EaseType["easeSineOut"] = 9] = "easeSineOut";
  39. EaseType[EaseType["easeSineInOut"] = 10] = "easeSineInOut";
  40. EaseType[EaseType["easeElasticIn"] = 11] = "easeElasticIn";
  41. EaseType[EaseType["easeElasticOut"] = 12] = "easeElasticOut";
  42. EaseType[EaseType["easeElasticInOut"] = 13] = "easeElasticInOut";
  43. EaseType[EaseType["easeBounceIn"] = 14] = "easeBounceIn";
  44. EaseType[EaseType["easeBounceOut"] = 15] = "easeBounceOut";
  45. EaseType[EaseType["easeBounceInOut"] = 16] = "easeBounceInOut";
  46. EaseType[EaseType["easeBackIn"] = 17] = "easeBackIn";
  47. EaseType[EaseType["easeBackOut"] = 18] = "easeBackOut";
  48. EaseType[EaseType["easeBackInOut"] = 19] = "easeBackInOut";
  49. EaseType[EaseType["easeBezierAction"] = 20] = "easeBezierAction";
  50. EaseType[EaseType["easeQuadraticActionIn"] = 21] = "easeQuadraticActionIn";
  51. EaseType[EaseType["easeQuadraticActionOut"] = 22] = "easeQuadraticActionOut";
  52. EaseType[EaseType["easeQuadraticActionInOut"] = 23] = "easeQuadraticActionInOut";
  53. EaseType[EaseType["easeQuarticActionIn"] = 24] = "easeQuarticActionIn";
  54. EaseType[EaseType["easeQuarticActionOut"] = 25] = "easeQuarticActionOut";
  55. EaseType[EaseType["easeQuarticActionInOut"] = 26] = "easeQuarticActionInOut";
  56. EaseType[EaseType["easeQuinticActionIn"] = 27] = "easeQuinticActionIn";
  57. EaseType[EaseType["easeQuinticActionOut"] = 28] = "easeQuinticActionOut";
  58. EaseType[EaseType["easeQuinticActionInOut"] = 29] = "easeQuinticActionInOut";
  59. EaseType[EaseType["easeCircleActionIn"] = 30] = "easeCircleActionIn";
  60. EaseType[EaseType["easeCircleActionOut"] = 31] = "easeCircleActionOut";
  61. EaseType[EaseType["easeCircleActionInOut"] = 32] = "easeCircleActionInOut";
  62. EaseType[EaseType["easeCubicActionIn"] = 33] = "easeCubicActionIn";
  63. EaseType[EaseType["easeCubicActionOut"] = 34] = "easeCubicActionOut";
  64. EaseType[EaseType["easeCubicActionInOut"] = 35] = "easeCubicActionInOut";
  65. })(EaseType = exports.EaseType || (exports.EaseType = {}));
  66. var TweenType;
  67. (function (TweenType) {
  68. TweenType[TweenType["none"] = 0] = "none";
  69. TweenType[TweenType["line"] = 1] = "line";
  70. TweenType[TweenType["angle"] = 2] = "angle";
  71. TweenType[TweenType["opacity"] = 3] = "opacity";
  72. TweenType[TweenType["scale"] = 4] = "scale";
  73. TweenType[TweenType["skewY"] = 5] = "skewY";
  74. TweenType[TweenType["shake"] = 6] = "shake";
  75. TweenType[TweenType["flip"] = 7] = "flip";
  76. })(TweenType || (TweenType = {}));
  77. var RunTime;
  78. (function (RunTime) {
  79. RunTime[RunTime["onLoad"] = 0] = "onLoad";
  80. RunTime[RunTime["start"] = 1] = "start";
  81. RunTime[RunTime["onEnable"] = 2] = "onEnable";
  82. })(RunTime || (RunTime = {}));
  83. var TweenEffect = /** @class */ (function (_super) {
  84. __extends(TweenEffect, _super);
  85. function TweenEffect() {
  86. var _this = _super !== null && _super.apply(this, arguments) || this;
  87. _this.type = TweenType.none;
  88. _this.easeType = EaseType.none;
  89. _this.run = RunTime.start;
  90. _this.delay = 0;
  91. _this.time = 1;
  92. _this.repeat = -1;
  93. _this.isReverse = false;
  94. _this.num = 0;
  95. _this.toPos = cc.Vec3.ZERO;
  96. _this._tw = null;
  97. return _this;
  98. }
  99. TweenEffect_1 = TweenEffect;
  100. TweenEffect.prototype.onLoad = function () {
  101. this._tw = cc.tween(this.node);
  102. // 间隔
  103. this._tw.delay(this.delay);
  104. // 动作类型
  105. switch (this.type) {
  106. case TweenType.line: {
  107. this._line();
  108. break;
  109. }
  110. case TweenType.angle: {
  111. this._angle();
  112. break;
  113. }
  114. case TweenType.opacity: {
  115. this._opacity();
  116. break;
  117. }
  118. case TweenType.scale: {
  119. this._scale();
  120. break;
  121. }
  122. case TweenType.skewY: {
  123. this._skewY();
  124. break;
  125. }
  126. case TweenType.shake: {
  127. this._shake();
  128. break;
  129. }
  130. case TweenType.flip: {
  131. this._flip();
  132. break;
  133. }
  134. }
  135. // 循环
  136. if (this.repeat > 0) {
  137. this._tw.union().repeat(this.repeat);
  138. }
  139. else if (this.repeat == -1) {
  140. this._tw.union().repeatForever();
  141. }
  142. // 运行
  143. if (this.run == RunTime.onLoad) {
  144. this._tw.start();
  145. }
  146. };
  147. TweenEffect.prototype.start = function () {
  148. if (this.run == RunTime.start) {
  149. this._tw.start();
  150. }
  151. };
  152. TweenEffect.prototype.onEnable = function () {
  153. if (this.run == RunTime.onEnable) {
  154. this.node.stopAllActions();
  155. this._tw.start();
  156. }
  157. };
  158. /** 线性效果 */
  159. TweenEffect.prototype._line = function () {
  160. this._tw.by(this.time, { position: this.toPos }, { easing: TweenEffect_1.getEase(this.easeType) });
  161. if (this.isReverse)
  162. this._tw.by(this.time, { position: this.toPos.neg() }, { easing: TweenEffect_1.getEase(this.easeType) });
  163. };
  164. /** 旋转效果 */
  165. TweenEffect.prototype._angle = function () {
  166. this._tw.by(this.time, { angle: this.num }, { easing: TweenEffect_1.getEase(this.easeType) });
  167. if (this.isReverse)
  168. this._tw.by(this.time, { angle: -this.num }, { easing: TweenEffect_1.getEase(this.easeType) });
  169. };
  170. /** 透明效果 */
  171. TweenEffect.prototype._opacity = function () {
  172. this._tw.by(this.time, { opacity: this.num }, { easing: TweenEffect_1.getEase(this.easeType) });
  173. if (this.isReverse)
  174. this._tw.by(this.time, { opacity: -this.num }, { easing: TweenEffect_1.getEase(this.easeType) });
  175. };
  176. /** 缩放效果 */
  177. TweenEffect.prototype._scale = function () {
  178. this._tw.by(this.time, { scale: this.num }, { easing: TweenEffect_1.getEase(this.easeType) });
  179. if (this.isReverse)
  180. this._tw.by(this.time, { scale: -this.num }, { easing: TweenEffect_1.getEase(this.easeType) });
  181. };
  182. /** 偏斜效果 */
  183. TweenEffect.prototype._skewY = function () {
  184. this._tw.by(this.time, { skewY: this.num }, { easing: TweenEffect_1.getEase(this.easeType) });
  185. if (this.isReverse)
  186. this._tw.by(this.time, { skewY: -this.num }, { easing: TweenEffect_1.getEase(this.easeType) });
  187. };
  188. /** 晃动效果 */
  189. TweenEffect.prototype._shake = function () {
  190. this._tw
  191. .by(this.time, { angle: this.num }, { easing: TweenEffect_1.getEase(this.easeType) })
  192. .by(this.time * 2, { angle: -2 * this.num }, { easing: TweenEffect_1.getEase(this.easeType) })
  193. .by(this.time, { angle: this.num }, { easing: TweenEffect_1.getEase(this.easeType) });
  194. };
  195. /** 翻转效果 */
  196. TweenEffect.prototype._flip = function () {
  197. this._tw
  198. .to(this.time, { scaleX: -this.node.scaleX }, { easing: TweenEffect_1.getEase(this.easeType) })
  199. .to(this.time, { scaleX: this.node.scaleX }, { easing: TweenEffect_1.getEase(this.easeType) });
  200. };
  201. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  202. //////////////////////////// 弹窗效果 //////////////////////////////////////////////////////////////////
  203. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  204. /** 遮罩渐显 */
  205. TweenEffect.panel_mask_opacity = function (node, callback) {
  206. var opacityBack = node.opacity;
  207. node.opacity = 0;
  208. cc.tween(node).to(0.2, { opacity: opacityBack }).call(function () { callback && callback(); }).start();
  209. };
  210. /** 移动Y轴_打开 */
  211. TweenEffect.panel_open_moveY = function (node, callback) {
  212. node.y += 1000;
  213. cc.tween(node).to(0.5, { y: node.y - 1000 }, { easing: "sineOut" }).call(function () { callback && callback(); }).start();
  214. };
  215. /** 移动Y轴_关闭 */
  216. TweenEffect.panel_close_moveY = function (node, callback) {
  217. cc.tween(node).to(0.5, { y: node.y + 1000 }, { easing: "sineIn" }).call(function () { callback && callback(); }).start();
  218. };
  219. /** 缩放Y轴_打开 */
  220. TweenEffect.panel_open_scaleY = function (node, callback) {
  221. node.scaleY = 0;
  222. cc.tween(node).to(0.5, { scaleY: 1 }, { easing: "sineOut" }).call(function () { callback && callback(); }).start();
  223. };
  224. /** 缩放Y轴_关闭 */
  225. TweenEffect.panel_close_scaleY = function (node, callback) {
  226. cc.tween(node).to(0.5, { scaleY: 0 }, { easing: "sineIn" }).call(function () { callback && callback(); }).start();
  227. };
  228. /** 整体缩放_打开 */
  229. TweenEffect.panel_open_scale = function (node, callback) {
  230. node.scale = 0;
  231. cc.tween(node).to(0.5, { scale: 1 }, { easing: "sineOut" }).call(function () { callback && callback(); }).start();
  232. };
  233. /** 整体缩放_关闭 */
  234. TweenEffect.panel_close_scale = function (node, callback) {
  235. cc.tween(node).to(0.5, { scale: 0 }, { easing: "sineIn" }).call(function () { callback && callback(); }).start();
  236. };
  237. /** 透明度缩放_打开 */
  238. TweenEffect.panel_open_opacity_scale = function (node, callback) {
  239. node.opacity = 0;
  240. node.scale = 1.5;
  241. cc.tween(node).to(0.5, { opacity: 255, scale: 1 }, { easing: "fade" }).call(function () { callback && callback(); }).start();
  242. };
  243. /** 透明度缩放_关闭 */
  244. TweenEffect.panel_close_opacity_scale = function (node, callback) {
  245. cc.tween(node).to(0.5, { opacity: 0, scale: 2 }, { easing: "fade" }).call(function () { callback && callback(); }).start();
  246. };
  247. /** 获取ease类型 */
  248. TweenEffect.getEase = function (type) {
  249. switch (type) {
  250. case EaseType.none: return "linear";
  251. case EaseType.fade: return "fade";
  252. case EaseType.easeOut: return "easeOut";
  253. case EaseType.easeInOut: return "easeInOut";
  254. case EaseType.easeExponentialIn: return "easeExponentialIn";
  255. case EaseType.easeExponentialOut: return "easeExponentialOut";
  256. case EaseType.easeExponentialInOut: return "easeExponentialInOut";
  257. case EaseType.easeSineIn: return "sineIn";
  258. case EaseType.easeSineOut: return "sineOut";
  259. case EaseType.easeSineInOut: return "sineInOut";
  260. case EaseType.easeElasticIn: return "elasticIn";
  261. case EaseType.easeElasticOut: return "elasticOut";
  262. case EaseType.easeElasticInOut: return "elasticInOut";
  263. case EaseType.easeBounceIn: return "bounceIn";
  264. case EaseType.easeBounceOut: return "bounceOut";
  265. case EaseType.easeBackIn: return "backIn";
  266. case EaseType.easeBackOut: return 'backOut';
  267. case EaseType.easeBackInOut: return "backInOut";
  268. case EaseType.easeQuadraticActionIn: return "quadraticActionIn";
  269. case EaseType.easeQuadraticActionOut: return "quadraticActionOut";
  270. case EaseType.easeQuadraticActionInOut: return "quadraticActionInOut";
  271. case EaseType.easeQuarticActionIn: return "quarticActionIn";
  272. case EaseType.easeQuarticActionOut: return "quarticActionOut";
  273. case EaseType.easeQuarticActionInOut: return "quarticActionInOut";
  274. case EaseType.easeQuinticActionIn: return "quinticActionIn";
  275. case EaseType.easeQuinticActionOut: return "quinticActionOut";
  276. case EaseType.easeQuinticActionInOut: return "quinticActionInOut";
  277. case EaseType.easeCircleActionIn: return "easeCircleActionIn";
  278. case EaseType.easeCircleActionOut: return "circleActionOut";
  279. case EaseType.easeCircleActionInOut: return "circleActionInOut";
  280. case EaseType.easeCubicActionIn: return "cubicActionIn";
  281. case EaseType.easeCubicActionOut: return "cubicActionOut";
  282. case EaseType.easeCubicActionInOut: return "cubicActionInOut";
  283. }
  284. };
  285. var TweenEffect_1;
  286. __decorate([
  287. property({ type: cc.Enum(TweenType), tooltip: "动作类型" })
  288. ], TweenEffect.prototype, "type", void 0);
  289. __decorate([
  290. property({ type: cc.Enum(EaseType) })
  291. ], TweenEffect.prototype, "easeType", void 0);
  292. __decorate([
  293. property({ type: cc.Enum(RunTime), tooltip: "运行条件" })
  294. ], TweenEffect.prototype, "run", void 0);
  295. __decorate([
  296. property({ type: cc.Float, tooltip: "开始延迟时间" })
  297. ], TweenEffect.prototype, "delay", void 0);
  298. __decorate([
  299. property({ type: cc.Float, tooltip: "单次运行时间" })
  300. ], TweenEffect.prototype, "time", void 0);
  301. __decorate([
  302. property({ type: cc.Integer, tooltip: "重复次数 -1永久重复 0不重复" })
  303. ], TweenEffect.prototype, "repeat", void 0);
  304. __decorate([
  305. property({ tooltip: "是否倒置" })
  306. ], TweenEffect.prototype, "isReverse", void 0);
  307. __decorate([
  308. property({ tooltip: "目标值", visible: function () { return this.type == TweenType.angle || this.type == TweenType.opacity || this.type == TweenType.scale || this.type == TweenType.skewY; } })
  309. ], TweenEffect.prototype, "num", void 0);
  310. __decorate([
  311. property({ tooltip: "目标坐标", visible: function () { return this.type == TweenType.line; } })
  312. ], TweenEffect.prototype, "toPos", void 0);
  313. TweenEffect = TweenEffect_1 = __decorate([
  314. ccclass,
  315. menu("Tools/TweenEffect")
  316. ], TweenEffect);
  317. return TweenEffect;
  318. }(cc.Component));
  319. exports.default = TweenEffect;
  320. cc._RF.pop();