@chiyou/minigame-framework 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/assets/Scripts/index.ts +2 -5
  2. package/package.json +5 -10
  3. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.d.ts +0 -78
  4. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.js +0 -230
  5. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.d.ts +0 -31
  6. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.js +0 -224
  7. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.d.ts +0 -34
  8. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.js +0 -524
  9. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.d.ts +0 -34
  10. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.js +0 -631
  11. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.d.ts +0 -33
  12. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.js +0 -460
  13. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.d.ts +0 -31
  14. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.js +0 -227
  15. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.d.ts +0 -33
  16. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.js +0 -458
  17. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.d.ts +0 -35
  18. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.js +0 -770
  19. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.d.ts +0 -33
  20. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.js +0 -519
  21. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.d.ts +0 -33
  22. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.js +0 -492
  23. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.d.ts +0 -33
  24. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.js +0 -695
  25. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.d.ts +0 -34
  26. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.js +0 -597
  27. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.d.ts +0 -33
  28. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.js +0 -458
  29. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.d.ts +0 -51
  30. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.js +0 -17
  31. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.d.ts +0 -45
  32. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.js +0 -555
  33. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.d.ts +0 -44
  34. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.js +0 -148
  35. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.d.ts +0 -48
  36. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.js +0 -715
  37. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.d.ts +0 -44
  38. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.js +0 -296
  39. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.d.ts +0 -45
  40. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.js +0 -284
  41. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.d.ts +0 -44
  42. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.js +0 -283
  43. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.d.ts +0 -43
  44. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.js +0 -406
  45. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.d.ts +0 -43
  46. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.js +0 -248
  47. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.d.ts +0 -44
  48. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.js +0 -517
  49. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.d.ts +0 -44
  50. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.js +0 -295
  51. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.d.ts +0 -55
  52. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.js +0 -964
  53. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.d.ts +0 -44
  54. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.js +0 -295
  55. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.d.ts +0 -44
  56. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.js +0 -393
  57. package/dist/Framework/Definition/AdDefinition.d.ts +0 -130
  58. package/dist/Framework/Definition/AdDefinition.js +0 -208
  59. package/dist/Framework/Definition/FrameworkBase.d.ts +0 -13
  60. package/dist/Framework/Definition/FrameworkBase.js +0 -23
  61. package/dist/Framework/Definition/PrivacyDefinition.d.ts +0 -51
  62. package/dist/Framework/Definition/PrivacyDefinition.js +0 -70
  63. package/dist/Framework/Definition/SocialDefinition.d.ts +0 -16
  64. package/dist/Framework/Definition/SocialDefinition.js +0 -2
  65. package/dist/Framework/Definition/SystemDefinition.d.ts +0 -43
  66. package/dist/Framework/Definition/SystemDefinition.js +0 -28
  67. package/dist/Framework/Definition/UIDefinition.d.ts +0 -6
  68. package/dist/Framework/Definition/UIDefinition.js +0 -7
  69. package/dist/Framework/Definition/UserDefinition.d.ts +0 -14
  70. package/dist/Framework/Definition/UserDefinition.js +0 -10
  71. package/dist/Framework/Manager/AdMgr.d.ts +0 -57
  72. package/dist/Framework/Manager/AdMgr.js +0 -684
  73. package/dist/Framework/Manager/AudioMgr.d.ts +0 -28
  74. package/dist/Framework/Manager/AudioMgr.js +0 -265
  75. package/dist/Framework/Manager/BaseMgr.d.ts +0 -18
  76. package/dist/Framework/Manager/BaseMgr.js +0 -114
  77. package/dist/Framework/Manager/EventMgr.d.ts +0 -18
  78. package/dist/Framework/Manager/EventMgr.js +0 -90
  79. package/dist/Framework/Manager/ExcelMgr.d.ts +0 -24
  80. package/dist/Framework/Manager/ExcelMgr.js +0 -156
  81. package/dist/Framework/Manager/LifeCycleMgr.d.ts +0 -20
  82. package/dist/Framework/Manager/LifeCycleMgr.js +0 -110
  83. package/dist/Framework/Manager/NodePoolMgr.d.ts +0 -53
  84. package/dist/Framework/Manager/NodePoolMgr.js +0 -279
  85. package/dist/Framework/Manager/PrivacyMgr.d.ts +0 -15
  86. package/dist/Framework/Manager/PrivacyMgr.js +0 -176
  87. package/dist/Framework/Manager/ResMgr.d.ts +0 -49
  88. package/dist/Framework/Manager/ResMgr.js +0 -337
  89. package/dist/Framework/Manager/SocialMgr.d.ts +0 -23
  90. package/dist/Framework/Manager/SocialMgr.js +0 -220
  91. package/dist/Framework/Manager/SystemMgr.d.ts +0 -24
  92. package/dist/Framework/Manager/SystemMgr.js +0 -222
  93. package/dist/Framework/Manager/TimerMgr.d.ts +0 -11
  94. package/dist/Framework/Manager/TimerMgr.js +0 -63
  95. package/dist/Framework/Manager/UIMgr.d.ts +0 -33
  96. package/dist/Framework/Manager/UIMgr.js +0 -223
  97. package/dist/Framework/Manager/UserMgr.d.ts +0 -15
  98. package/dist/Framework/Manager/UserMgr.js +0 -148
  99. package/dist/Framework/Utils/BezierUtils.d.ts +0 -49
  100. package/dist/Framework/Utils/BezierUtils.js +0 -247
  101. package/dist/Framework/Utils/CSVUtils.d.ts +0 -35
  102. package/dist/Framework/Utils/CSVUtils.js +0 -341
  103. package/dist/Framework/Utils/LogUtils.d.ts +0 -7
  104. package/dist/Framework/Utils/LogUtils.js +0 -32
  105. package/dist/Framework/Utils/NumberUtils.d.ts +0 -16
  106. package/dist/Framework/Utils/NumberUtils.js +0 -44
  107. package/dist/Framework/Utils/TaskUtils.d.ts +0 -10
  108. package/dist/Framework/Utils/TaskUtils.js +0 -24
  109. package/dist/Framework/Utils/TimeUtils.d.ts +0 -19
  110. package/dist/Framework/Utils/TimeUtils.js +0 -33
  111. package/dist/Framework/Utils/WXBizDataCryptUtils.d.ts +0 -12
  112. package/dist/Framework/Utils/WXBizDataCryptUtils.js +0 -37
  113. package/dist/index.d.ts +0 -30
  114. package/dist/index.js +0 -35
@@ -1,223 +0,0 @@
1
- import { Component, Node, Button, instantiate, screen, UITransform, v3, view, ResolutionPolicy, tween, Label, Color, Sprite, SpriteFrame, BlockInputEvents, Texture2D } from 'cc';
2
- import { ResMgr } from './ResMgr';
3
- import { LogUtils } from '../Utils/LogUtils';
4
- import { ToastDuration } from '../Definition/UIDefinition';
5
- import { BaseMgr } from './BaseMgr';
6
- export class UICtrl extends Component {
7
- constructor() {
8
- super(...arguments);
9
- this.views = new Map();
10
- }
11
- onLoad() {
12
- this.views = new Map();
13
- this.load_all_object(this.node, "");
14
- }
15
- load_all_object(root, path) {
16
- for (let i = 0; i < root.children.length; i++) {
17
- this.views.set(path + root.children[i].name, root.children[i]);
18
- this.load_all_object(root.children[i], path + root.children[i].name + "/");
19
- }
20
- }
21
- set_button_listener(view_name, clickListener, target) {
22
- let view_node = this.views.get(view_name);
23
- if (!view_node) {
24
- return;
25
- }
26
- let button = view_node.getComponent(Button);
27
- if (!button) {
28
- return;
29
- }
30
- button.node.on("click", clickListener, target);
31
- }
32
- }
33
- export class UIMgr extends BaseMgr {
34
- constructor() {
35
- super(...arguments);
36
- this.canvas = null;
37
- this.uiMap = null;
38
- this.windowWidth = 0;
39
- this.windowHeight = 0;
40
- this.node_toastRoot = null;
41
- this.tween_toast = null;
42
- this.node_dialogRoot = null;
43
- }
44
- print() {
45
- LogUtils.Instance.log("", this.uiMap);
46
- }
47
- onLoad() {
48
- super.onLoad();
49
- if (UIMgr.Instance === null) {
50
- UIMgr.Instance = this;
51
- }
52
- else {
53
- this.destroy();
54
- return;
55
- }
56
- }
57
- init() {
58
- this.canvas = this.node.parent;
59
- this.uiMap = new Map();
60
- let designSize = view.getDesignResolutionSize();
61
- view.setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy.SHOW_ALL);
62
- this.windowWidth = screen.windowSize.width;
63
- this.windowHeight = screen.windowSize.height;
64
- this.node_toastRoot = null;
65
- this.tween_toast = null;
66
- LogUtils.Instance.log(UIMgr.TAG, "init() finished.");
67
- }
68
- create_ui(ui_name, parent) {
69
- let uiPrefab = ResMgr.Instance.getAsset("GUI", "UIPrefabs/" + ui_name);
70
- if (!uiPrefab) {
71
- return null;
72
- }
73
- let uiNode = instantiate(uiPrefab);
74
- if (!uiNode) {
75
- return null;
76
- }
77
- if (parent) {
78
- parent.addChild(uiNode);
79
- }
80
- uiNode.addComponent(ui_name + "_Ctrl");
81
- let array = null;
82
- if (this.uiMap.has(ui_name)) {
83
- array = this.uiMap.get(ui_name);
84
- }
85
- if (array === null) {
86
- array = new Array();
87
- }
88
- array.push(uiNode);
89
- this.uiMap.set(ui_name, array);
90
- return uiNode;
91
- }
92
- destroy_ui(ui_name, node) {
93
- if (this.uiMap.has(ui_name)) {
94
- let array = this.uiMap.get(ui_name);
95
- if (array !== null) {
96
- let index = array.indexOf(node);
97
- if (index >= 0) {
98
- node.removeFromParent();
99
- node.destroy();
100
- array.splice(index, 1);
101
- }
102
- }
103
- if (array === null || array.length === 0) {
104
- this.uiMap.delete(ui_name);
105
- }
106
- else {
107
- this.uiMap.set(ui_name, array);
108
- }
109
- }
110
- }
111
- destroy_ui_all(ui_name) {
112
- if (this.uiMap.has(ui_name)) {
113
- let array = this.uiMap.get(ui_name);
114
- if (array !== null) {
115
- for (let i = 0; i < array.length; i++) {
116
- let node = array[i];
117
- node.removeFromParent();
118
- node.destroy();
119
- }
120
- }
121
- this.uiMap.delete(ui_name);
122
- }
123
- }
124
- clear_ui_all() {
125
- for (let ui_name of this.uiMap.keys()) {
126
- this.destroy_ui_all(ui_name);
127
- }
128
- }
129
- adaptScreen(node) {
130
- // 用于背景适配整个屏幕
131
- let nodeWidth = node.getComponent(UITransform).width;
132
- let nodeHeight = node.getComponent(UITransform).height;
133
- let scrScaleForShowAll = Math.min(this.windowWidth / nodeWidth, this.windowHeight / nodeHeight);
134
- let realWidth = nodeWidth * scrScaleForShowAll;
135
- let realHeight = nodeHeight * scrScaleForShowAll;
136
- let scaleRatio = Math.max(this.windowWidth / realWidth, this.windowHeight / realHeight);
137
- node.scale = v3(scaleRatio, scaleRatio, 1);
138
- }
139
- setToastRootNode(node) {
140
- this.node_toastRoot = node;
141
- }
142
- showToast(content, toastDuration = ToastDuration.Duration_Short) {
143
- if (this.node_toastRoot === null) {
144
- return;
145
- }
146
- if (this.tween_toast !== null) {
147
- this.tween_toast.stop();
148
- this.tween_toast = null;
149
- }
150
- let showTime = 1.5;
151
- if (toastDuration === ToastDuration.Duration_Long) {
152
- showTime = 3;
153
- }
154
- let labelComponent = this.node_toastRoot.getChildByName("Label").getComponent(Label);
155
- labelComponent.string = content;
156
- labelComponent.updateRenderData(true);
157
- let textWidth = labelComponent.node.getComponent(UITransform).contentSize.width;
158
- this.node_toastRoot.active = true;
159
- this.node_toastRoot.getComponent(UITransform).width = textWidth + 80;
160
- this.tween_toast = tween(this.node_toastRoot)
161
- .delay(showTime)
162
- .call(() => {
163
- this.tween_toast = null;
164
- this.node_toastRoot.active = false;
165
- });
166
- this.tween_toast.start();
167
- }
168
- setDialogRootNode(node) {
169
- this.node_dialogRoot = node;
170
- }
171
- openDialog(ui_name, maskColor) {
172
- if (!maskColor) {
173
- maskColor = new Color(51, 51, 51, 230);
174
- }
175
- const whitePixelData = new Uint8Array([maskColor.r, maskColor.g, maskColor.b, maskColor.a]);
176
- const texture = new Texture2D();
177
- texture.reset({
178
- width: 1,
179
- height: 1,
180
- });
181
- texture.uploadData(whitePixelData);
182
- let sf = new SpriteFrame();
183
- sf.texture = texture;
184
- let node_mask = new Node("Node_Mask");
185
- let sprite = node_mask.addComponent(Sprite);
186
- sprite.spriteFrame = sf;
187
- let designSize = view.getDesignResolutionSize();
188
- node_mask.getComponent(UITransform).width = designSize.width;
189
- node_mask.getComponent(UITransform).height = designSize.height;
190
- UIMgr.Instance.adaptScreen(node_mask);
191
- node_mask.addComponent(BlockInputEvents);
192
- let node_agent = new Node();
193
- node_agent.addChild(node_mask);
194
- let node_dialog = this.create_ui(ui_name, node_agent);
195
- if (node_dialog) {
196
- this.node_dialogRoot.addChild(node_agent);
197
- this.node_dialogRoot.active = true;
198
- }
199
- else {
200
- node_agent.destroy();
201
- }
202
- return node_dialog;
203
- }
204
- closeDialog(ui_name, node) {
205
- let hasNode = false;
206
- if (this.uiMap.has(ui_name)) {
207
- let array = this.uiMap.get(ui_name);
208
- if (array !== null) {
209
- let index = array.indexOf(node);
210
- if (index >= 0) {
211
- hasNode = true;
212
- }
213
- }
214
- }
215
- if (hasNode) {
216
- let node_agent = node.parent;
217
- this.destroy_ui(ui_name, node);
218
- node_agent.destroy();
219
- }
220
- }
221
- }
222
- UIMgr.Instance = null;
223
- UIMgr.TAG = "UIMgr";
@@ -1,15 +0,0 @@
1
- import { BaseMgr } from "./BaseMgr";
2
- export declare class UserMgr extends BaseMgr {
3
- static Instance: UserMgr;
4
- static TAG: string;
5
- private newUser;
6
- private isLogin;
7
- onLoad(): void;
8
- init(): void;
9
- private initNewUser;
10
- isNewUser(): boolean;
11
- login(needForceLogin: boolean, callback: Function): void;
12
- private _checkSession;
13
- private _login;
14
- isLogined(): boolean;
15
- }
@@ -1,148 +0,0 @@
1
- import { FrameworkBase } from "../Definition/FrameworkBase";
2
- import { LoginResultType } from "../Definition/UserDefinition";
3
- import { LogUtils } from "../Utils/LogUtils";
4
- import { BaseMgr } from "./BaseMgr";
5
- export class UserMgr extends BaseMgr {
6
- constructor() {
7
- super(...arguments);
8
- this.newUser = false;
9
- this.isLogin = false;
10
- }
11
- onLoad() {
12
- super.onLoad();
13
- if (UserMgr.Instance === null) {
14
- UserMgr.Instance = this;
15
- }
16
- else {
17
- this.destroy();
18
- return;
19
- }
20
- }
21
- init() {
22
- this.initNewUser();
23
- LogUtils.Instance.log(UserMgr.TAG, "init() finished.");
24
- }
25
- initNewUser() {
26
- let userMgr_NewUser = localStorage.getItem(FrameworkBase.LocalStorage.Key_UserMgr_NewUser);
27
- let userInfo_NewUser = localStorage.getItem(FrameworkBase.LocalStorage.Key_UserInfo_NewUser);
28
- if (userMgr_NewUser !== null && userMgr_NewUser === "0") {
29
- this.newUser = false;
30
- }
31
- else if (userInfo_NewUser !== null && userInfo_NewUser === "0") {
32
- this.newUser = false;
33
- localStorage.removeItem(FrameworkBase.LocalStorage.Key_UserInfo_NewUser);
34
- localStorage.setItem(FrameworkBase.LocalStorage.Key_UserMgr_NewUser, "0");
35
- }
36
- else {
37
- this.newUser = true;
38
- localStorage.setItem(FrameworkBase.LocalStorage.Key_UserMgr_NewUser, "0");
39
- }
40
- LogUtils.Instance.log(UserMgr.TAG, "isNewUser=" + this.isNewUser());
41
- }
42
- isNewUser() {
43
- return this.newUser;
44
- }
45
- login(needForceLogin, callback) {
46
- if (callback === null) {
47
- return;
48
- }
49
- if (this.getPlatformAdapter() === null) {
50
- this.isLogin = false;
51
- callback({
52
- type: LoginResultType.Type_LoginFail_ContinueGame,
53
- code: "",
54
- accountId: 0,
55
- });
56
- return;
57
- }
58
- if (!needForceLogin) {
59
- this._checkSession().then((loginResult) => {
60
- this.isLogin = true;
61
- callback(loginResult);
62
- }).catch(() => {
63
- this._login().then((loginResult) => {
64
- this.isLogin = true;
65
- callback(loginResult);
66
- }).catch((loginResult) => {
67
- this.isLogin = false;
68
- callback(loginResult);
69
- });
70
- });
71
- }
72
- else {
73
- this._login().then((loginResult) => {
74
- this.isLogin = true;
75
- callback(loginResult);
76
- }).catch((loginResult) => {
77
- this.isLogin = false;
78
- callback(loginResult);
79
- });
80
- }
81
- }
82
- _checkSession() {
83
- return new Promise((resolve, reject) => {
84
- if (this.getPlatformAdapter() === null) {
85
- reject();
86
- return;
87
- }
88
- this.getPlatformAdapter().checkSession(() => {
89
- resolve({
90
- type: LoginResultType.Type_SessionAvailable,
91
- code: "",
92
- accountId: 0,
93
- });
94
- }, () => {
95
- reject();
96
- });
97
- });
98
- }
99
- _login() {
100
- return new Promise((resolve, reject) => {
101
- if (this.getPlatformAdapter() === null) {
102
- reject("");
103
- return;
104
- }
105
- this.getPlatformAdapter().login((code, accountId) => {
106
- if (code.length > 0) {
107
- resolve({
108
- type: LoginResultType.Type_LoginSuccess_Auth_Code,
109
- code: code,
110
- accountId: 0,
111
- });
112
- }
113
- else if (accountId > 0) {
114
- resolve({
115
- type: LoginResultType.Type_LoginSuccess_Auth_AccountID,
116
- code: "",
117
- accountId: accountId,
118
- });
119
- }
120
- reject({
121
- type: LoginResultType.Type_LoginFail_ContinueGame,
122
- code: "",
123
- accountId: 0,
124
- });
125
- }, (canContinueGame) => {
126
- if (canContinueGame) {
127
- reject({
128
- type: LoginResultType.Type_LoginFail_ContinueGame,
129
- code: "",
130
- accountId: 0,
131
- });
132
- }
133
- else {
134
- reject({
135
- type: LoginResultType.Type_LoginFail_ExitGame,
136
- code: "",
137
- accountId: 0,
138
- });
139
- }
140
- });
141
- });
142
- }
143
- isLogined() {
144
- return this.isLogin;
145
- }
146
- }
147
- UserMgr.Instance = null;
148
- UserMgr.TAG = "UserMgr";
@@ -1,49 +0,0 @@
1
- import { Component, Node, Tween, TweenEasing, Vec2, Vec3 } from 'cc';
2
- export interface BezierMoveOptions {
3
- rotateToDirection?: boolean;
4
- rotateSpeed?: number;
5
- rotateOffset?: number;
6
- lookAtTarget?: Node | Vec3;
7
- smoothing?: number;
8
- onUpdate?: (ratio: number, position: Vec3, rotation: number) => void;
9
- }
10
- export declare class BezierUtils extends Component {
11
- /**
12
- * 二阶贝塞尔曲线移动(带朝向控制)
13
- * @param target 目标节点
14
- * @param controlPoint 控制点
15
- * @param endPoint 终点
16
- * @param duration 持续时间
17
- * @param easing 缓动函数
18
- * @param options 配置选项
19
- */
20
- static quadraticTween(target: Node, controlPoint: Vec3, endPoint: Vec3, duration: number, easing?: TweenEasing, options?: BezierMoveOptions): Tween<Node>;
21
- /**
22
- * 计算看向目标的角度
23
- */
24
- private static calculateLookAtAngle;
25
- /**
26
- * 根据移动方向计算角度
27
- */
28
- private static calculateMovementAngle;
29
- /**
30
- * 向量转角度(2D平面,相对于X轴正方向,逆时针为正)
31
- */
32
- private static vectorToAngle;
33
- /**
34
- * 生成控制点
35
- */
36
- static getControlPoint2D(start: Vec2, end: Vec2, options?: {
37
- heightScale?: number;
38
- maxHeight?: number;
39
- direction?: number;
40
- intensity?: number;
41
- }): Vec2;
42
- /**
43
- * 通过角度生成控制点
44
- */
45
- static getControlPointByAngle2D(start: Vec2, end: Vec2, options?: {
46
- angle?: number;
47
- distance?: number;
48
- }): Vec2;
49
- }
@@ -1,247 +0,0 @@
1
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
- var _, done = false;
7
- for (var i = decorators.length - 1; i >= 0; i--) {
8
- var context = {};
9
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
- if (kind === "accessor") {
14
- if (result === void 0) continue;
15
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
- if (_ = accept(result.get)) descriptor.get = _;
17
- if (_ = accept(result.set)) descriptor.set = _;
18
- if (_ = accept(result.init)) initializers.unshift(_);
19
- }
20
- else if (_ = accept(result)) {
21
- if (kind === "field") initializers.unshift(_);
22
- else descriptor[key] = _;
23
- }
24
- }
25
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
- done = true;
27
- };
28
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
- var useValue = arguments.length > 2;
30
- for (var i = 0; i < initializers.length; i++) {
31
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
- }
33
- return useValue ? value : void 0;
34
- };
35
- var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
36
- if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
37
- return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
38
- };
39
- import { _decorator, Component, Node, tween, v2, Vec2, Vec3 } from 'cc';
40
- const { ccclass } = _decorator;
41
- let BezierUtils = (() => {
42
- let _classDecorators = [ccclass];
43
- let _classDescriptor;
44
- let _classExtraInitializers = [];
45
- let _classThis;
46
- let _classSuper = Component;
47
- var BezierUtils = _classThis = class extends _classSuper {
48
- /**
49
- * 二阶贝塞尔曲线移动(带朝向控制)
50
- * @param target 目标节点
51
- * @param controlPoint 控制点
52
- * @param endPoint 终点
53
- * @param duration 持续时间
54
- * @param easing 缓动函数
55
- * @param options 配置选项
56
- */
57
- static quadraticTween(target, controlPoint, endPoint, duration, easing = 'linear', options = {}) {
58
- const startPoint = target.position.clone();
59
- const startRotation = target.angle;
60
- let lastPosition = startPoint.clone();
61
- let lastRotation = 0;
62
- const rotateToDirection = options.rotateToDirection ?? false;
63
- const rotateSpeed = options.rotateSpeed ?? 1;
64
- const rotateOffset = options.rotateOffset ?? 0;
65
- const smoothing = options.smoothing ?? 0.3;
66
- return tween(target)
67
- .to(duration, {}, {
68
- onStart: (target) => {
69
- target.setPosition(startPoint);
70
- // 如果需要调整朝向
71
- if (rotateToDirection || options.lookAtTarget) {
72
- let targetAngle = 0;
73
- if (options.lookAtTarget) {
74
- // 看向目标
75
- targetAngle = this.calculateLookAtAngle(target.position, options.lookAtTarget instanceof Node
76
- ? options.lookAtTarget.position
77
- : options.lookAtTarget);
78
- }
79
- else {
80
- // 根据移动方向调整朝向
81
- targetAngle = this.calculateMovementAngle(lastPosition, target.position, target.angle, rotateSpeed);
82
- }
83
- // 应用角度偏移
84
- targetAngle += rotateOffset;
85
- // 角度平滑
86
- if (smoothing > 0 && smoothing < 1) {
87
- const currentAngle = target.angle;
88
- const smoothedAngle = currentAngle + (targetAngle - currentAngle) * smoothing;
89
- target.angle = smoothedAngle;
90
- lastRotation = smoothedAngle;
91
- }
92
- else {
93
- target.angle = targetAngle;
94
- lastRotation = targetAngle;
95
- }
96
- }
97
- lastPosition = startPoint.clone();
98
- lastRotation = startRotation;
99
- // 保存当前位置用于计算下一帧方向
100
- lastPosition.set(target.position);
101
- },
102
- onUpdate: (target, ratio) => {
103
- const t = ratio;
104
- const u = 1 - t;
105
- // 计算当前位置
106
- const x = u * u * startPoint.x +
107
- 2 * u * t * controlPoint.x +
108
- t * t * endPoint.x;
109
- const y = u * u * startPoint.y +
110
- 2 * u * t * controlPoint.y +
111
- t * t * endPoint.y;
112
- const z = u * u * startPoint.z +
113
- 2 * u * t * controlPoint.z +
114
- t * t * endPoint.z;
115
- target.setPosition(x, y, z);
116
- // 如果需要调整朝向
117
- if (rotateToDirection || options.lookAtTarget) {
118
- let targetAngle = 0;
119
- if (options.lookAtTarget) {
120
- // 看向目标
121
- targetAngle = this.calculateLookAtAngle(target.position, options.lookAtTarget instanceof Node
122
- ? options.lookAtTarget.position
123
- : options.lookAtTarget);
124
- }
125
- else {
126
- // 根据移动方向调整朝向
127
- targetAngle = this.calculateMovementAngle(lastPosition, target.position, target.angle, rotateSpeed);
128
- }
129
- // 应用角度偏移
130
- targetAngle += rotateOffset;
131
- // 角度平滑
132
- if (smoothing > 0 && smoothing < 1) {
133
- const currentAngle = target.angle;
134
- const smoothedAngle = currentAngle + (targetAngle - currentAngle) * smoothing;
135
- target.angle = smoothedAngle;
136
- lastRotation = smoothedAngle;
137
- }
138
- else {
139
- target.angle = targetAngle;
140
- lastRotation = targetAngle;
141
- }
142
- }
143
- // 保存当前位置用于计算下一帧方向
144
- lastPosition.set(target.position);
145
- // 调用自定义回调
146
- options.onUpdate?.(ratio, target.position.clone(), target.angle);
147
- },
148
- onComplete: (target) => {
149
- // 如果需要调整朝向
150
- if (rotateToDirection || options.lookAtTarget) {
151
- let targetAngle = 0;
152
- if (options.lookAtTarget) {
153
- // 看向目标
154
- targetAngle = this.calculateLookAtAngle(target.position, options.lookAtTarget instanceof Node
155
- ? options.lookAtTarget.position
156
- : options.lookAtTarget);
157
- }
158
- else {
159
- // 根据移动方向调整朝向
160
- targetAngle = this.calculateMovementAngle(lastPosition, target.position, target.angle, rotateSpeed);
161
- }
162
- // 应用角度偏移
163
- targetAngle += rotateOffset;
164
- // 角度平滑
165
- if (smoothing > 0 && smoothing < 1) {
166
- const currentAngle = target.angle;
167
- const smoothedAngle = currentAngle + (targetAngle - currentAngle) * smoothing;
168
- target.angle = smoothedAngle;
169
- lastRotation = smoothedAngle;
170
- }
171
- else {
172
- target.angle = targetAngle;
173
- lastRotation = targetAngle;
174
- }
175
- }
176
- lastPosition = startPoint.clone();
177
- lastRotation = startRotation;
178
- // 保存当前位置用于计算下一帧方向
179
- lastPosition.set(target.position);
180
- },
181
- easing: easing,
182
- })
183
- .start();
184
- }
185
- /**
186
- * 计算看向目标的角度
187
- */
188
- static calculateLookAtAngle(from, to) {
189
- const direction = new Vec3();
190
- Vec3.subtract(direction, to, from);
191
- return this.vectorToAngle(direction);
192
- }
193
- /**
194
- * 根据移动方向计算角度
195
- */
196
- static calculateMovementAngle(lastPos, currentPos, currentAngle, speed = 1) {
197
- const delta = new Vec3();
198
- Vec3.subtract(delta, currentPos, lastPos);
199
- // 如果移动距离很小,保持当前角度
200
- if (delta.lengthSqr() < 0.0001) {
201
- return currentAngle;
202
- }
203
- return this.vectorToAngle(delta);
204
- }
205
- /**
206
- * 向量转角度(2D平面,相对于X轴正方向,逆时针为正)
207
- */
208
- static vectorToAngle(vector) {
209
- // 计算相对于X轴正方向的角度(弧度)
210
- const rad = Math.atan2(vector.y, vector.x);
211
- // 转换为度(Cocos Creator 使用度作为单位)
212
- return rad * 180 / Math.PI;
213
- }
214
- /**
215
- * 生成控制点
216
- */
217
- static getControlPoint2D(start, end, options) {
218
- const { heightScale = 1, maxHeight = 200, direction = 1, intensity = 0.5 } = options || {};
219
- const height = Math.min(Vec2.distance(start, end) * heightScale, maxHeight);
220
- const mid = start.add(end).multiplyScalar(0.5);
221
- const dir = end.subtract(start);
222
- const perpendicular = v2(-dir.y, dir.x).normalize();
223
- return mid.add(perpendicular.multiplyScalar(height * direction * intensity));
224
- }
225
- /**
226
- * 通过角度生成控制点
227
- */
228
- static getControlPointByAngle2D(start, end, options) {
229
- const { angle = Math.PI / 2, distance = 200 } = options || {};
230
- const midPoint = start.add(end).multiplyScalar(0.5);
231
- // 计算控制点位置
232
- const x = midPoint.x + Math.cos(angle) * distance;
233
- const y = midPoint.y + Math.sin(angle) * distance;
234
- return v2(x, y);
235
- }
236
- };
237
- __setFunctionName(_classThis, "BezierUtils");
238
- (() => {
239
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
240
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
241
- BezierUtils = _classThis = _classDescriptor.value;
242
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
243
- __runInitializers(_classThis, _classExtraInitializers);
244
- })();
245
- return BezierUtils = _classThis;
246
- })();
247
- export { BezierUtils };