@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,161 @@
|
|
|
1
|
+
import { sys } from "cc";
|
|
2
|
+
import { PREVIEW } from "cc/env";
|
|
3
|
+
|
|
4
|
+
export interface IStorageSecurity {
|
|
5
|
+
decrypt(str: string): string;
|
|
6
|
+
encrypt(str: string): string;
|
|
7
|
+
encryptKey(str: string): string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 本地存储
|
|
12
|
+
* @help https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12037957&doc_id=2873565
|
|
13
|
+
*/
|
|
14
|
+
export class StorageManager {
|
|
15
|
+
private id: string = null!;
|
|
16
|
+
private iss: IStorageSecurity = null!;
|
|
17
|
+
|
|
18
|
+
/** 数据加密开关 */
|
|
19
|
+
private get encrypted(): boolean {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 本地存储数据加密方式初始化 */
|
|
24
|
+
init(iis: IStorageSecurity) {
|
|
25
|
+
this.iss = iis;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 设置用户唯一标识
|
|
30
|
+
* @param id
|
|
31
|
+
*/
|
|
32
|
+
setUser(id: string) {
|
|
33
|
+
this.id = id;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 存储本地数据
|
|
38
|
+
* @param key 存储key
|
|
39
|
+
* @param value 存储值
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
set(key: string, value: any) {
|
|
43
|
+
let keywords = this.getKey(key);
|
|
44
|
+
|
|
45
|
+
if (null == key) {
|
|
46
|
+
console.error("存储的key不能为空");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (this.encrypted) {
|
|
50
|
+
keywords = this.iss.encryptKey(keywords);
|
|
51
|
+
}
|
|
52
|
+
if (null == value) {
|
|
53
|
+
console.warn("存储的值为空,则直接移除该存储");
|
|
54
|
+
this.remove(key);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (typeof value === 'function') {
|
|
58
|
+
console.error("储存的值不能为方法");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (typeof value === 'object') {
|
|
62
|
+
try {
|
|
63
|
+
value = JSON.stringify(value);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
console.error(`解析失败,str = ${value}`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (typeof value === 'number') {
|
|
71
|
+
value = value + "";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (this.encrypted) {
|
|
75
|
+
value = this.iss.encrypt(value);
|
|
76
|
+
}
|
|
77
|
+
sys.localStorage.setItem(keywords, value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 获取指定关键字的数据
|
|
82
|
+
* @param key 获取的关键字
|
|
83
|
+
* @param defaultValue 获取的默认值
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
get(key: string, defaultValue: any = ""): string {
|
|
87
|
+
if (null == key) {
|
|
88
|
+
console.error("存储的key不能为空");
|
|
89
|
+
return null!;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
key = this.getKey(key);
|
|
93
|
+
|
|
94
|
+
if (this.encrypted) {
|
|
95
|
+
key = this.iss.encryptKey(key);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let str: string | null = sys.localStorage.getItem(key);
|
|
99
|
+
if (null != str && '' !== str && this.encrypted) {
|
|
100
|
+
str = this.iss.decrypt(str);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (null === str) {
|
|
104
|
+
return defaultValue;
|
|
105
|
+
}
|
|
106
|
+
return str;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 获取指定关键字的数值 */
|
|
110
|
+
getNumber(key: string, defaultValue: number = 0): number {
|
|
111
|
+
const r = this.get(key);
|
|
112
|
+
if (r == "0") {
|
|
113
|
+
return Number(r);
|
|
114
|
+
}
|
|
115
|
+
return Number(r) || defaultValue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** 获取指定关键字的布尔值 */
|
|
119
|
+
getBoolean(key: string): boolean {
|
|
120
|
+
const r = this.get(key);
|
|
121
|
+
return r.toLowerCase() === 'true';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 获取指定关键字的JSON对象 */
|
|
125
|
+
getJson(key: string, defaultValue?: any): any {
|
|
126
|
+
const r = this.get(key);
|
|
127
|
+
return (r && JSON.parse(r)) || defaultValue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 删除指定关键字的数据
|
|
132
|
+
* @param key 需要移除的关键字
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
remove(key: string) {
|
|
136
|
+
if (null == key) {
|
|
137
|
+
console.error("存储的key不能为空");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let keywords = this.getKey(key);
|
|
142
|
+
|
|
143
|
+
if (this.encrypted) {
|
|
144
|
+
keywords = this.iss.encryptKey(keywords);
|
|
145
|
+
}
|
|
146
|
+
sys.localStorage.removeItem(keywords);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** 清空整个本地存储 */
|
|
150
|
+
clear() {
|
|
151
|
+
sys.localStorage.clear();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** 获取数据分组关键字 */
|
|
155
|
+
private getKey(key: string): string {
|
|
156
|
+
if (this.id == null || this.id == "") {
|
|
157
|
+
return key;
|
|
158
|
+
}
|
|
159
|
+
return `${this.id}_${key}`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
_decorator, Component, Node, EventTouch, Quat, Vec3, Enum, IVec3Like, Input, find
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
} from 'cc';
|
|
7
|
+
import { Quaternion, VectorTool } from './Quaternion';
|
|
8
|
+
|
|
9
|
+
const { ccclass, property } = _decorator;
|
|
10
|
+
|
|
11
|
+
export enum ThirdPersonCameraType {
|
|
12
|
+
/** 相机紧跟随着目标,相机不会旋转 */
|
|
13
|
+
Follow = 0,
|
|
14
|
+
/** 相机会旋转紧跟着目标正后方,旋转不可控制 */
|
|
15
|
+
FollowTrackRotation = 1,
|
|
16
|
+
/** 相机紧跟随着目标,相机可以自由旋转 */
|
|
17
|
+
FollowIndependentRotation = 2,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 第三人称相机跟随
|
|
22
|
+
* 这里总结了三个相机跟随
|
|
23
|
+
* 1. 相机紧跟随着目标,相机不会旋转
|
|
24
|
+
* 2. 相机紧跟随着目标,相机会旋转紧跟着目标正后方,旋转不可控制
|
|
25
|
+
* 3. 相机紧跟随着目标,相机可以自由旋转,角色向前移动的时候,前方向永远是相机的正方向
|
|
26
|
+
*/
|
|
27
|
+
@ccclass('ThirdFreeLookCamera')
|
|
28
|
+
export class ThirdFreeLookCamera extends Component {
|
|
29
|
+
/** 目标 */
|
|
30
|
+
@property(Node)
|
|
31
|
+
target: Node = null;
|
|
32
|
+
/** 注视的目标,这里我想让相机对准目标的上方一点,所有多加了注视(相机正对着)的目标 */
|
|
33
|
+
@property(Node)
|
|
34
|
+
lookAt: Node = null;
|
|
35
|
+
@property({ type: Enum(ThirdPersonCameraType) })
|
|
36
|
+
cameraType: ThirdPersonCameraType = ThirdPersonCameraType.Follow;
|
|
37
|
+
/** 距离目标距离 */
|
|
38
|
+
@property
|
|
39
|
+
positionOffset: Vec3 = new Vec3(0, 120, 200);
|
|
40
|
+
/** 移动差值移动系数 */
|
|
41
|
+
@property
|
|
42
|
+
moveSmooth: number = 0.02;
|
|
43
|
+
/** 差值旋转系数 */
|
|
44
|
+
@property
|
|
45
|
+
rotateSmooth: number = 0.03;
|
|
46
|
+
|
|
47
|
+
public MouseX: number = 0;
|
|
48
|
+
public MouseY: number = 0;
|
|
49
|
+
|
|
50
|
+
private _forward: Vec3 = new Vec3();
|
|
51
|
+
private _right: Vec3 = new Vec3();
|
|
52
|
+
private _up: Vec3 = new Vec3();
|
|
53
|
+
private angle: IVec3Like = null;
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
start() {
|
|
58
|
+
|
|
59
|
+
// this.node.on(Node.EventType.TOUCH_START, this.MouseDown, this);
|
|
60
|
+
|
|
61
|
+
// 注册触摸事件
|
|
62
|
+
let bbb = find("game")
|
|
63
|
+
bbb.on(Input.EventType.TOUCH_START, this.MouseDown, this);
|
|
64
|
+
bbb.on(Input.EventType.TOUCH_MOVE, this.MouseMove, this);
|
|
65
|
+
bbb.on(Input.EventType.TOUCH_END, this.MouseUp, this);
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
this.cameraType == ThirdPersonCameraType.Follow && this.node.lookAt(this.target.worldPosition);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
isDown: boolean = false;
|
|
73
|
+
private MouseDown(e: EventTouch) {
|
|
74
|
+
this.isDown = true;
|
|
75
|
+
console.log("点击");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private MouseMove(e: EventTouch) {
|
|
79
|
+
|
|
80
|
+
if (this.cameraType == ThirdPersonCameraType.FollowIndependentRotation) {
|
|
81
|
+
|
|
82
|
+
this.SetIndependentRotation(e);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private MouseUp(e: EventTouch) {
|
|
88
|
+
this.isDown = false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
update(dt: number) {
|
|
92
|
+
if (this.target) {
|
|
93
|
+
switch (this.cameraType) {
|
|
94
|
+
case ThirdPersonCameraType.Follow:
|
|
95
|
+
this.SetFollow();
|
|
96
|
+
break;
|
|
97
|
+
case ThirdPersonCameraType.FollowTrackRotation:
|
|
98
|
+
this.SetFollowTrackRotation();
|
|
99
|
+
break;
|
|
100
|
+
case ThirdPersonCameraType.FollowIndependentRotation:
|
|
101
|
+
// this.SetMove();
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private SetFollow() {
|
|
109
|
+
let temp: Vec3 = new Vec3();
|
|
110
|
+
Vec3.add(temp, this.lookAt.worldPosition, new Vec3(0, this.positionOffset.y, this.positionOffset.z));
|
|
111
|
+
this.node.position = this.node.position.lerp(temp, this.moveSmooth);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private velocity = new Vec3();
|
|
115
|
+
private forwardView: Vec3 = new Vec3();
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
private SetFollowTrackRotation() {
|
|
120
|
+
//这里计算出相机距离目标的位置的所在坐标先,距离多高Y,距离多远Z
|
|
121
|
+
//下面四句代码等同于:targetPosition+Up*updistance-forwardView*backDistance
|
|
122
|
+
let u = Vec3.multiplyScalar(new Vec3(), Vec3.UP, this.positionOffset.y);
|
|
123
|
+
let f = Vec3.multiplyScalar(new Vec3(), this.target.forward, this.positionOffset.z);
|
|
124
|
+
let pos = Vec3.add(new Vec3(), this.target.position, u);
|
|
125
|
+
//本来这里应该是减的,可是下面的lookat默认前方是-z,所有这里倒转过来变为加
|
|
126
|
+
Vec3.add(pos, pos, f);
|
|
127
|
+
//球形差值移动,我发现cocos只有Lerp差值移动,而我看unity是有球形差值移动的,所有我这里照搬过来了一个球形差值
|
|
128
|
+
this.node.position = VectorTool.SmoothDampV3(this.node.position, pos, this.velocity, this.moveSmooth, 100000, 0.02);
|
|
129
|
+
//cocos的差值移动
|
|
130
|
+
//this.node.position=this.node.position.lerp(pos,this.moveSmooth);
|
|
131
|
+
//计算前方向
|
|
132
|
+
this.forwardView = Vec3.subtract(this.forwardView, this.node.position, this.target.getWorldPosition());
|
|
133
|
+
this.node.lookAt(this.target.worldPosition);
|
|
134
|
+
//this.node.rotation=Quaternion.LookRotation(this.forwardView);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/*************************FollowIndependentRotation***************** */
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 实时设置相机距离目标的位置position
|
|
141
|
+
*/
|
|
142
|
+
public SetMove() {
|
|
143
|
+
this._forward = new Vec3();
|
|
144
|
+
this._right = new Vec3();
|
|
145
|
+
this._up = new Vec3();
|
|
146
|
+
Vec3.transformQuat(this._forward, Vec3.FORWARD, this.node.rotation);
|
|
147
|
+
//Vec3.transformQuat(this._right, Vec3.RIGHT, this.node.rotation);
|
|
148
|
+
//Vec3.transformQuat(this._up, Vec3.UP, this.node.rotation);
|
|
149
|
+
|
|
150
|
+
this._forward.multiplyScalar(this.positionOffset.z);
|
|
151
|
+
//this._right.multiplyScalar(this.positionOffset.x);
|
|
152
|
+
//this._up.multiplyScalar(this.positionOffset.y);
|
|
153
|
+
let desiredPos = new Vec3();
|
|
154
|
+
desiredPos = desiredPos.add(this.lookAt.worldPosition).subtract(this._forward).add(this._right).add(this._up);
|
|
155
|
+
this.node.position = this.node.position.lerp(desiredPos, this.moveSmooth);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 计算根据鼠标X,Y偏移量来围绕X轴和Y轴的旋转四元数
|
|
160
|
+
* @param e
|
|
161
|
+
*/
|
|
162
|
+
private SetIndependentRotation(e: EventTouch) {
|
|
163
|
+
|
|
164
|
+
let radX: number = -e.getUILocation().x;
|
|
165
|
+
let radY: number = -e.getUILocation().y;
|
|
166
|
+
let _quat: Quat = new Quat();
|
|
167
|
+
|
|
168
|
+
//计算绕X轴旋转的四元数并应用到node,这里用的是鼠标上下Y偏移量
|
|
169
|
+
let _right = Vec3.transformQuat(this._right, Vec3.RIGHT, this.node.rotation);
|
|
170
|
+
_quat = Quaternion.RotationAroundNode(this.node, this.target.position, _right, radY);
|
|
171
|
+
this.angle = Quaternion.GetEulerFromQuat(_quat);
|
|
172
|
+
//限制相机抬头低头的范围
|
|
173
|
+
this.angle.x = this.angle.x > 0 ? this.Clamp(this.angle.x, 120, 180) : this.Clamp(this.angle.x, -180, -170);
|
|
174
|
+
Quat.fromEuler(_quat, this.angle.x, this.angle.y, this.angle.z);
|
|
175
|
+
this.node.setWorldRotation(_quat);
|
|
176
|
+
|
|
177
|
+
//计算绕Y轴旋转的四元数并应用到node,这里用的是鼠标上下X偏移量
|
|
178
|
+
_quat = Quaternion.RotationAroundNode(this.node, this.target.position, Vec3.UP, radX);
|
|
179
|
+
this.node.setWorldRotation(_quat);
|
|
180
|
+
|
|
181
|
+
this.angle = Quaternion.GetEulerFromQuat(_quat);
|
|
182
|
+
this.MouseX = this.angle.y;
|
|
183
|
+
this.MouseY = this.angle.x;
|
|
184
|
+
//console.log(this.MouseX.toFixed(2),this.MouseY.toFixed(2));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/*************************FollowIndependentRotation end***************** */
|
|
188
|
+
|
|
189
|
+
private Clamp(val: number, min: number, max: number) {
|
|
190
|
+
if (val <= min) val = min;
|
|
191
|
+
else if (val >= max) val = max;
|
|
192
|
+
return val;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public GetType(): ThirdPersonCameraType {
|
|
196
|
+
return this.cameraType;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|