@cc-component/cc-ex-component 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.
- package/assets/core/ReferenceCollector.ts +172 -0
- package/assets/core/ReferenceCollector.ts.meta +9 -0
- package/assets/core.meta +9 -0
- package/assets/{BaseEx.ts → ex/BaseEx.ts} +21 -23
- package/assets/{BaseEx.ts.meta → ex/BaseEx.ts.meta} +1 -1
- package/assets/{ExTween.ts.meta → ex/ExTween.ts.meta} +1 -1
- package/assets/ex.meta +9 -0
- package/assets/video/IVideo.ts +73 -0
- package/assets/video/IVideo.ts.meta +9 -0
- package/assets/video/Interface.ts +26 -0
- package/assets/video/Interface.ts.meta +9 -0
- package/assets/video/VideoComponent.prefab +614 -0
- package/assets/video/VideoComponent.prefab.meta +13 -0
- package/assets/video/VideoComponent.ts +33 -0
- package/assets/video/VideoComponent.ts.meta +9 -0
- package/assets/video/VideoManager.ts +395 -0
- package/assets/video/VideoManager.ts.meta +9 -0
- package/assets/video/VideoModule.ts +114 -0
- package/assets/video/VideoModule.ts.meta +9 -0
- package/assets/video/VideoPlayTT.ts +319 -0
- package/assets/video/VideoPlayTT.ts.meta +9 -0
- package/assets/video/VideoPlayWX.ts +246 -0
- package/assets/video/VideoPlayWX.ts.meta +9 -0
- package/assets/video/VideoPlayWeb.ts +228 -0
- package/assets/video/VideoPlayWeb.ts.meta +9 -0
- package/assets/video/list.meta +9 -0
- package/assets/video.meta +9 -0
- package/index.ts +1 -1
- package/index.ts.meta +1 -1
- package/package.json +1 -1
- package/package.json.meta +1 -1
- /package/assets/{ExTween.ts → ex/ExTween.ts} +0 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { _decorator, Component, js, Node } from "cc";
|
|
2
|
+
import { EDITOR_NOT_IN_PREVIEW } from "cc/env";
|
|
3
|
+
|
|
4
|
+
const { ccclass, property, executeInEditMode, executionOrder, disallowMultiple } = _decorator;
|
|
5
|
+
|
|
6
|
+
@ccclass("CollectorNodeData")
|
|
7
|
+
class CollectorNodeData {
|
|
8
|
+
@property({ readonly: true })
|
|
9
|
+
public key = "";
|
|
10
|
+
@property({ type: Node, readonly: true })
|
|
11
|
+
public node: Node = null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@ccclass("ReferenceCollector")
|
|
15
|
+
@disallowMultiple
|
|
16
|
+
@executeInEditMode(true)
|
|
17
|
+
@executionOrder(-100)
|
|
18
|
+
export class ReferenceCollector extends Component {
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
private _refresh = false;
|
|
22
|
+
@property({ displayName: "复制属性" })
|
|
23
|
+
private get refresh() { return this._refresh; }
|
|
24
|
+
private set refresh(val: boolean) {
|
|
25
|
+
if (EDITOR_NOT_IN_PREVIEW) {
|
|
26
|
+
this.initNodeList();
|
|
27
|
+
this.genCode();
|
|
28
|
+
}
|
|
29
|
+
this._refresh = false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@property({ type: CollectorNodeData, readonly: true })
|
|
33
|
+
private _nodes: CollectorNodeData[] = [];
|
|
34
|
+
@property({ type: CollectorNodeData, tooltip: "自动引用节点(名字以$开头的)", readonly: true })
|
|
35
|
+
private get nodes() { return this._nodes; }
|
|
36
|
+
private set nodes(val: CollectorNodeData[]) { this._nodes = val; }
|
|
37
|
+
|
|
38
|
+
private _isInitNodeMap = false;
|
|
39
|
+
private _nodeMap: Map<string, Node> = new Map();
|
|
40
|
+
|
|
41
|
+
protected onLoad(): void {
|
|
42
|
+
if (EDITOR_NOT_IN_PREVIEW) {//处理编辑器逻辑
|
|
43
|
+
this.initNodeList();
|
|
44
|
+
} else {//处理运行时逻辑
|
|
45
|
+
this.initNodeMap();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private initNodeMap() {
|
|
50
|
+
if (this._isInitNodeMap) return;
|
|
51
|
+
this._isInitNodeMap = true;
|
|
52
|
+
this._nodeMap.clear();
|
|
53
|
+
for (const collectorNodeData of this.nodes) {
|
|
54
|
+
let key = collectorNodeData.key.trim();
|
|
55
|
+
if (!this._nodeMap.has(key)) {
|
|
56
|
+
this._nodeMap.set(key, collectorNodeData.node);
|
|
57
|
+
} else {
|
|
58
|
+
console.error("[MLogger Error]", this.node.name, "引用的节点名字重复 Key=" + key);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getNode(key: string) {
|
|
64
|
+
if (this._nodeMap.size == 0) this.initNodeMap();
|
|
65
|
+
return this._nodeMap.get(key);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public get(key: string, type: typeof Node): Node;
|
|
69
|
+
public get<T extends Component>(key: string, type: new (...args: any[]) => T): T;
|
|
70
|
+
public get(key: string, type: any): any {
|
|
71
|
+
if (this._nodeMap.size == 0) this.initNodeMap();
|
|
72
|
+
let node = this._nodeMap.get(key);
|
|
73
|
+
if (node?.isValid) {
|
|
74
|
+
if (type as any === Node) {
|
|
75
|
+
return node;
|
|
76
|
+
} else {
|
|
77
|
+
return node.getComponent(type);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//#region 编辑器逻辑
|
|
84
|
+
|
|
85
|
+
/** 收集名字以$开头的节点 */
|
|
86
|
+
private _tag = "$";
|
|
87
|
+
|
|
88
|
+
private initNodeList() {
|
|
89
|
+
if (!EDITOR_NOT_IN_PREVIEW) return;
|
|
90
|
+
this.nodes.length = 0;
|
|
91
|
+
let nodes = this.getValidNode(this.node);
|
|
92
|
+
for (const node of nodes) {
|
|
93
|
+
let refData = new CollectorNodeData();
|
|
94
|
+
let name = node.name.replace(this._tag, "").trim();
|
|
95
|
+
refData.key = name;
|
|
96
|
+
refData.node = node;
|
|
97
|
+
this.nodes.push(refData);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
/** 获取符合需求的节点 */
|
|
103
|
+
private getValidNode(root: Node) {
|
|
104
|
+
if (!EDITOR_NOT_IN_PREVIEW) return;
|
|
105
|
+
let arr: Node[] = [];
|
|
106
|
+
let checkArr: Node[] = [];
|
|
107
|
+
checkArr.push(root);
|
|
108
|
+
while (checkArr.length > 0) {
|
|
109
|
+
let v = checkArr.shift();
|
|
110
|
+
let rc = v.getComponent(ReferenceCollector);
|
|
111
|
+
if (rc && rc != this) continue;
|
|
112
|
+
arr.push(...v.children.filter(v => this.isNodeValid(v)));
|
|
113
|
+
checkArr.push(...v.children);
|
|
114
|
+
}
|
|
115
|
+
return arr;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private isNodeValid(node: Node) {
|
|
119
|
+
if (!EDITOR_NOT_IN_PREVIEW) return;
|
|
120
|
+
if (node.name.startsWith(this._tag)) return true;
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 生成引用节点的获取代码 并复制到剪切板 */
|
|
125
|
+
private genCode() {
|
|
126
|
+
if (!EDITOR_NOT_IN_PREVIEW) return;
|
|
127
|
+
let text = "";
|
|
128
|
+
//生成get属性
|
|
129
|
+
this.nodes.forEach(data => {
|
|
130
|
+
let key = data.key;
|
|
131
|
+
if (text) text += "\n";
|
|
132
|
+
let name = key[0].toLowerCase() + key.substring(1);
|
|
133
|
+
let line = `private get ${name}() { return this.rc.get("${key}", ${this.getPropertyType(data.node)}); }`;
|
|
134
|
+
text += line;
|
|
135
|
+
});
|
|
136
|
+
Editor.Clipboard.write("text", text);
|
|
137
|
+
console.log("已复制到剪切板");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** 获取属性类型名字 */
|
|
141
|
+
private getPropertyType(node: Node) {
|
|
142
|
+
if (!EDITOR_NOT_IN_PREVIEW) return;
|
|
143
|
+
|
|
144
|
+
//自定义脚本
|
|
145
|
+
let comp = node.getComponent('MComponent');
|
|
146
|
+
if (comp) return js.getClassName(comp);
|
|
147
|
+
//自定义组件
|
|
148
|
+
if (node.getComponent("Switch")) return "Switch";
|
|
149
|
+
if (node.getComponent("MSlider")) return "MSlider";
|
|
150
|
+
if (node.getComponent("MToggle")) return "MToggle";
|
|
151
|
+
if (node.getComponent("MButton")) return "MButton";
|
|
152
|
+
if (node.getComponent("Dropdown")) return "Dropdown";
|
|
153
|
+
//UI组件
|
|
154
|
+
if (node.getComponent("cc.EditBox")) return "EditBox";
|
|
155
|
+
if (node.getComponent("cc.Toggle")) return "Toggle";
|
|
156
|
+
if (node.getComponent("cc.Slider")) return "Slider";
|
|
157
|
+
if (node.getComponent("cc.Button")) return "Button";
|
|
158
|
+
if (node.getComponent("cc.ProgressBar")) return "ProgressBar";
|
|
159
|
+
if (node.getComponent("cc.ScrollView")) return "ScrollView";
|
|
160
|
+
if (node.getComponent("cc.PageView")) return "PageView";
|
|
161
|
+
if (node.getComponent("cc.Animation")) return "Animation";
|
|
162
|
+
//渲染组件
|
|
163
|
+
if (node.getComponent("cc.Sprite")) return "Sprite";
|
|
164
|
+
if (node.getComponent("cc.Label")) return "Label";
|
|
165
|
+
if (node.getComponent("cc.RichText")) return "RichText";
|
|
166
|
+
if (node.getComponent("cc.ParticleSystem2D")) return "ParticleSystem2D";
|
|
167
|
+
if (node.getComponent("sp.Skeleton")) return "sp.Skeleton";
|
|
168
|
+
|
|
169
|
+
return "Node";
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
}
|
package/assets/core.meta
ADDED
|
@@ -10,6 +10,7 @@ import { Color } from "cc";
|
|
|
10
10
|
|
|
11
11
|
declare global {
|
|
12
12
|
interface String {
|
|
13
|
+
/**转map */
|
|
13
14
|
toMap<K, V>(): Map<K, V>;
|
|
14
15
|
/**转数组 */
|
|
15
16
|
toArray<T>(): T[];
|
|
@@ -17,19 +18,24 @@ declare global {
|
|
|
17
18
|
toObj<T>(): T;
|
|
18
19
|
/**是JSON */
|
|
19
20
|
isJSON(): boolean;
|
|
21
|
+
/**转bool */
|
|
20
22
|
toBool(): boolean;
|
|
23
|
+
/**转数字 */
|
|
21
24
|
toNumber(): number;
|
|
22
25
|
/**添加颜色-富文本 */
|
|
23
26
|
addColor(colorHex: string): string
|
|
24
27
|
/**添加颜色 -富文本*/
|
|
25
28
|
addSize(font: number): string
|
|
26
29
|
}
|
|
30
|
+
|
|
27
31
|
interface Any {
|
|
28
32
|
toMap<K, V>(): Map<K, V>;
|
|
29
33
|
/**对象转map */
|
|
30
34
|
toMapObj<K, V>(): Map<K, V>;
|
|
31
35
|
}
|
|
36
|
+
|
|
32
37
|
interface Number {
|
|
38
|
+
/**时间戳转天数 */
|
|
33
39
|
toDay(): { days: number, hours: number, minutes: number, seconds: number };
|
|
34
40
|
}
|
|
35
41
|
|
|
@@ -38,7 +44,9 @@ declare global {
|
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
interface Array<T> {
|
|
47
|
+
/**数组第一个元素 */
|
|
41
48
|
first(): T;
|
|
49
|
+
/**数组最后一个元素 */
|
|
42
50
|
last(): T;
|
|
43
51
|
/**
|
|
44
52
|
* 将一维数组按指定大小分组成二维数组
|
|
@@ -49,27 +57,21 @@ declare global {
|
|
|
49
57
|
chunkArray(chunkSize: number): T[][];
|
|
50
58
|
|
|
51
59
|
}
|
|
52
|
-
}
|
|
53
|
-
interface Window {
|
|
54
|
-
/**抖音添加到桌面按钮 */
|
|
55
|
-
tt_button: boolean;
|
|
56
|
-
/**抖音订阅 */
|
|
57
|
-
tt_button_ding_yue: boolean;
|
|
58
|
-
/**抖音订阅视频流 */
|
|
59
|
-
tt_button_ding_yue_feed: boolean;
|
|
60
|
-
|
|
61
|
-
/**微信订阅 */
|
|
62
|
-
wx_button_ding_yue: boolean;
|
|
63
60
|
|
|
61
|
+
interface Window {
|
|
62
|
+
/**抖音添加到桌面按钮 */
|
|
63
|
+
tt_button: boolean;
|
|
64
|
+
/**抖音订阅 */
|
|
65
|
+
tt_button_ding_yue: boolean;
|
|
66
|
+
/**抖音订阅视频流 */
|
|
67
|
+
tt_button_ding_yue_feed: boolean;
|
|
68
|
+
/**微信订阅 */
|
|
69
|
+
wx_button_ding_yue: boolean;
|
|
70
|
+
}
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// 扩展 Node 接口,声明自定义属性
|
|
73
|
+
// 扩展 cocos
|
|
69
74
|
declare module 'cc' {
|
|
70
|
-
interface window {
|
|
71
|
-
|
|
72
|
-
}
|
|
73
75
|
interface Asset {
|
|
74
76
|
/**资源路径 */
|
|
75
77
|
asset_path: string;
|
|
@@ -83,7 +85,6 @@ declare module 'cc' {
|
|
|
83
85
|
//暂停所有schedule
|
|
84
86
|
pauseSchedule(): void;
|
|
85
87
|
resumeSchedule(): void;
|
|
86
|
-
|
|
87
88
|
/**暂停所有的spine 和 tween 和schedule
|
|
88
89
|
* key 是指定twenn的分组key,不传参则 不暂停tween,使用TweenGame 收集tween
|
|
89
90
|
*/
|
|
@@ -115,7 +116,6 @@ declare module 'cc' {
|
|
|
115
116
|
addActionSlider(callBack: (slider: Slider) => void): void;
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
|
|
119
119
|
interface ProgressBar {
|
|
120
120
|
pro(progress: number, max: number, anim_time?: number);
|
|
121
121
|
}
|
|
@@ -150,6 +150,8 @@ declare module 'cc' {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
+
|
|
154
|
+
//#region 实现
|
|
153
155
|
/**
|
|
154
156
|
* 扩展 UITransform 接口,添加 isBoxInsideAnotherBox 方法
|
|
155
157
|
*/
|
|
@@ -356,10 +358,6 @@ Object.defineProperties(Slider.prototype, {
|
|
|
356
358
|
}
|
|
357
359
|
});
|
|
358
360
|
|
|
359
|
-
|
|
360
|
-
//.
|
|
361
|
-
|
|
362
|
-
|
|
363
361
|
// 实现字符串扩展方法
|
|
364
362
|
String.prototype.toMap = function <K, V>(): Map<K, V> {
|
|
365
363
|
try {
|
package/assets/ex.meta
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Component, Node } from "cc";
|
|
2
|
+
|
|
3
|
+
export interface InitParam {
|
|
4
|
+
node: Node,
|
|
5
|
+
cover: Node,
|
|
6
|
+
bg: Node,
|
|
7
|
+
bundle: string,
|
|
8
|
+
dir: string,
|
|
9
|
+
cover_dir: string,
|
|
10
|
+
remote_url: string,
|
|
11
|
+
proCall?: (pro: number) => void
|
|
12
|
+
}
|
|
13
|
+
export interface IVideoData {
|
|
14
|
+
/**视频文件名称 */
|
|
15
|
+
name: string,
|
|
16
|
+
/**开始时间*/
|
|
17
|
+
start_time?: number,
|
|
18
|
+
/**结束时间 */
|
|
19
|
+
end_time?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IVideoParam {
|
|
23
|
+
/**本次播放或者加载,是否指定目标大小*/
|
|
24
|
+
isTargetSize?: boolean,
|
|
25
|
+
/**是否是 时间段 视频,备注:多个小视频合成一个大视频 */
|
|
26
|
+
isPlayTime?: boolean,
|
|
27
|
+
/**循环播放 */
|
|
28
|
+
isLoop?: boolean,
|
|
29
|
+
/**封面图片 */
|
|
30
|
+
coverImage?: string,
|
|
31
|
+
/**是否不是全屏-保持原比例 */
|
|
32
|
+
isFullNot?: boolean,
|
|
33
|
+
/**视频封面 */
|
|
34
|
+
onRead?: Function,
|
|
35
|
+
/**播放完成 */
|
|
36
|
+
onFinish?: Function,
|
|
37
|
+
/**可不设置
|
|
38
|
+
* 是本地视频还是远程,
|
|
39
|
+
* 小游戏会设置为:远程视频,
|
|
40
|
+
* 安卓和ios原生端会可不设置,根据url 判断是远程还是本地视频 */
|
|
41
|
+
isLocal?: boolean,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// export interface IVideoParam {
|
|
46
|
+
// isPlayTime?: boolean,
|
|
47
|
+
// isLoop?: boolean,
|
|
48
|
+
// finish?: Function,
|
|
49
|
+
|
|
50
|
+
// }
|
|
51
|
+
|
|
52
|
+
export class BaseVideo extends Component {
|
|
53
|
+
initVideo(initParam: { bundle: string, dir: string }) { }
|
|
54
|
+
loadVideo(name: string, param?: IVideoParam) { }
|
|
55
|
+
play(isloop?: boolean) { }
|
|
56
|
+
async pause() { }
|
|
57
|
+
stop() { }
|
|
58
|
+
resume() { }
|
|
59
|
+
seek(time: number) { }
|
|
60
|
+
destroyVideo() { }
|
|
61
|
+
setSize(param: { x: number, y: number, width: number, height: number }) { }
|
|
62
|
+
autoSize() { }
|
|
63
|
+
onTimeUpdate: (data: { position: number, duration: number }) => void;
|
|
64
|
+
onError: Function
|
|
65
|
+
onVideoEnd: Function
|
|
66
|
+
onRead: Function
|
|
67
|
+
getisPause(): boolean {
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
// getDuration(): number;
|
|
71
|
+
// isPlaying: boolean;
|
|
72
|
+
// isLocal:boolean;
|
|
73
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { macro } from "cc";
|
|
2
|
+
import { IVideoData, IVideoParam } from "./IVideo";
|
|
3
|
+
declare global {
|
|
4
|
+
namespace VideoModule {
|
|
5
|
+
/**开启日志打印 */
|
|
6
|
+
function Debug(enabled: boolean);
|
|
7
|
+
/**提前加载视频 */
|
|
8
|
+
function LoadVideo(url: string, param: IVideoParam)
|
|
9
|
+
/**播放单个视频 */
|
|
10
|
+
function PlayVideo(video: IVideoData, param: IVideoParam)
|
|
11
|
+
/** 播放多个视频*/
|
|
12
|
+
function PlayVideoMore(video_list: IVideoData[], param: IVideoParam)
|
|
13
|
+
/**暂停 */
|
|
14
|
+
function Pause()
|
|
15
|
+
/**继续 */
|
|
16
|
+
function Resume()
|
|
17
|
+
/**停止视频 */
|
|
18
|
+
function StopVideoTask()
|
|
19
|
+
/**视频设置到指定大小 */
|
|
20
|
+
function SetSize(param: { x: number, y: number, width: number, height: number })
|
|
21
|
+
/**节点位置适配-自动适配 */
|
|
22
|
+
function AutoSize()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// // 必须在 game.init() 之前设置!
|
|
26
|
+
//macro.ENABLE_TRANSPARENT_CANVAS = true;
|