@cc-component/cc-core 1.2.8
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.
- package/.cc-ex-component.md +12 -0
- package/assets/core/config/CommonEnum.ts +94 -0
- package/assets/core/config/CommonEnum.ts.meta +9 -0
- package/assets/core/config/IConfig.ts +89 -0
- package/assets/core/config/IConfig.ts.meta +9 -0
- package/assets/core/config/LayerType.ts +44 -0
- package/assets/core/config/LayerType.ts.meta +9 -0
- package/assets/core/config/LayerUI.ts +113 -0
- package/assets/core/config/LayerUI.ts.meta +9 -0
- package/assets/core/config.meta +9 -0
- package/assets/core/editor/LanguageManager.ts +323 -0
- package/assets/core/editor/LanguageManager.ts.meta +9 -0
- package/assets/core/editor/SpineRunner.ts +39 -0
- package/assets/core/editor/SpineRunner.ts.meta +9 -0
- package/assets/core/editor/i18nEditorComponent.ts +137 -0
- package/assets/core/editor/i18nEditorComponent.ts.meta +9 -0
- package/assets/core/editor.meta +9 -0
- package/assets/core/home/AudioUtil.ts +164 -0
- package/assets/core/home/AudioUtil.ts.meta +9 -0
- package/assets/core/home/BaseBoxView.ts +60 -0
- package/assets/core/home/BaseBoxView.ts.meta +9 -0
- package/assets/core/home/BaseLaunchComponent.ts +9 -0
- package/assets/core/home/BaseLaunchComponent.ts.meta +9 -0
- package/assets/core/home/BaseLoading.ts +136 -0
- package/assets/core/home/BaseLoading.ts.meta +9 -0
- package/assets/core/home/BaseSkeleton.ts +39 -0
- package/assets/core/home/BaseSkeleton.ts.meta +9 -0
- package/assets/core/home/CameraAngel.ts +326 -0
- package/assets/core/home/CameraAngel.ts.meta +9 -0
- package/assets/core/home/DouYinShow.ts +27 -0
- package/assets/core/home/DouYinShow.ts.meta +9 -0
- package/assets/core/home/EventManager.ts +39 -0
- package/assets/core/home/EventManager.ts.meta +9 -0
- package/assets/core/home/ExView.ts +9 -0
- package/assets/core/home/ExView.ts.meta +9 -0
- package/assets/core/home/FollowCamera.ts +205 -0
- package/assets/core/home/FollowCamera.ts.meta +9 -0
- package/assets/core/home/InViewCenter.ts +52 -0
- package/assets/core/home/InViewCenter.ts.meta +9 -0
- package/assets/core/home/JsonUtil.ts +102 -0
- package/assets/core/home/JsonUtil.ts.meta +9 -0
- package/assets/core/home/LoadingWindow.ts +44 -0
- package/assets/core/home/LoadingWindow.ts.meta +9 -0
- package/assets/core/home/ParabolaTween.ts +110 -0
- package/assets/core/home/ParabolaTween.ts.meta +9 -0
- package/assets/core/home/ProgessView.ts +96 -0
- package/assets/core/home/ProgessView.ts.meta +9 -0
- package/assets/core/home/Quaternion.ts +237 -0
- package/assets/core/home/Quaternion.ts.meta +9 -0
- package/assets/core/home/ResUtil.ts +132 -0
- package/assets/core/home/ResUtil.ts.meta +9 -0
- package/assets/core/home/ResourceManager.ts +430 -0
- package/assets/core/home/ResourceManager.ts.meta +9 -0
- package/assets/core/home/StateMachine.ts +93 -0
- package/assets/core/home/StateMachine.ts.meta +9 -0
- package/assets/core/home/StorageManager.ts +161 -0
- package/assets/core/home/StorageManager.ts.meta +9 -0
- package/assets/core/home/ThirdFreeLookCamera.ts +201 -0
- package/assets/core/home/ThirdFreeLookCamera.ts.meta +9 -0
- package/assets/core/home/TimeManager.ts +486 -0
- package/assets/core/home/TimeManager.ts.meta +9 -0
- package/assets/core/home/Tools.ts +103 -0
- package/assets/core/home/Tools.ts.meta +9 -0
- package/assets/core/home/prefabs.meta +12 -0
- package/assets/core/home/util/EncryptUtil.ts +60 -0
- package/assets/core/home/util/EncryptUtil.ts.meta +11 -0
- package/assets/core/home/util/MathUtil.ts +22 -0
- package/assets/core/home/util/MathUtil.ts.meta +9 -0
- package/assets/core/home/util/Md5.ts +202 -0
- package/assets/core/home/util/Md5.ts.meta +11 -0
- package/assets/core/home/util/RandomUtil.ts +61 -0
- package/assets/core/home/util/RandomUtil.ts.meta +9 -0
- package/assets/core/home/util/ResUtil.ts +129 -0
- package/assets/core/home/util/ResUtil.ts.meta +9 -0
- package/assets/core/home/util/crypto-js.d.ts +30 -0
- package/assets/core/home/util/crypto-js.d.ts.meta +11 -0
- package/assets/core/home/util/crypto-js.js +6030 -0
- package/assets/core/home/util/crypto-js.js.meta +9 -0
- package/assets/core/home/util.meta +12 -0
- package/assets/core/home.meta +12 -0
- package/assets/core/interface/ISceneParam.ts +11 -0
- package/assets/core/interface/ISceneParam.ts.meta +9 -0
- package/assets/core/interface/Interface.ts +160 -0
- package/assets/core/interface/Interface.ts.meta +1 -0
- package/assets/core/interface/MainModule.ts +1019 -0
- package/assets/core/interface/MainModule.ts.meta +9 -0
- package/assets/core/interface.meta +9 -0
- package/assets/core/lib/Logger.ts +286 -0
- package/assets/core/lib/Logger.ts.meta +9 -0
- package/assets/core/lib/language/.language.md +1 -0
- package/assets/core/lib/language/Language.ts +133 -0
- package/assets/core/lib/language/Language.ts.meta +13 -0
- package/assets/core/lib/language/LanguageData.ts +114 -0
- package/assets/core/lib/language/LanguageData.ts.meta +9 -0
- package/assets/core/lib/language/LanguageLabel.ts +172 -0
- package/assets/core/lib/language/LanguageLabel.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePack.ts +126 -0
- package/assets/core/lib/language/LanguagePack.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePointLabel.ts.meta +16 -0
- package/assets/core/lib/language/LanguageSpine.ts +60 -0
- package/assets/core/lib/language/LanguageSpine.ts.meta +9 -0
- package/assets/core/lib/language/LanguageSprite.ts +138 -0
- package/assets/core/lib/language/LanguageSprite.ts.meta +13 -0
- package/assets/core/lib/language.meta +9 -0
- package/assets/core/lib/logger/ELoggerLevel.ts +16 -0
- package/assets/core/lib/logger/ELoggerLevel.ts.meta +9 -0
- package/assets/core/lib/logger/MLogger.ts +118 -0
- package/assets/core/lib/logger/MLogger.ts.meta +9 -0
- package/assets/core/lib/logger.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts +2729 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js +8 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts +102 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js +222 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto +6 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto +12 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/base.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/base.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/command.proto +31 -0
- package/assets/core/lib/net/libs/proto/source/command.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto +13 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto +26 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto +23 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto +43 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/push.meta +9 -0
- package/assets/core/lib/net/libs/proto/source.meta +12 -0
- package/assets/core/lib/net/libs/proto.meta +9 -0
- package/assets/core/lib/net/libs.meta +9 -0
- package/assets/core/lib/net/net/HttpManager.ts +307 -0
- package/assets/core/lib/net/net/HttpManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetInterface.ts +114 -0
- package/assets/core/lib/net/net/NetInterface.ts.meta +9 -0
- package/assets/core/lib/net/net/NetManager.ts +77 -0
- package/assets/core/lib/net/net/NetManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetNode.ts +471 -0
- package/assets/core/lib/net/net/NetNode.ts.meta +9 -0
- package/assets/core/lib/net/net/WebSock.ts +81 -0
- package/assets/core/lib/net/net/WebSock.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts +41 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts +11 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts +4 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts +53 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts +105 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts.meta +9 -0
- package/assets/core/lib/net/net/custom.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts +39 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts +85 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol.meta +9 -0
- package/assets/core/lib/net/net.meta +9 -0
- package/assets/core/lib/net/prompt.meta +9 -0
- package/assets/core/lib/net.meta +9 -0
- package/assets/core/lib/old/VM2.ts +619 -0
- package/assets/core/lib/old/VM2.ts.meta +9 -0
- package/assets/core/lib/old/ViewModel.ts +905 -0
- package/assets/core/lib/old/ViewModel.ts.meta +9 -0
- package/assets/core/lib/old/ViewSearch.ts +125 -0
- package/assets/core/lib/old/ViewSearch.ts.meta +9 -0
- package/assets/core/lib/old.meta +9 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts +113 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarController.ts +86 -0
- package/assets/core/lib/tabbar/TabBarController.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarItem.ts +52 -0
- package/assets/core/lib/tabbar/TabBarItem.ts.meta +9 -0
- package/assets/core/lib/tabbar.meta +9 -0
- package/assets/core/lib.meta +12 -0
- package/assets/core.meta +9 -0
- package/assets.meta +9 -0
- package/index.ts +3 -0
- package/index.ts.meta +9 -0
- package/package.json +19 -0
- package/package.json.meta +11 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { _decorator, Component, Event, Node, Button, Animation, EventHandler, Color, EventTouch, tween, Vec3, Quat, CCBoolean, v3, misc, mat4, math, Mat4, find, EventKeyboard, macro, director, UITransform } from 'cc';
|
|
2
|
+
import { FollowCamera } from './FollowCamera';
|
|
3
|
+
const { ccclass, property } = _decorator;
|
|
4
|
+
|
|
5
|
+
@ccclass('CameraAngel')
|
|
6
|
+
export class CameraAngel extends Component {
|
|
7
|
+
|
|
8
|
+
targetCube: Node = null;
|
|
9
|
+
|
|
10
|
+
@property
|
|
11
|
+
rotationSpeed: number = 1;
|
|
12
|
+
private isTouching: boolean = false;
|
|
13
|
+
|
|
14
|
+
private touchStartPos: Vec3 = new Vec3();
|
|
15
|
+
|
|
16
|
+
followCamera: FollowCamera;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
distance = 50;
|
|
20
|
+
|
|
21
|
+
touNode:Node;
|
|
22
|
+
touNodeSize:UITransform;
|
|
23
|
+
start() {
|
|
24
|
+
|
|
25
|
+
// this.node.on(Node.EventType.MOUSE_DOWN, this.MouseDown, this);
|
|
26
|
+
|
|
27
|
+
let node = find("Home/root/yaogan")
|
|
28
|
+
this.touNode = find("Home/root/yaogan/tou")
|
|
29
|
+
this.touNodeSize = this.touNode.getComponent(UITransform)
|
|
30
|
+
|
|
31
|
+
node.on(Node.EventType.TOUCH_START, this.TouchStart, this);
|
|
32
|
+
node.on(Node.EventType.TOUCH_MOVE, this.TouchMove, this);
|
|
33
|
+
node.on(Node.EventType.TOUCH_END, this.TouchEnd, this);
|
|
34
|
+
node.on(Node.EventType.TOUCH_CANCEL, this.TouchEnd, this);
|
|
35
|
+
|
|
36
|
+
//this.UpdatePos(0, 0)
|
|
37
|
+
|
|
38
|
+
// systemEvent.on(SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
|
|
39
|
+
// systemEvent.on(SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
StartGame(targetCube:Node) {
|
|
46
|
+
this.targetCube = targetCube;
|
|
47
|
+
this.followCamera = this.getComponent(FollowCamera)
|
|
48
|
+
this.followCamera.StartGame(this.targetCube,this.distance)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
private MouseDown(e: Event) {
|
|
53
|
+
|
|
54
|
+
console.log("222");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
protected update(dt: number): void {
|
|
59
|
+
if (this.targetCube) {
|
|
60
|
+
let fff = Vec3.FORWARD
|
|
61
|
+
fff = v3(0, 0, -1).multiplyScalar(0.01)
|
|
62
|
+
// console.log(fff);
|
|
63
|
+
// this.targetCube.worldPosition = this.targetCube.worldPosition.add(fff)
|
|
64
|
+
// this.UpdatePos(0, 0)
|
|
65
|
+
// this.SetPos();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
fromRotation(axis, angle) {
|
|
72
|
+
let euler = new Vec3();
|
|
73
|
+
euler.set(axis.x * misc.radiansToDegrees(angle), axis.y * misc.radiansToDegrees(angle), axis.z * misc.radiansToDegrees(angle));
|
|
74
|
+
|
|
75
|
+
let quat = new Quat();
|
|
76
|
+
Quat.fromEuler(quat, euler.x, euler.y, euler.z);
|
|
77
|
+
|
|
78
|
+
return quat;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
private TouchStart(e: EventTouch) {
|
|
84
|
+
this.isTouching = true;
|
|
85
|
+
this.touchStartPos = this.GetPos(e);
|
|
86
|
+
//å console.log("开始", this.touchStartPos)
|
|
87
|
+
|
|
88
|
+
this.isHave = false
|
|
89
|
+
this.f_x = v3(0)
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
GetPos(e:EventTouch){
|
|
94
|
+
|
|
95
|
+
let super_pos = this.touNode.parent.worldPosition
|
|
96
|
+
let pos = v3(super_pos.x ,super_pos.y,0)//this.touNode.parent.position;
|
|
97
|
+
return v3(e.getUILocation().x-pos.x, e.getUILocation().y-pos.y,0)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
f_x: Vec3 = v3(0)
|
|
105
|
+
isHave = false
|
|
106
|
+
private TouchMove(e: EventTouch) {
|
|
107
|
+
if (!this.isTouching) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
let pos = this.GetPos(e);;
|
|
113
|
+
this.UpdatePos(pos.x, pos.y);
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private TouchEnd(e: EventTouch) {
|
|
119
|
+
|
|
120
|
+
this.ResetPos();
|
|
121
|
+
if( this.touNode){
|
|
122
|
+
this.touNode.position = v3(75,75)
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
ResetPos(){
|
|
131
|
+
this.followCamera.isMove = false;
|
|
132
|
+
this.followCamera.resetPos();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
UpdatePos(x, y) {
|
|
137
|
+
|
|
138
|
+
if (this.followCamera.isUpdatePos) {
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
if(this.touNode){
|
|
144
|
+
this.touNode.position = v3(x,y)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
// console.log(x,y)
|
|
149
|
+
// console.log("ddd");
|
|
150
|
+
this.followCamera.isMove = true;
|
|
151
|
+
let currentPos = new Vec3(x, y, 0);
|
|
152
|
+
let delta = currentPos.clone().subtract(this.touchStartPos);
|
|
153
|
+
|
|
154
|
+
if (delta.x < this.f_x.x && !this.f_x.equals(v3(0), 0.01)) {
|
|
155
|
+
this.touchStartPos = this.f_x
|
|
156
|
+
// console.log("转");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//console.log(currentPos)
|
|
160
|
+
this.f_x = currentPos.clone();
|
|
161
|
+
// 根据 deltaX 进行旋转
|
|
162
|
+
// console.log(delta);
|
|
163
|
+
this.rotateByDeltaX(delta.x,delta.y);
|
|
164
|
+
//this.rotateAndLookAtTarget()
|
|
165
|
+
|
|
166
|
+
this.touchStartPos.clone().set(currentPos);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// private rotateByDeltaX(deltaX: number) {
|
|
170
|
+
// if (!this.targetCube) {
|
|
171
|
+
|
|
172
|
+
// return
|
|
173
|
+
// }
|
|
174
|
+
// // 根据 deltaX 计算旋转角度
|
|
175
|
+
// let rotationAngle = -deltaX * 0.0001; // 调整旋转速度
|
|
176
|
+
|
|
177
|
+
// // 创建绕 Y 轴旋转的四元数
|
|
178
|
+
// let rotationQuat = this.fromRotation(v3(0, 1, 0), misc.radiansToDegrees(rotationAngle));
|
|
179
|
+
|
|
180
|
+
// // 使用四元数进行旋转
|
|
181
|
+
// let rotatedPos = new Vec3();
|
|
182
|
+
// math.Vec3.transformQuat(rotatedPos, this.node.position.clone().subtract(this.targetCube.worldPosition), rotationQuat);
|
|
183
|
+
|
|
184
|
+
// // 更新摄像机位置
|
|
185
|
+
// this.node.setWorldPosition(rotatedPos.add(this.targetCube.worldPosition));
|
|
186
|
+
|
|
187
|
+
// // 摄像机始终朝向目标立方体
|
|
188
|
+
// this.node.lookAt(this.targetCube.worldPosition);
|
|
189
|
+
// }
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
// private rotateByDeltaX(deltaX: number) {
|
|
193
|
+
// if (!this.targetCube) {
|
|
194
|
+
// return;
|
|
195
|
+
// }
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
// // 根据deltaX计算旋转角度
|
|
199
|
+
// let rotationAngle = -deltaX * 0.0001;
|
|
200
|
+
|
|
201
|
+
// // 创建围绕Y轴旋转的四元数
|
|
202
|
+
// let rotationQuat = this.fromRotation(v3(0, 1, 0), misc.radiansToDegrees(rotationAngle));
|
|
203
|
+
|
|
204
|
+
// // 计算从相机到targetCube的向量
|
|
205
|
+
|
|
206
|
+
// let cameraToTarget = this.node.position.clone().subtract(this.targetCube.worldPosition);
|
|
207
|
+
|
|
208
|
+
// // 将四元数旋转应用于向量
|
|
209
|
+
// math.Vec3.transformQuat(cameraToTarget, cameraToTarget, rotationQuat);
|
|
210
|
+
|
|
211
|
+
// // 确保距离targetCube的固定距离为10个单位
|
|
212
|
+
// let distance = 30;
|
|
213
|
+
// let rotatedPos = this.targetCube.worldPosition.clone().add(cameraToTarget.normalize().multiplyScalar(distance));
|
|
214
|
+
|
|
215
|
+
// // 更新相机位置
|
|
216
|
+
// this.node.setWorldPosition(rotatedPos);
|
|
217
|
+
|
|
218
|
+
// // 保持相机始终朝向targetCube
|
|
219
|
+
// this.node.lookAt(this.targetCube.worldPosition);
|
|
220
|
+
// }
|
|
221
|
+
|
|
222
|
+
private rotateByDeltaX(deltaX: number, deltaY: number) {
|
|
223
|
+
if (!this.targetCube) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 根据deltaX和deltaY计算旋转角度
|
|
228
|
+
let rotationAngleX = -deltaY * 0.0001; // deltaY用于X轴旋转
|
|
229
|
+
let rotationAngleY = -deltaX * 0.0001; // deltaX用于Y轴旋转
|
|
230
|
+
|
|
231
|
+
// 创建围绕X轴和Y轴旋转的两个四元数
|
|
232
|
+
let rotationQuatX = this.fromRotation(v3(1, 1, 0), misc.radiansToDegrees(rotationAngleX));
|
|
233
|
+
let rotationQuatY = this.fromRotation(v3(0, 1, 0), misc.radiansToDegrees(rotationAngleY));
|
|
234
|
+
// let rotationQuatz = this.fromRotation(v3(0, 0, 1), misc.radiansToDegrees(rotationAngleY));
|
|
235
|
+
|
|
236
|
+
let combinedQuat = rotationQuatY//this.multiplyQuaternions(rotationQuatX, rotationQuatY)
|
|
237
|
+
// 将两个四元数相乘,以获得综合的旋转效果
|
|
238
|
+
// let combinedQuat = math.Quat.multiply(rotationQuatX, rotationQuatY, rotationQuatX);
|
|
239
|
+
|
|
240
|
+
// 计算从相机到targetCube的向量
|
|
241
|
+
let cameraToTarget = this.node.worldPosition.clone().subtract(this.targetCube.worldPosition);
|
|
242
|
+
|
|
243
|
+
// 将综合的四元数旋转应用于向量
|
|
244
|
+
math.Vec3.transformQuat(cameraToTarget, cameraToTarget, combinedQuat);
|
|
245
|
+
|
|
246
|
+
// 确保距离targetCube的固定距离为10个单位
|
|
247
|
+
let distance = this.distance;
|
|
248
|
+
let rotatedPos = this.targetCube.worldPosition.clone().add(cameraToTarget.normalize().multiplyScalar(distance));
|
|
249
|
+
|
|
250
|
+
// 更新相机位置
|
|
251
|
+
this.node.setWorldPosition(v3(rotatedPos));
|
|
252
|
+
|
|
253
|
+
// 保持相机始终朝向targetCube
|
|
254
|
+
this.node.lookAt(this.targetCube.worldPosition);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
multiplyQuaternions(quat1: math.Quat, quat2: math.Quat): math.Quat {
|
|
258
|
+
let result = new math.Quat();
|
|
259
|
+
|
|
260
|
+
// Quaternion multiplication formula: result = quat2 * quat1
|
|
261
|
+
result.x = quat2.x * quat1.w + quat2.y * quat1.z - quat2.z * quat1.y + quat2.w * quat1.x;
|
|
262
|
+
result.y = -quat2.x * quat1.z + quat2.y * quat1.w + quat2.z * quat1.x + quat2.w * quat1.y;
|
|
263
|
+
result.z = quat2.x * quat1.y - quat2.y * quat1.x + quat2.z * quat1.w + quat2.w * quat1.z;
|
|
264
|
+
result.w = -quat2.x * quat1.x - quat2.y * quat1.y - quat2.z * quat1.z + quat2.w * quat1.w;
|
|
265
|
+
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
rotateAndLookAtTarget() {
|
|
270
|
+
if (!this.targetCube) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 旋转相机位置(45度角)
|
|
275
|
+
let rotationAngle = misc.degreesToRadians(90); // 将角度转换为弧度
|
|
276
|
+
//let rotationQuat = Quat.fromAxisAngle(v3(0, 1, 0), rotationAngle);
|
|
277
|
+
let rotationQuat = this.fromRotation(v3(0, 1, 0), misc.radiansToDegrees(rotationAngle));
|
|
278
|
+
let rotatedDirection = v3(1, 1, -1); // 初始方向
|
|
279
|
+
math.Vec3.transformQuat(rotatedDirection, rotatedDirection, rotationQuat);
|
|
280
|
+
|
|
281
|
+
// 确保距离targetCube的固定距离为10个单位
|
|
282
|
+
let distance = 20;
|
|
283
|
+
let rotatedPos = this.targetCube.worldPosition.clone().add(rotatedDirection.clone().multiplyScalar(distance));
|
|
284
|
+
let rotatedPos2 = this.targetCube.worldPosition.clone().add(this.node.forward.multiplyScalar(distance * -1));
|
|
285
|
+
|
|
286
|
+
console.log(rotatedDirection.clone(), rotatedPos2)
|
|
287
|
+
// 更新相机位置
|
|
288
|
+
this.node.setWorldPosition(rotatedPos);
|
|
289
|
+
|
|
290
|
+
// 使相机朝向targetCube
|
|
291
|
+
this.node.lookAt(this.targetCube.worldPosition);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
@property
|
|
297
|
+
speed: number = 300;
|
|
298
|
+
onKeyDown(event: EventKeyboard) {
|
|
299
|
+
switch (event.keyCode) {
|
|
300
|
+
case macro.KEY.w:
|
|
301
|
+
this.targetCube.worldPosition = this.targetCube.worldPosition.add3f(0, 0, this.speed * director.getDeltaTime());
|
|
302
|
+
break;
|
|
303
|
+
case macro.KEY.s:
|
|
304
|
+
this.targetCube.worldPosition = this.targetCube.worldPosition.subtract3f(0, 0, this.speed * director.getDeltaTime());
|
|
305
|
+
|
|
306
|
+
break;
|
|
307
|
+
case macro.KEY.a:
|
|
308
|
+
this.targetCube.worldPosition = this.targetCube.worldPosition.subtract3f(this.speed * director.getDeltaTime(), 0, 0);
|
|
309
|
+
|
|
310
|
+
break;
|
|
311
|
+
case macro.KEY.d:
|
|
312
|
+
this.targetCube.worldPosition = this.targetCube.worldPosition.add3f(this.speed * director.getDeltaTime(), 0, 0);
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
this.ResetPos()
|
|
318
|
+
|
|
319
|
+
// this.targetCube_lastPos = this.targetCube.worldPosition.clone();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
onKeyUp(event: EventKeyboard) {
|
|
323
|
+
// 可以在需要的时候处理键盘抬起事件
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { _decorator, CCBoolean, Component, Node } from 'cc';
|
|
2
|
+
import { BYTEDANCE } from 'cc/env';
|
|
3
|
+
const { ccclass, property } = _decorator;
|
|
4
|
+
|
|
5
|
+
@ccclass('DouYinShow')
|
|
6
|
+
export class DouYinShow extends Component {
|
|
7
|
+
|
|
8
|
+
@property({})
|
|
9
|
+
isTip = false;
|
|
10
|
+
protected onLoad(): void {
|
|
11
|
+
if (BYTEDANCE) {
|
|
12
|
+
if (!MainModule.IsDouYin() && !this.isTip) {
|
|
13
|
+
this.node.active = false;
|
|
14
|
+
} else {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
start() {
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
update(deltaTime: number) {
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { _decorator, EventTarget } from 'cc';
|
|
2
|
+
|
|
3
|
+
const { ccclass } = _decorator;
|
|
4
|
+
|
|
5
|
+
@ccclass('EventManager')
|
|
6
|
+
export class EventManager {
|
|
7
|
+
|
|
8
|
+
private static instance: EventManager;
|
|
9
|
+
private eventTarget: EventTarget;
|
|
10
|
+
|
|
11
|
+
private constructor() {
|
|
12
|
+
this.eventTarget = new EventTarget();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static get ins() {
|
|
16
|
+
if (!this.instance) {
|
|
17
|
+
this.instance = new EventManager();
|
|
18
|
+
}
|
|
19
|
+
return this.instance;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
on(eventName: string, callback: any, target?: any) {
|
|
23
|
+
this.eventTarget.on(eventName, callback, target);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
off(eventName: string, callback?: any, target?: any) {
|
|
27
|
+
this.eventTarget.off(eventName, callback, target);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
emit(eventName: string, params: any) {
|
|
31
|
+
this.eventTarget.emit(eventName, params);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
OffAll(target: any) {
|
|
35
|
+
this.eventTarget.targetOff(target);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Component, EventKeyboard, EventTouch, Node, Quat, Tween, Vec3, _decorator, director, find, macro, math, misc, tween, v3 } from "cc";
|
|
2
|
+
import Message from "./Message";
|
|
3
|
+
import { MessageType } from "./MessageType";
|
|
4
|
+
const { ccclass, property } = _decorator;
|
|
5
|
+
|
|
6
|
+
const v3_1 = new Vec3;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 自动跟随目标,并平滑移动的摄像机
|
|
10
|
+
*/
|
|
11
|
+
@ccclass
|
|
12
|
+
export class FollowCamera extends Component {
|
|
13
|
+
|
|
14
|
+
@property(Node)
|
|
15
|
+
focusTarget: Node = null as any;
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
speedFactor: number = 0.05;
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
private _distance: number = 30.0;
|
|
22
|
+
@property
|
|
23
|
+
public get distance(): number {
|
|
24
|
+
return this._distance;
|
|
25
|
+
}
|
|
26
|
+
public set distance(v: number) {
|
|
27
|
+
this._distance = v;
|
|
28
|
+
this._updateTargetWorldPos();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Limit range
|
|
32
|
+
enableLimit: boolean = true;
|
|
33
|
+
minX = -Infinity;
|
|
34
|
+
maxX = Infinity;
|
|
35
|
+
minZ = -Infinity;
|
|
36
|
+
maxZ = Infinity;
|
|
37
|
+
|
|
38
|
+
protected _tweenFollow?: Tween<any>;
|
|
39
|
+
protected _targetWorldPos = new Vec3;
|
|
40
|
+
protected _lastTargetPos = new Vec3;
|
|
41
|
+
|
|
42
|
+
private static Deg2Rad:number=(Math.PI) / 180;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
isMove = false;
|
|
46
|
+
start() {
|
|
47
|
+
|
|
48
|
+
// let node = find("Canvas/yaogan")
|
|
49
|
+
|
|
50
|
+
// node.on(Node.EventType.TOUCH_START, this.TouchStart, this);
|
|
51
|
+
// node.on(Node.EventType.TOUCH_MOVE, this.TouchMove, this);
|
|
52
|
+
// node.on(Node.EventType.TOUCH_END, this.TouchEnd, this);
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
StartGame(focusTarget:Node,dis:number){
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
this.focusTarget = focusTarget;
|
|
62
|
+
this._lastTargetPos.set(this.focusTarget.worldPosition.clone());
|
|
63
|
+
this.distance = dis
|
|
64
|
+
this._updateTargetWorldPos();
|
|
65
|
+
|
|
66
|
+
tween(this.node)
|
|
67
|
+
.to(0.5, { worldPosition: this._targetWorldPos })
|
|
68
|
+
.start();
|
|
69
|
+
|
|
70
|
+
//this.node.setWorldPosition(this._targetWorldPos);
|
|
71
|
+
|
|
72
|
+
// this.UpdatePos(0, 0)
|
|
73
|
+
}
|
|
74
|
+
protected _updateTargetWorldPos() {
|
|
75
|
+
this._targetWorldPos.set(this.focusTarget.worldPosition.clone());
|
|
76
|
+
if (this.enableLimit) {
|
|
77
|
+
this._targetWorldPos.x = FollowCamera.limit(this._targetWorldPos.x, this.minX, this.maxX);
|
|
78
|
+
this._targetWorldPos.z = FollowCamera.limit(this._targetWorldPos.z, this.minZ, this.maxZ);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this._targetWorldPos.add(this.node.forward.multiplyScalar(this.distance * -1));
|
|
82
|
+
// this._targetWorldPos.add3f(this._targetWorldPos.x,this._targetWorldPos.y,this._targetWorldPos.z);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
update() {
|
|
86
|
+
if (!this.focusTarget) {
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
if(this.isMove){
|
|
90
|
+
|
|
91
|
+
// console.log("阻止")
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.UpdateP();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
isUpdatePos = false;
|
|
99
|
+
UpdateP(){
|
|
100
|
+
if (!this._lastTargetPos.equals(this.focusTarget.worldPosition.clone())) {
|
|
101
|
+
this._lastTargetPos.set(this.focusTarget.worldPosition.clone());
|
|
102
|
+
this._updateTargetWorldPos();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 向TargetWorldPos平滑逼近
|
|
106
|
+
// Limit Range
|
|
107
|
+
|
|
108
|
+
v3_1.set(this._targetWorldPos);
|
|
109
|
+
let diff = v3_1.subtract(this.node.worldPosition);
|
|
110
|
+
if (diff.lengthSqr() > 0.01) {
|
|
111
|
+
let ret = this.node.worldPosition.clone().add(diff.multiplyScalar(this.speedFactor));
|
|
112
|
+
//ret = ret.add(v3(0,0.5,0));
|
|
113
|
+
this.node.setWorldPosition(ret);
|
|
114
|
+
//console.log('-----',this.node.worldPosition);
|
|
115
|
+
//this.node.setWorldPosition(v3(ret.x,37,ret.z));
|
|
116
|
+
|
|
117
|
+
this.isUpdatePos = true
|
|
118
|
+
}else{
|
|
119
|
+
this.isUpdatePos = false
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
IsMovePos(){
|
|
125
|
+
|
|
126
|
+
v3_1.set(this._targetWorldPos);
|
|
127
|
+
let diff = v3_1.subtract(this.node.worldPosition);
|
|
128
|
+
if (diff.lengthSqr() > 0.01) {
|
|
129
|
+
this.isUpdatePos = true
|
|
130
|
+
return true
|
|
131
|
+
} else {
|
|
132
|
+
this.isUpdatePos = false
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 将变换围绕穿过世界坐标中的 point 的 axis 旋转 angle 度。
|
|
140
|
+
* 这会修改变换的位置和旋转。
|
|
141
|
+
* @param self 要变换旋转的目标
|
|
142
|
+
* @param pos 指定围绕的point
|
|
143
|
+
* @param axis 旋转轴
|
|
144
|
+
* @param angle 旋转角度
|
|
145
|
+
*/
|
|
146
|
+
public static RotationAroundNode(self:Node,pos:Vec3,axis:Vec3,angle:number):Quat
|
|
147
|
+
{
|
|
148
|
+
let _quat=new Quat();
|
|
149
|
+
let v1=new Vec3();
|
|
150
|
+
let v2=new Vec3();
|
|
151
|
+
let pos2:Vec3=self.position;
|
|
152
|
+
let rad=angle* this.Deg2Rad;
|
|
153
|
+
//根据旋转轴和旋转弧度计算四元数
|
|
154
|
+
Quat.fromAxisAngle(_quat,axis,rad);
|
|
155
|
+
//相减,目标点与相机点之间的向量
|
|
156
|
+
Vec3.subtract(v1,pos2,pos);
|
|
157
|
+
//把向量dir根据计算到的四元数旋转,然后计算出旋转后的距离
|
|
158
|
+
Vec3.transformQuat(v2,v1,_quat);
|
|
159
|
+
self.position=Vec3.add(v2,pos,v2);
|
|
160
|
+
//根据轴和弧度绕世界空间下指定轴旋转四元数
|
|
161
|
+
Quat.rotateAround(_quat,self.rotation,axis,rad);
|
|
162
|
+
return _quat;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
resetPos() {
|
|
167
|
+
this._updateTargetWorldPos();
|
|
168
|
+
//this.node.setWorldPosition(this._targetWorldPos);
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
v3_1.set(this._targetWorldPos);
|
|
172
|
+
let diff = v3_1.subtract(this.node.worldPosition);
|
|
173
|
+
if (diff.lengthSqr() > 0.01) {
|
|
174
|
+
let ret = this.node.worldPosition.clone().add(diff.multiplyScalar(this.speedFactor));
|
|
175
|
+
//ret = ret.add(v3(0,0.5,0));
|
|
176
|
+
this.node.setWorldPosition(ret);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@property
|
|
181
|
+
get preview() {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
set preview(v: boolean) {
|
|
185
|
+
this.resetPos();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@property
|
|
189
|
+
get autoSetDistance() {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
set autuSetDistance(v: boolean) {
|
|
193
|
+
this.distance = this.node.worldPosition.clone().subtract(this.focusTarget.worldPosition.clone()).length();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
static limit(src: number, min: number, max: number) {
|
|
197
|
+
return Math.min(max, Math.max(min, src));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
}
|