Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sn03_playVideo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
sn03_playVideo
Commits
2fdf3931
Commit
2fdf3931
authored
Oct 19, 2023
by
李维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除无用的预制体文件
parent
587821a6
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
0 additions
and
8546 deletions
+0
-8546
JJ_Video_01.prefab
assets/sn03_playVideo/prefab/JJ_Video_01/JJ_Video_01.prefab
+0
-7120
JJ_Video_01.prefab.meta
...sn03_playVideo/prefab/JJ_Video_01/JJ_Video_01.prefab.meta
+0
-8
Scene.meta
assets/sn03_playVideo/prefab/JJ_Video_01/Scene.meta
+0
-12
JJ_Video_01.ts
...ts/sn03_playVideo/prefab/JJ_Video_01/Scene/JJ_Video_01.ts
+0
-720
JJ_Video_01.ts.meta
...03_playVideo/prefab/JJ_Video_01/Scene/JJ_Video_01.ts.meta
+0
-9
Script.meta
assets/sn03_playVideo/prefab/JJ_Video_01/Script.meta
+0
-12
defaultData_JJ_Video_01.js
...ideo/prefab/JJ_Video_01/Script/defaultData_JJ_Video_01.js
+0
-16
defaultData_JJ_Video_01.js.meta
...prefab/JJ_Video_01/Script/defaultData_JJ_Video_01.js.meta
+0
-9
util_JJ_Video_01.js
...3_playVideo/prefab/JJ_Video_01/Script/util_JJ_Video_01.js
+0
-631
util_JJ_Video_01.js.meta
...yVideo/prefab/JJ_Video_01/Script/util_JJ_Video_01.js.meta
+0
-9
No files found.
assets/sn03_playVideo/prefab/JJ_Video_01/JJ_Video_01.prefab
deleted
100644 → 0
View file @
587821a6
This source diff could not be displayed because it is too large. You can
view the blob
instead.
assets/sn03_playVideo/prefab/JJ_Video_01/JJ_Video_01.prefab.meta
deleted
100644 → 0
View file @
587821a6
{
"ver": "1.2.9",
"uuid": "59286199-6a11-47ed-8d48-f792c3448a8f",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}
\ No newline at end of file
assets/sn03_playVideo/prefab/JJ_Video_01/Scene.meta
deleted
100644 → 0
View file @
587821a6
{
"ver": "1.1.2",
"uuid": "c83618a6-a058-4cb0-bf49-0872f18ba784",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
assets/sn03_playVideo/prefab/JJ_Video_01/Scene/JJ_Video_01.ts
deleted
100644 → 0
View file @
587821a6
import
{
asyncGetSpriteFrimeByUrl
,
onHomeworkFinish
}
from
"
../Script/util_JJ_Video_01
"
;
import
{
defaultData
}
from
"
../Script/defaultData_JJ_Video_01
"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
@
ccclass
export
default
class
VideoPlayerComponent
extends
cc
.
Component
{
@
property
(
cc
.
VideoPlayer
)
videoPlayer
:
cc
.
VideoPlayer
=
null
;
@
property
(
cc
.
Node
)
ProgressBar
:
cc
.
Node
=
null
;
@
property
(
cc
.
Button
)
playButton
:
cc
.
Button
=
null
;
@
property
(
cc
.
Button
)
pauseButton
:
cc
.
Button
=
null
;
@
property
(
cc
.
Button
)
restartButton
:
cc
.
Button
=
null
;
@
property
(
cc
.
Button
)
backButton
:
cc
.
Button
=
null
;
@
property
(
cc
.
Button
)
forwardButton
:
cc
.
Button
=
null
;
@
property
(
cc
.
Label
)
durationLabel
:
cc
.
Label
=
null
;
@
property
(
cc
.
Label
)
currentTimeLabel
:
cc
.
Label
=
null
;
@
property
(
cc
.
Node
)
barTag
:
cc
.
Node
=
null
;
@
property
(
cc
.
Node
)
bar
:
cc
.
Node
=
null
;
@
property
(
cc
.
Node
)
loadingSprite
:
cc
.
Node
=
null
;
_designSize
:
cc
.
Size
=
null
;
_frameSize
:
cc
.
Size
=
null
;
_mapScaleMin
:
number
=
null
;
_mapScaleMax
:
number
=
null
;
_cocosScale
:
number
=
null
;
data
;
initSize
()
{
let
screen_size
=
cc
.
view
.
getFrameSize
().
width
/
cc
.
view
.
getFrameSize
().
height
;
let
design_size
=
cc
.
Canvas
.
instance
.
designResolution
.
width
/
cc
.
Canvas
.
instance
.
designResolution
.
height
;
console
.
log
(
"
原本尺寸
"
,
screen_size
,
"
现在尺寸
"
,
design_size
)
let
f
=
screen_size
>=
design_size
;
cc
.
Canvas
.
instance
.
fitHeight
=
f
;
cc
.
Canvas
.
instance
.
fitWidth
=
!
f
;
const
frameSize
=
cc
.
view
.
getFrameSize
();
this
.
_frameSize
=
frameSize
;
this
.
_designSize
=
cc
.
view
.
getDesignResolutionSize
();
let
sx
=
cc
.
winSize
.
width
/
frameSize
.
width
;
let
sy
=
cc
.
winSize
.
height
/
frameSize
.
height
;
this
.
_cocosScale
=
Math
.
min
(
sx
,
sy
);
sx
=
frameSize
.
width
/
this
.
_designSize
.
width
;
sy
=
frameSize
.
height
/
this
.
_designSize
.
height
;
this
.
_mapScaleMin
=
Math
.
min
(
sx
,
sy
)
*
this
.
_cocosScale
;
this
.
_mapScaleMax
=
Math
.
max
(
sx
,
sy
)
*
this
.
_cocosScale
;
console
.
log
(
"
原本宽度
"
,
cc
.
director
[
"
_scene
"
].
width
,
"
现在宽度
"
,
frameSize
.
width
)
console
.
log
(
"
原本高度
"
,
cc
.
director
[
"
_scene
"
].
height
,
"
现在高度
"
,
frameSize
.
height
)
cc
.
director
[
"
_scene
"
].
width
=
frameSize
.
width
;
cc
.
director
[
"
_scene
"
].
height
=
frameSize
.
height
;
}
getVideoUrl
(
url1
:
string
):
Promise
<
string
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
url2
=
url1
.
replace
(
/.mp4$/g
,
"
_h.mp4
"
);
this
.
httpHeadCall
(
url2
,
(
success
)
=>
{
if
(
success
)
{
console
.
log
(
'
return url2:
'
,
url2
);
resolve
(
url2
);
}
else
{
console
.
log
(
'
return url1:
'
,
url1
);
resolve
(
url1
);
}
});
});
}
httpHeadCall
(
requestUrl
:
string
,
callback
:
(
success
:
boolean
)
=>
void
)
{
let
xhr
=
new
XMLHttpRequest
();
console
.
log
(
"
Status: Send Post Request to
"
+
requestUrl
);
try
{
xhr
.
onreadystatechange
=
()
=>
{
try
{
console
.
log
(
'
xhr.readyState:
'
,
xhr
.
readyState
);
if
(
xhr
.
readyState
==
4
)
{
if
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
)
{
callback
(
true
);
}
else
{
callback
(
false
);
}
}
}
catch
(
e
)
{
console
.
log
(
e
);
}
};
xhr
.
open
(
"
HEAD
"
,
requestUrl
,
true
);
xhr
.
send
();
xhr
.
timeout
=
15000
;
xhr
.
onerror
=
(
e
)
=>
{
console
.
log
(
"
汪汪汪 posterror
"
,
e
);
callback
(
false
);
};
xhr
.
ontimeout
=
(
e
)
=>
{
console
.
log
(
"
汪汪汪 ontimeout
"
,
e
);
callback
(
false
);
};
}
catch
(
e
)
{
console
.
log
(
"
Send Get Request error:
"
,
e
);
}
}
_isPlayComplated
:
boolean
=
null
;
_isReadyToPlay
:
boolean
=
null
;
onLoad
()
{
cc
.
debug
.
setDisplayStats
(
false
);
this
.
initSize
();
cc
.
find
(
'
JJ_Video_01/bg
'
).
scale
=
this
.
_mapScaleMax
;
cc
.
find
(
'
JJ_Video_01/video_node/bg
'
).
scale
=
this
.
_mapScaleMax
;
// cc.find('JJ_Video_01/bgwhite').zIndex=-2
// cc.find('JJ_Video_01/bg').zIndex=-1
// cc.find('JJ_Video_01/VideoNode').zIndex=0
// cc.find('JJ_Video_01/video_node').zIndex=1
// cc.find('JJ_Video_01/bg_video_shadow').zIndex=2
// cc.find('JJ_Video_01/Controls').zIndex=3
// cc.find('JJ_Video_01/videolist').zIndex=4
// cc.find('JJ_Video_01/btn_return').zIndex=5
// cc.find('JJ_Video_01/title').zIndex=5
this
.
_isReadyToPlay
=
false
;
cc
.
macro
.
ENABLE_TRANSPARENT_CANVAS
=
true
;
this
.
videoPlayer
.
node
.
on
(
'
ready-to-play
'
,
()
=>
{
console
.
log
(
'
ready-to-play
'
);
this
.
playButton
.
node
.
active
=
true
;
cc
.
find
(
`JJ_Video_01/bg_video_shadow`
).
active
=
false
;
// cc.find(`JJ_Video_01/loading`).active = false;
this
.
durationLabel
.
string
=
this
.
formatTime
(
this
.
videoPlayer
.
getDuration
());
this
.
_isReadyToPlay
=
true
;
this
.
_isPlayComplated
=
false
;
this
.
videoPlayer
.
currentTime
=
0
;
this
.
play
();
});
this
.
videoPlayer
.
node
.
on
(
'
meta-loaded
'
,
()
=>
{
console
.
log
(
'
meta-loaded
'
);
});
this
.
videoPlayer
.
node
.
on
(
'
clicked
'
,
()
=>
{
console
.
log
(
'
clicked
'
);
if
(
this
.
isVideoFull
)
{
this
.
videoPlayer
.
stayOnBottom
=
true
;
cc
.
find
(
`JJ_Video_01/Controls`
).
active
=
true
;
if
(
this
.
time1
)
{
clearTimeout
(
this
.
time1
);
}
this
.
time1
=
setTimeout
(()
=>
{
this
.
videoPlayer
.
stayOnBottom
=
false
;
cc
.
find
(
`JJ_Video_01/Controls`
).
active
=
false
;
},
6000
);
}
});
this
.
videoPlayer
.
node
.
on
(
'
touchstarted
'
,
()
=>
{
console
.
log
(
'
touchstarted
'
);
if
(
this
.
isVideoFull
)
{
this
.
videoPlayer
.
stayOnBottom
=
true
;
cc
.
find
(
`JJ_Video_01/Controls`
).
active
=
true
;
if
(
this
.
time1
)
{
clearTimeout
(
this
.
time1
);
}
this
.
time1
=
setTimeout
(()
=>
{
this
.
videoPlayer
.
stayOnBottom
=
false
;
cc
.
find
(
`JJ_Video_01/Controls`
).
active
=
false
;
},
6000
);
}
});
this
.
videoPlayer
.
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
console
.
log
(
'
touchstarted
'
);
if
(
this
.
isVideoFull
)
{
this
.
videoPlayer
.
stayOnBottom
=
true
;
cc
.
find
(
`JJ_Video_01/Controls`
).
active
=
true
;
if
(
this
.
time1
)
{
clearTimeout
(
this
.
time1
);
}
this
.
time1
=
setTimeout
(()
=>
{
this
.
videoPlayer
.
stayOnBottom
=
false
;
cc
.
find
(
`JJ_Video_01/Controls`
).
active
=
false
;
},
6000
);
}
});
this
.
videoPlayer
.
node
.
on
(
'
playing
'
,
()
=>
{
console
.
log
(
'
playing
'
);
this
.
durationLabel
.
string
=
this
.
formatTime
(
this
.
videoPlayer
.
getDuration
());
this
.
playButton
.
node
.
active
=
false
;
this
.
restartButton
.
node
.
active
=
false
;
this
.
pauseButton
.
node
.
active
=
true
;
});
this
.
videoPlayer
.
node
.
on
(
'
paused
'
,
()
=>
{
console
.
log
(
'
paused
'
);
});
this
.
videoPlayer
.
node
.
on
(
'
stopped
'
,
()
=>
{
console
.
log
(
'
stopped
'
);
});
this
.
videoPlayer
.
node
.
on
(
'
completed
'
,
async
()
=>
{
console
.
log
(
'
completed
'
);
this
.
_isPlayComplated
=
true
;
this
.
playButton
.
node
.
active
=
false
;
this
.
pauseButton
.
node
.
active
=
false
;
this
.
restartButton
.
node
.
active
=
false
;
const
nextItem
=
this
.
videoItemList
[
this
.
videoPlayIndex
+
1
];
if
(
nextItem
)
{
nextItem
.
emit
(
'
my_item_click
'
);
}
else
{
this
.
videoItemList
[
0
].
emit
(
'
my_item_click
'
);
}
});
cc
.
view
.
setResizeCallback
(()
=>
{
console
.
log
(
'
Resize
'
);
this
.
initdDrag
();
});
this
.
initdDrag
();
this
.
videoPlayIndex
=
0
this
.
refreshLastNextBtns
()
}
refreshLastNextBtns
(){
cc
.
find
(
"
JJ_Video_01/btn_last
"
).
active
=
this
.
videoPlayIndex
!=
0
if
(
this
.
videoItemList
)
cc
.
find
(
"
JJ_Video_01/btn_next
"
).
active
=
this
.
videoPlayIndex
!=
this
.
videoItemList
.
length
-
1
}
onClickNext
(){
const
nextItem
=
this
.
videoItemList
[
this
.
videoPlayIndex
+
1
];
if
(
nextItem
)
{
nextItem
.
emit
(
'
my_item_click
'
);
}
else
{
this
.
videoItemList
[
0
].
emit
(
'
my_item_click
'
);
}
this
.
refreshLastNextBtns
()
}
onClickLast
(){
const
nextItem
=
this
.
videoItemList
[
this
.
videoPlayIndex
-
1
];
if
(
nextItem
)
{
nextItem
.
emit
(
'
my_item_click
'
);
}
else
{
this
.
videoItemList
[
0
].
emit
(
'
my_item_click
'
);
}
this
.
refreshLastNextBtns
()
}
initListener
()
{
if
(
window
[
'
air
'
])
{
window
[
"
air
"
].
dialogStatus
=
(
statusCode
:
number
)
=>
{
console
.
log
(
"
缓冲
"
,
statusCode
);
if
(
statusCode
==
701
)
{
this
.
loadingSprite
.
active
=
true
;
}
else
if
(
statusCode
==
702
)
{
this
.
loadingSprite
.
active
=
false
;
}
};
}
}
initdDrag
()
{
const
maxX
=
this
.
ProgressBar
.
width
;
const
minX
=
0
;
this
.
barTag
.
off
(
cc
.
Node
.
EventType
.
TOUCH_START
);
this
.
barTag
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
(
e
)
=>
{
if
(
!
this
.
_isReadyToPlay
)
{
return
;
}
console
.
log
(
"
TOUCH_START
"
);
});
this
.
barTag
.
off
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
);
this
.
barTag
.
on
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
,
(
e
)
=>
{
if
(
!
this
.
_isReadyToPlay
)
{
return
;
}
const
worldPos
=
e
.
getLocation
();
const
localPos
=
this
.
barTag
.
parent
.
convertToNodeSpaceAR
(
worldPos
);
let
newX
=
localPos
.
x
;
newX
=
Math
.
min
(
maxX
,
Math
.
max
(
newX
,
minX
));
this
.
barTag
.
x
=
newX
;
const
percent
=
newX
/
maxX
;
const
dur
=
this
.
videoPlayer
.
getDuration
();
this
.
currentTimeLabel
.
string
=
this
.
formatTime
(
percent
*
dur
);
this
.
videoPlayer
.
currentTime
=
percent
*
dur
;
});
this
.
barTag
.
off
(
cc
.
Node
.
EventType
.
TOUCH_END
);
this
.
barTag
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
(
e
)
=>
{
if
(
!
this
.
_isReadyToPlay
)
{
return
;
}
console
.
log
(
"
TOUCH_ENDED
"
);
this
.
updateBarByPos
(
this
.
barTag
.
x
);
});
this
.
barTag
.
off
(
cc
.
Node
.
EventType
.
MOUSE_UP
);
this
.
barTag
.
on
(
cc
.
Node
.
EventType
.
MOUSE_UP
,
(
e
)
=>
{
if
(
!
this
.
_isReadyToPlay
)
{
return
;
}
console
.
log
(
"
MOUSE_UP
"
);
this
.
updateBarByPos
(
this
.
barTag
.
x
);
});
}
videoItemList
:
cc
.
Node
[]
=
null
;
videoPlayIndex
:
number
=
null
;
async
initView
()
{
this
.
videoItemList
=
[];
const
videoListContent
=
cc
.
find
(
`JJ_Video_01/videolist/view/content`
);
const
templateItem
=
cc
.
find
(
`item`
,
videoListContent
);
for
(
let
i
=
0
;
i
<
this
.
data
.
dataArr
.
length
;
i
++
)
{
const
row
=
this
.
data
.
dataArr
[
i
];
const
itemClone
=
cc
.
instantiate
(
templateItem
);
itemClone
.
parent
=
videoListContent
;
itemClone
.
active
=
true
;
const
spriteFrame
=
await
asyncGetSpriteFrimeByUrl
(
row
.
cover
);
const
picNode1
=
cc
.
find
(
`item/mask/cover`
,
itemClone
);
picNode1
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
spriteFrame
;
const
sx1
=
321
/
picNode1
.
width
;
const
sy1
=
199
/
picNode1
.
height
;
picNode1
.
scale
=
Math
.
min
(
sx1
,
sy1
);
const
picNode2
=
cc
.
find
(
`item_active/mask/cover`
,
itemClone
);
picNode2
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
spriteFrame
;
const
sx2
=
366
/
picNode2
.
width
;
const
sy2
=
227
/
picNode2
.
height
;
picNode2
.
scale
=
Math
.
min
(
sx2
,
sy2
);
cc
.
find
(
`item_active/title`
,
itemClone
).
getComponent
(
cc
.
Label
).
string
=
row
.
title
;
cc
.
find
(
`item/title`
,
itemClone
).
getComponent
(
cc
.
Label
).
string
=
row
.
title
;
cc
.
find
(
`item_active/num`
,
itemClone
).
getComponent
(
cc
.
Label
).
string
=
String
(
i
+
1
>
9
?
(
i
+
1
)
:
`0
${
i
+
1
}
`
);
cc
.
find
(
`item/num`
,
itemClone
).
getComponent
(
cc
.
Label
).
string
=
String
(
i
+
1
>
9
?
(
i
+
1
)
:
`0
${
i
+
1
}
`
);
itemClone
.
attr
({
video_url
:
row
.
video_url
,
playIndex
:
i
});
itemClone
.
on
(
'
my_item_click
'
,
()
=>
{
this
.
clickVideoItem
(
null
,
itemClone
);
});
this
.
videoItemList
.
push
(
itemClone
);
}
let
videolist
=
cc
.
find
(
`JJ_Video_01/videolist`
)
videolist
.
getComponent
(
cc
.
ScrollView
).
scrollToLeft
()
}
showTips
(
tips
:
string
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
showTips
(
tips
);
}
else
{
console
.
log
(
tips
);
}
}
async
clickVideoItem
(
evt
:
cc
.
Event
.
EventTouch
,
_node
:
cc
.
Node
)
{
const
item
=
evt
?
evt
.
currentTarget
:
_node
;
if
(
!
item
.
video_url
)
{
this
.
showTips
(
"
视频不存在
"
);
return
;
}
if
(
item
.
video_url
==
this
.
videoPlayer
.
remoteURL
)
{
this
.
showTips
(
"
该视频正在播放
"
);
return
;
}
this
.
videoPlayIndex
=
item
.
playIndex
;
this
.
_isReadyToPlay
=
false
;
// cc.find(`JJ_Video_01/loading`).active = true;
cc
.
find
(
`JJ_Video_01/bg`
).
active
=
true
;
cc
.
find
(
`JJ_Video_01/bgwhite`
).
active
=
true
;
// cc.find(`JJ_Video_01/bg_video_shadow`).active = true;
// this.videoPlayer.node.x = -5000;
// this.videoPlayer.node.y = -5000;
cc
.
find
(
`JJ_Video_01/videolist/view/content`
).
children
.
forEach
(
row
=>
{
cc
.
find
(
`item_active`
,
row
).
active
=
false
;
cc
.
find
(
`item`
,
row
).
active
=
true
;
});
cc
.
find
(
`item_active`
,
item
).
active
=
true
;
const
originalUrl
=
item
.
video_url
;
this
.
videoPlayer
.
remoteURL
=
await
this
.
getVideoUrl
(
item
.
video_url
);
for
(
let
i
=
0
;
i
<
this
.
data
.
dataArr
.
length
;
i
++
)
{
const
element
=
this
.
data
.
dataArr
[
i
];
if
(
element
.
video_url
==
originalUrl
)
{
const
count
=
this
.
data
.
dataArr
[
i
].
count
;
if
(
count
)
{
this
.
data
.
dataArr
[
i
].
count
++
;
}
else
{
this
.
data
.
dataArr
[
i
].
count
=
1
;
}
}
}
const
totalCount
=
this
.
data
.
totalCount
;
if
(
totalCount
)
{
this
.
data
.
totalCount
++
;
}
else
{
this
.
data
.
totalCount
=
1
;
}
this
.
refreshLastNextBtns
()
}
start
()
{
this
.
node
.
zIndex
=
10000
;
let
getData
=
this
.
getData
.
bind
(
this
);
if
(
window
&&
window
[
"
courseware
"
])
{
getData
=
window
[
"
courseware
"
].
getData
;
}
getData
(
async
(
data
)
=>
{
console
.
log
(
'
data:
'
,
JSON
.
stringify
(
data
));
this
.
data
=
data
||
this
.
getDefaultData
();
await
this
.
initView
();
if
(
window
&&
window
[
"
air
"
])
{
window
[
"
air
"
].
hideAirClassLoading
();
}
cc
.
find
(
`JJ_Video_01/videolist`
).
active
=
this
.
data
.
dataArr
.
length
>
1
;
if
(
this
.
data
.
dataArr
.
length
<=
1
){
console
.
log
(
"
qsj???
"
)
cc
.
find
(
`JJ_Video_01/bg/videoBg`
).
scale
=
1.2
cc
.
find
(
`JJ_Video_01/bg/videoBg`
).
y
=-
136.058
// cc.find(`JJ_Video_01/video_node`).scale=1.2
cc
.
find
(
`JJ_Video_01/video_node`
).
width
*=
1.2
cc
.
find
(
`JJ_Video_01/video_node`
).
height
*=
1.2
cc
.
find
(
`JJ_Video_01/video_node`
).
y
=
73.311
cc
.
find
(
`JJ_Video_01/bg_video_shadow`
).
scale
=
1.2
cc
.
find
(
`JJ_Video_01/bg_video_shadow`
).
y
=
59.039
cc
.
find
(
`JJ_Video_01/btn_last`
).
x
=-
734.101
cc
.
find
(
`JJ_Video_01/btn_last`
).
y
=-
39.603
cc
.
find
(
`JJ_Video_01/btn_next`
).
x
=
734.101
cc
.
find
(
`JJ_Video_01/btn_next`
).
y
=-
39.603
cc
.
find
(
`JJ_Video_01/VideoNode`
).
scale
=
1.2
cc
.
find
(
`JJ_Video_01/Controls`
).
scale
=
1.2
cc
.
find
(
`JJ_Video_01/Controls`
).
y
=-
570
cc
.
find
(
`JJ_Video_01/Controls`
).
x
+=
50
this
.
videoPlayIndex
=
0
this
.
videoItemList
[
0
].
emit
(
'
my_item_click
'
);
}
});
if
(
window
.
CustomEvent
)
{
window
.
dispatchEvent
(
new
CustomEvent
(
'
resize
'
));
}
this
.
initListener
();
}
updateBarByPos
(
newX
:
number
)
{
const
maxX
=
this
.
ProgressBar
.
width
;
const
minX
=
0
;
let
percent
=
newX
/
maxX
;
if
(
percent
>
1
)
{
percent
=
1
;
}
const
dur
=
this
.
videoPlayer
.
getDuration
();
this
.
videoPlayer
.
currentTime
=
percent
*
dur
;
}
updateBarByTime
(
ct
:
number
)
{
if
(
this
.
_isPlayComplated
)
{
return
;
}
this
.
currentTimeLabel
.
string
=
this
.
formatTime
(
ct
);
const
dur
=
this
.
videoPlayer
.
getDuration
();
let
percent
=
ct
/
dur
;
if
(
percent
>
1
)
{
percent
=
1
;
}
this
.
ProgressBar
.
getComponent
(
cc
.
ProgressBar
).
progress
=
percent
;
const
maxX
=
this
.
ProgressBar
.
width
;
const
minX
=
0
;
let
newX
=
percent
*
maxX
;
newX
=
Math
.
min
(
maxX
,
Math
.
max
(
newX
,
minX
));
this
.
barTag
.
x
=
newX
;
}
formatTime
(
time
:
number
):
string
{
if
(
time
===
undefined
)
{
return
''
;
}
let
hh
:
Number
|
String
=
Math
.
floor
(
time
/
60
/
60
);
if
(
Number
(
hh
)
>
0
)
{
hh
=
`
${
hh
.
toString
().
padStart
(
2
,
'
0
'
)}
:`
;
}
else
{
hh
=
''
;
}
const
mm
=
Math
.
floor
(
time
/
60
).
toString
().
padStart
(
2
,
'
0
'
);
const
ss
=
Math
.
round
(
time
%
60
).
toString
().
padStart
(
2
,
'
0
'
);
return
`
${
hh
}${
mm
}
:
${
ss
}
`
;
}
getData
(
func
:
(
data
:
any
)
=>
void
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
getData
(
func
);
return
;
}
func
(
this
.
getDefaultData
());
}
getDefaultData
()
{
return
defaultData
;
}
play
()
{
if
(
!
this
.
_isReadyToPlay
)
{
return
;
}
const
{
width
,
height
}
=
cc
.
find
(
`JJ_Video_01/bg`
);
cc
.
find
(
`JJ_Video_01/text_tips`
).
active
=
false
;
// cc.find(`JJ_Video_01/bg`).active = false;
cc
.
find
(
`JJ_Video_01/bgwhite`
).
active
=
false
;
cc
.
find
(
`JJ_Video_01/bg_video_shadow`
).
active
=
false
;
const
videoContainer
=
cc
.
find
(
'
JJ_Video_01/video_node
'
);
cc
.
find
(
'
bg
'
,
videoContainer
).
width
=
width
;
cc
.
find
(
'
bg
'
,
videoContainer
).
height
=
height
;
this
.
videoPlayer
.
node
.
x
=
videoContainer
.
x
;
this
.
videoPlayer
.
node
.
y
=
videoContainer
.
y
;
this
.
videoPlayer
.
play
();
}
pause
()
{
this
.
videoPlayer
.
pause
();
}
forward
()
{
}
backward
()
{
}
replay
()
{
this
.
_isPlayComplated
=
false
;
this
.
videoPlayer
.
currentTime
=
0
;
this
.
videoPlayer
.
play
();
}
playLocalAudio
(
audioName
:
string
)
{
cc
.
audioEngine
.
stopAll
();
const
audio
=
cc
.
find
(
`JJ_Video_01/res/audio/
${
audioName
}
`
).
getComponent
(
cc
.
AudioSource
);
cc
.
audioEngine
.
playEffect
(
audio
.
clip
,
false
);
}
time1
:
any
=
null
;
isVideoFull
:
boolean
=
false
;
tempPos
:
any
=
null
;
fullScreen
()
{
if
(
this
.
isVideoFull
)
{
return
;
}
if
(
!
this
.
_isReadyToPlay
)
{
return
;
}
this
.
tempPos
=
{};
console
.
log
(
"
====进入全屏===
"
);
this
.
isVideoFull
=
true
;
this
.
videoPlayer
.
stayOnBottom
=
true
;
cc
.
find
(
`JJ_Video_01/Controls/fullscreen`
).
active
=
!
this
.
isVideoFull
;
cc
.
find
(
`JJ_Video_01/Controls/exitfull`
).
active
=
this
.
isVideoFull
;
cc
.
find
(
`JJ_Video_01/btn_return`
).
active
=
!
this
.
isVideoFull
;
cc
.
find
(
`JJ_Video_01/title`
).
active
=
!
this
.
isVideoFull
;
cc
.
find
(
`JJ_Video_01/bg`
).
active
=
!
this
.
isVideoFull
;
const
videoContainer
=
cc
.
find
(
'
JJ_Video_01/video_node
'
);
this
.
tempPos
.
videoPos
=
{
x
:
videoContainer
.
x
,
y
:
videoContainer
.
y
,
width
:
videoContainer
.
width
,
height
:
videoContainer
.
height
};
videoContainer
.
width
=
this
.
node
.
width
;
videoContainer
.
height
=
this
.
node
.
height
;
videoContainer
.
x
=
0
;
videoContainer
.
y
=
0
;
cc
.
find
(
`JJ_Video_01/videolist`
).
active
=
false
;
const
controls
=
cc
.
find
(
`JJ_Video_01/Controls`
);
const
controlBg
=
cc
.
find
(
`bg_video_bottom`
,
controls
);
this
.
tempPos
.
controlPos
=
{
x
:
controls
.
x
,
y
:
controls
.
y
};
controls
.
x
=
300
;
// qsj
if
(
this
.
data
.
dataArr
.
length
<=
1
){
controls
.
y
=
0
-
this
.
node
.
height
/
2
-
30
;
}
else
{
controls
.
y
=
0
-
this
.
node
.
height
/
2
-
30
;
}
controlBg
.
opacity
=
240
;
controlBg
.
width
=
this
.
node
.
width
;
this
.
videoPlayer
.
node
.
height
=
this
.
node
.
height
;
this
.
videoPlayer
.
node
.
width
=
this
.
node
.
width
;
this
.
videoPlayer
.
node
.
x
=
0
;
this
.
videoPlayer
.
node
.
y
=
0
;
setTimeout
(()
=>
{
this
.
videoPlayer
.
node
.
width
=
Math
.
min
(
this
.
node
.
width
,
this
.
node
.
height
*
16
/
9
);
},
100
);
this
.
time1
=
setTimeout
(()
=>
{
this
.
videoPlayer
.
stayOnBottom
=
false
;
cc
.
find
(
`JJ_Video_01/Controls`
).
active
=
false
;
},
3000
);
}
exitFullScreen
()
{
if
(
!
this
.
isVideoFull
)
{
return
;
}
console
.
log
(
"
====退出全屏===
"
,
this
.
tempPos
);
this
.
isVideoFull
=
false
;
cc
.
find
(
`JJ_Video_01/Controls/fullscreen`
).
active
=
!
this
.
isVideoFull
;
cc
.
find
(
`JJ_Video_01/Controls/exitfull`
).
active
=
this
.
isVideoFull
;
cc
.
find
(
`JJ_Video_01/btn_return`
).
active
=
!
this
.
isVideoFull
;
cc
.
find
(
`JJ_Video_01/title`
).
active
=
!
this
.
isVideoFull
;
cc
.
find
(
`JJ_Video_01/bg`
).
active
=
!
this
.
isVideoFull
;
const
videoContainer
=
cc
.
find
(
'
JJ_Video_01/video_node
'
);
videoContainer
.
width
=
this
.
tempPos
.
videoPos
.
width
;
videoContainer
.
height
=
this
.
tempPos
.
videoPos
.
height
;
videoContainer
.
x
=
this
.
tempPos
.
videoPos
.
x
;
videoContainer
.
y
=
this
.
tempPos
.
videoPos
.
y
;
this
.
videoPlayer
.
node
.
width
=
this
.
tempPos
.
videoPos
.
width
;
this
.
videoPlayer
.
node
.
height
=
this
.
tempPos
.
videoPos
.
height
;
this
.
videoPlayer
.
node
.
x
=
videoContainer
.
x
;
this
.
videoPlayer
.
node
.
y
=
videoContainer
.
y
;
cc
.
find
(
`JJ_Video_01/videolist`
).
active
=
this
.
data
.
dataArr
.
length
>
1
;
const
controls
=
cc
.
find
(
`JJ_Video_01/Controls`
);
const
controlBg
=
cc
.
find
(
`bg_video_bottom`
,
controls
);
controls
.
x
=
this
.
tempPos
.
controlPos
.
x
;
controls
.
y
=
this
.
tempPos
.
controlPos
.
y
;
controlBg
.
opacity
=
255
;
controlBg
.
width
=
1259
;
if
(
this
.
time1
)
{
clearTimeout
(
this
.
time1
);
}
}
onDestroy
()
{
if
(
this
.
time1
)
{
clearTimeout
(
this
.
time1
);
}
}
exitGame
()
{
this
.
data
.
templateName
=
"
JJ_Video_01
"
;
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
exitGame
(
this
.
data
,
true
);
}
else
{
console
.
log
(
"
==触发返回事件==
"
);
}
}
update
(
dt
:
number
)
{
console
.
log
(
"
==VIDEO==
"
,
this
.
node
.
active
);
if
(
!
this
.
_isReadyToPlay
)
{
return
;
}
if
(
this
.
videoPlayer
)
{
const
ct
=
this
.
videoPlayer
.
currentTime
;
if
(
ct
)
{
this
.
updateBarByTime
(
ct
);
}
if
(
this
.
videoPlayer
.
isPlaying
())
{
if
(
this
.
playButton
.
node
.
active
)
{
this
.
playButton
.
node
.
active
=
false
;
this
.
restartButton
.
node
.
active
=
false
;
}
if
(
!
this
.
pauseButton
.
node
.
active
)
{
this
.
pauseButton
.
node
.
active
=
true
;
}
}
else
{
if
(
!
this
.
playButton
.
node
.
active
)
{
this
.
playButton
.
node
.
active
=
true
;
}
if
(
this
.
pauseButton
.
node
.
active
)
{
this
.
pauseButton
.
node
.
active
=
false
;
}
if
(
this
.
restartButton
.
node
.
active
)
{
this
.
playButton
.
node
.
active
=
false
;
}
}
}
}
}
\ No newline at end of file
assets/sn03_playVideo/prefab/JJ_Video_01/Scene/JJ_Video_01.ts.meta
deleted
100644 → 0
View file @
587821a6
{
"ver": "1.0.8",
"uuid": "ed52eb63-fc85-4f55-b5f9-b56aabff79cf",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
assets/sn03_playVideo/prefab/JJ_Video_01/Script.meta
deleted
100644 → 0
View file @
587821a6
{
"ver": "1.1.2",
"uuid": "e0e698b1-03bb-4e00-a907-4be459ef4eeb",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
assets/sn03_playVideo/prefab/JJ_Video_01/Script/defaultData_JJ_Video_01.js
deleted
100644 → 0
View file @
587821a6
export
const
defaultData
=
{
"
dataArr
"
:
[
{
"
title
"
:
"
The Old Man
"
,
"
cover
"
:
"
http://staging-teach.cdn.ireadabc.com/c8abf7383d65bcbdba8f390785cece60.png
"
,
"
video_url
"
:
"
http://staging-teach.cdn.ireadabc.com/c37a3945121274a1f7d95717327539ec.mp4
"
},
{
"
title
"
:
"
Where has my little dog gone
"
,
"
cover
"
:
"
http://staging-teach.cdn.ireadabc.com/f6f4bbef497409fef3c8f1d375893829.png
"
,
"
video_url
"
:
"
http://staging-teach.cdn.ireadabc.com/d9df7ef1ba8d7e20613e83984d2d7b9a.mp4
"
}
]
};
\ No newline at end of file
assets/sn03_playVideo/prefab/JJ_Video_01/Script/defaultData_JJ_Video_01.js.meta
deleted
100644 → 0
View file @
587821a6
{
"ver": "1.0.8",
"uuid": "cf76d7b2-4e91-4e3f-b8ee-06159c3cd83d",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
assets/sn03_playVideo/prefab/JJ_Video_01/Script/util_JJ_Video_01.js
deleted
100644 → 0
View file @
587821a6
export
function
getPosByAngle
(
angle
,
len
)
{
const
radian
=
angle
*
Math
.
PI
/
180
;
const
x
=
Math
.
sin
(
radian
)
*
len
;
const
y
=
Math
.
cos
(
radian
)
*
len
;
return
{
x
,
y
};
}
export
function
getAngleByPos
(
px
,
py
,
mx
,
my
)
{
const
x
=
Math
.
abs
(
px
-
mx
);
const
y
=
Math
.
abs
(
py
-
my
);
const
z
=
Math
.
sqrt
(
Math
.
pow
(
x
,
2
)
+
Math
.
pow
(
y
,
2
));
const
cos
=
y
/
z
;
const
radina
=
Math
.
acos
(
cos
);
// 用反三角函数求弧度
let
angle
=
Math
.
floor
(
180
/
(
Math
.
PI
/
radina
)
*
100
)
/
100
;
// 将弧度转换成角度
if
(
mx
>
px
&&
my
>
py
)
{
// 鼠标在第四象限
angle
=
180
-
angle
;
}
if
(
mx
===
px
&&
my
>
py
)
{
// 鼠标在y轴负方向上
angle
=
180
;
}
if
(
mx
>
px
&&
my
===
py
)
{
// 鼠标在x轴正方向上
angle
=
90
;
}
if
(
mx
<
px
&&
my
>
py
)
{
// 鼠标在第三象限
angle
=
180
+
angle
;
}
if
(
mx
<
px
&&
my
===
py
)
{
// 鼠标在x轴负方向
angle
=
270
;
}
if
(
mx
<
px
&&
my
<
py
)
{
// 鼠标在第二象限
angle
=
360
-
angle
;
}
// console.log('angle: ', angle);
return
angle
;
}
export
function
exchangeNodePos
(
baseNode
,
targetNode
)
{
return
baseNode
.
convertToNodeSpaceAR
(
targetNode
.
_parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
)));
}
export
function
RandomInt
(
a
,
b
=
0
)
{
let
max
=
Math
.
max
(
a
,
b
);
let
min
=
Math
.
min
(
a
,
b
);
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
)
+
min
);
}
export
function
randomSortByArr
(
arr
)
{
const
newArr
=
[];
const
tmpArr
=
arr
.
concat
();
while
(
tmpArr
.
length
>
0
)
{
const
randomIndex
=
Math
.
floor
(
tmpArr
.
length
*
Math
.
random
());
newArr
.
push
(
tmpArr
[
randomIndex
]);
tmpArr
.
splice
(
randomIndex
,
1
);
}
return
newArr
;
}
export
function
setSprNodeMaxLen
(
sprNode
,
maxW
,
maxH
)
{
const
sx
=
maxW
/
sprNode
.
width
;
const
sy
=
maxH
/
sprNode
.
height
;
const
s
=
Math
.
min
(
sx
,
sy
);
sprNode
.
scale
=
Math
.
round
(
s
*
1000
)
/
1000
;
}
export
function
localPosTolocalPos
(
baseNode
,
targetNode
)
{
const
worldPos
=
targetNode
.
parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
));
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
}
export
function
worldPosToLocalPos
(
worldPos
,
baseNode
)
{
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
}
export
function
getScaleRateBy2Node
(
baseNode
,
targetNode
,
maxFlag
=
true
)
{
const
worldRect1
=
targetNode
.
getBoundingBoxToWorld
();
const
worldRect2
=
baseNode
.
getBoundingBoxToWorld
();
const
sx
=
worldRect1
.
width
/
worldRect2
.
width
;
const
sy
=
worldRect1
.
height
/
worldRect2
.
height
;
if
(
maxFlag
)
{
return
Math
.
max
(
sx
,
sy
);
}
else
{
return
Math
.
min
(
sx
,
sy
);
}
}
export
function
getDistance
(
start
,
end
)
{
var
pos
=
cc
.
v2
(
start
.
x
-
end
.
x
,
start
.
y
-
end
.
y
);
var
dis
=
Math
.
sqrt
(
pos
.
x
*
pos
.
x
+
pos
.
y
*
pos
.
y
);
return
dis
;
}
export
function
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
if
(
audio_url
)
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
();
});
}
});
}
}
export
function
btnClickAnima
(
btn
,
time
=
0.15
,
rate
=
1.05
)
{
btn
.
tmpScale
=
btn
.
scale
;
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
scale
*
rate
})
.
start
()
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
()
=>
{
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
()
=>
{
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
})
}
export
function
setNetImg
(
item
,
res
,
{
w
,
h
},
custom
=
true
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
item
)
return
console
.
warn
(
"
图片更换失败,传入了错误的item
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
res
)
{
if
(
node
)
node
.
active
=
false
;
return
console
.
warn
(
"
图片更换失败,传入了错误的res
"
);
}
if
(
!
node
)
return
console
.
warn
(
"
图片更换失败,传入了错误的item
"
);
if
(
node
.
net_url
==
res
)
return
;
node
.
active
=
false
;
//
cc
.
loader
.
load
({
url
:
res
},
(
err
,
texture
)
=>
{
if
(
err
&&
!
texture
)
return
resolve
(
console
.
warn
(
'
loading loadRes warn->
'
+
texture
));
if
(
!
cc
.
isValid
(
node
))
return
console
.
info
(
"
节点已销毁
"
);
let
nw
=
node
.
width
=
texture
.
width
;
let
nh
=
node
.
height
=
texture
.
height
;
let
component
=
node
.
getComponent
(
cc
.
Sprite
);
let
spriteFrame
=
new
cc
.
SpriteFrame
(
texture
);
component
.
spriteFrame
=
spriteFrame
;
node
.
net_url
=
res
;
if
(
!
cc
.
isValid
(
node
))
return
console
.
info
(
"
节点已销毁
"
);
if
(
!
node
)
return
console
.
warn
(
"
节点已销毁
"
);
if
(
w
&&
h
&&
custom
)
{
let
scaleX
=
w
/
nw
;
let
scaleY
=
h
/
nh
;
let
scale
=
scaleX
<=
scaleY
?
scaleX
:
scaleY
;
node
.
width
=
nw
*
scale
;
node
.
height
=
nh
*
scale
;
}
node
.
active
=
true
;
resolve
({
w
:
nw
,
h
:
nh
});
});
})
}
export
function
getSpriteFrimeByUrl
(
url
,
cb
)
{
cc
.
loader
.
load
({
url
},
(
err
,
img
)
=>
{
const
spriteFrame
=
new
cc
.
SpriteFrame
(
img
)
if
(
cb
)
{
cb
(
spriteFrame
);
}
})
}
export
function
getSprNode
(
resName
)
{
const
sf
=
cc
.
find
(
'
Canvas/res/img/
'
+
resName
).
getComponent
(
cc
.
Sprite
).
spriteFrame
;
const
node
=
new
cc
.
Node
();
node
.
addComponent
(
cc
.
Sprite
).
spriteFrame
=
sf
;
return
node
;
}
export
function
getSprNodeByUrl
(
url
,
cb
)
{
const
node
=
new
cc
.
Node
();
const
spr
=
node
.
addComponent
(
cc
.
Sprite
);
getSpriteFrimeByUrl
(
url
,
(
sf
)
=>
{
spr
.
spriteFrame
=
sf
;
if
(
cb
)
{
cb
(
spr
);
}
})
}
export
function
playAudio
(
audioClip
,
cb
=
null
)
{
if
(
audioClip
)
{
const
audioId
=
cc
.
audioEngine
.
playEffect
(
audioClip
,
false
);
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
();
});
}
}
}
export
async
function
asyncDelay
(
time
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
cc
.
tween
(
cc
.
find
(
'
Canvas
'
))
.
delay
(
time
)
.
call
(()
=>
{
resolve
(
null
);
})
.
start
();
}
catch
(
e
)
{
reject
(
e
);
}
})
}
export
async
function
asyncLoadDragonBoneAnime
(
node
,
{
skeJsonData
:
{
url
:
skeJsonDataUrl
},
texJsonData
:
{
url
:
texJsonDataUrl
},
texPngData
:
{
url
:
texPngDataUrl
}
})
{
if
(
!
texPngDataUrl
||
!
texJsonDataUrl
||
!
texPngDataUrl
||
texPngDataUrl
==
''
||
texJsonDataUrl
==
''
||
texPngDataUrl
==
''
)
{
return
;
}
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
node
.
animaNode
)
{
node
.
animaNode
.
removeFromParent
();
}
const
animaNode
=
new
cc
.
Node
();
animaNode
.
name
=
'
animaNode
'
;
animaNode
.
parent
=
node
;
animaNode
.
active
=
true
;
node
.
animaNode
=
animaNode
;
const
dragonDisplay
=
animaNode
.
addComponent
(
dragonBones
.
ArmatureDisplay
);
const
loadTexture
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
texPngDataUrl
,
(
error
,
texture
)
=>
{
if
(
error
)
{
reject
(
error
);
}
resolve
(
texture
);
});
});
const
loadTexJsonData
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
texJsonDataUrl
,
(
error
,
atlasJson
)
=>
{
if
(
error
)
{
reject
(
error
);
}
resolve
(
atlasJson
);
});
});
const
loadSkeJsonData
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
skeJsonDataUrl
,
(
error
,
dragonBonesJson
)
=>
{
if
(
error
)
{
reject
(
error
);
}
resolve
(
dragonBonesJson
);
});
});
Promise
.
all
([
loadTexture
,
loadTexJsonData
,
loadSkeJsonData
]).
then
(([
texture
,
atlasJson
,
dragonBonesJson
])
=>
{
const
atlas
=
new
dragonBones
.
DragonBonesAtlasAsset
();
atlas
.
atlasJson
=
JSON
.
stringify
(
atlasJson
.
json
);
atlas
.
texture
=
texture
;
const
asset
=
new
dragonBones
.
DragonBonesAsset
();
asset
.
dragonBonesJson
=
JSON
.
stringify
(
dragonBonesJson
.
json
);
dragonDisplay
.
dragonAtlasAsset
=
atlas
;
dragonDisplay
.
dragonAsset
=
asset
;
//设置
let
defaultArmature
=
dragonBonesJson
.
json
.
armature
[
0
];
//aramture 所有的骨骼名称
dragonDisplay
.
armatureName
=
defaultArmature
.
name
;
resolve
(
animaNode
);
});
});
}
export
class
FireworkSettings
{
baseNode
;
// 父节点
nodeList
;
// 火花节点的array
pos
;
// 发射点
side
;
// 发射方向
range
;
// 扩散范围
number
;
// 发射数量
scalseRange
;
// 缩放范围
constructor
(
baseNode
,
nodeList
,
pos
=
cc
.
v2
(
0
,
0
),
side
=
cc
.
v2
(
0
,
100
),
range
=
50
,
number
=
100
,
scalseRange
=
0
)
{
this
.
baseNode
=
baseNode
;
this
.
nodeList
=
nodeList
;
this
.
pos
=
pos
;
this
.
side
=
side
;
this
.
range
=
range
;
this
.
number
=
number
;
this
.
scalseRange
=
scalseRange
;
}
static
copy
(
firework
)
{
return
new
FireworkSettings
(
firework
.
baseNode
,
firework
.
nodeList
,
firework
.
pos
,
firework
.
side
,
firework
.
range
,
firework
.
number
,
);
}
}
export
async
function
showFireworks
(
fireworkSettings
)
{
const
{
baseNode
,
nodeList
,
pos
,
side
,
range
,
number
,
scalseRange
}
=
fireworkSettings
;
new
Array
(
number
).
fill
(
'
'
).
forEach
(
async
(
_
,
i
)
=>
{
let
rabbonNode
=
new
cc
.
Node
();
rabbonNode
.
parent
=
baseNode
;
rabbonNode
.
x
=
pos
.
x
;
rabbonNode
.
y
=
pos
.
y
;
rabbonNode
.
angle
=
60
*
Math
.
random
()
-
30
;
let
node
=
cc
.
instantiate
(
nodeList
[
RandomInt
(
nodeList
.
length
)]);
node
.
parent
=
rabbonNode
;
node
.
active
=
true
;
node
.
x
=
0
;
node
.
y
=
0
;
node
.
angle
=
0
;
node
.
scale
=
(
Math
.
random
()
-
0.5
)
*
scalseRange
+
1
;
const
rate
=
Math
.
random
();
const
angle
=
Math
.
PI
*
(
Math
.
random
()
*
2
-
1
);
await
asyncTweenBy
(
rabbonNode
,
0.3
,
{
x
:
side
.
x
*
rate
+
Math
.
cos
(
angle
)
*
range
*
rate
,
y
:
side
.
y
*
rate
+
Math
.
sin
(
angle
)
*
range
*
rate
},
{
easing
:
'
quadIn
'
});
cc
.
tween
(
rabbonNode
)
.
by
(
8
,
{
y
:
-
2000
})
.
start
();
cc
.
tween
(
rabbonNode
)
.
to
(
5
,
{
scale
:
(
Math
.
random
()
-
0.5
)
*
scalseRange
+
1
})
.
start
();
rabbonFall
(
rabbonNode
);
await
asyncDelay
(
Math
.
random
());
cc
.
tween
(
node
)
.
by
(
0.15
,
{
x
:
-
10
,
angle
:
-
10
})
.
by
(
0.3
,
{
x
:
20
,
angle
:
20
})
.
by
(
0.15
,
{
x
:
-
10
,
angle
:
-
10
})
.
union
()
.
repeatForever
()
.
start
();
cc
.
tween
(
rabbonNode
)
.
delay
(
5
)
.
to
(
0.3
,
{
opacity
:
0
})
.
call
(()
=>
{
node
.
stopAllActions
();
node
.
active
=
false
;
node
.
parent
=
null
;
node
=
null
;
})
.
start
();
});
}
async
function
rabbonFall
(
node
)
{
const
time
=
1
+
Math
.
random
();
const
offsetX
=
RandomInt
(
-
200
,
200
)
*
time
;
await
asyncTweenBy
(
node
,
time
,
{
x
:
offsetX
,
angle
:
offsetX
*
60
/
200
});
rabbonFall
(
node
);
}
export
async
function
asyncTweenTo
(
node
,
duration
,
obj
,
ease
=
undefined
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
cc
.
tween
(
node
)
.
to
(
duration
,
obj
,
ease
)
.
call
(()
=>
{
resolve
(
null
);
})
.
start
();
}
catch
(
e
)
{
reject
(
e
);
}
});
}
export
async
function
asyncTweenBy
(
node
,
duration
,
obj
,
ease
=
undefined
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
cc
.
tween
(
node
)
.
by
(
duration
,
obj
,
ease
)
.
call
(()
=>
{
resolve
(
null
);
})
.
start
();
}
catch
(
e
)
{
reject
(
e
);
}
});
}
export
function
showTrebleFirework
(
baseNode
,
rabbonList
)
{
const
middle
=
new
FireworkSettings
(
baseNode
,
rabbonList
);
middle
.
pos
=
cc
.
v2
(
0
,
-
400
);
middle
.
side
=
cc
.
v2
(
0
,
1000
);
middle
.
range
=
200
;
middle
.
number
=
100
;
middle
.
scalseRange
=
0.4
;
const
left
=
FireworkSettings
.
copy
(
middle
);
left
.
pos
=
cc
.
v2
(
-
600
,
-
400
);
left
.
side
=
cc
.
v2
(
200
,
1000
);
const
right
=
FireworkSettings
.
copy
(
middle
);
right
.
pos
=
cc
.
v2
(
600
,
-
400
);
right
.
side
=
cc
.
v2
(
-
200
,
1000
);
showFireworks
(
middle
);
showFireworks
(
left
);
showFireworks
(
right
);
}
export
function
onHomeworkFinish
(
data
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
onHomeworkFinish
(()
=>
{},
data
);
}
else
{
console
.
log
(
'
onHomeworkFinish
'
,
data
);
}
}
export
function
jumpToBundle
(
bundleName
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
loadOnlineBundle
(
bundleName
);
}
else
{
console
.
log
(
'
jump to bundle:
'
+
bundleName
);
}
}
export
function
jumpToLogin
()
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
loadOnlineBundle
(
"
NJ_login
"
);
}
else
{
console
.
log
(
'
jump to bundle: NJ_login
'
);
}
}
export
function
asyncCallNetworkApiGet
(
apiName
,
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
callNetworkApiGet
(
apiName
,
data
,
(
res
=>
{
resolve
(
res
);
}));
});
}
export
function
asyncCallNetworkApiPost
(
uri
,
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
callNetworkApiPost
(
uri
,
data
,
(
res
)
=>
{
resolve
(
res
);
});
});
}
export
function
callNetworkApiPost
(
uri
,
data
,
callBack
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
callNetworkApiPost
(
uri
,
data
,
callBack
);
return
;
}
const
baseUrl
=
'
http://staging-openapi.iteachabc.com
'
;
const
xhr
=
new
XMLHttpRequest
();
const
url
=
`
${
baseUrl
}${
uri
}
`
;
xhr
.
open
(
"
POST
"
,
url
,
true
);
xhr
.
setRequestHeader
(
'
content-type
'
,
'
application/json
'
);
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
)
{
callBack
(
JSON
.
parse
(
xhr
.
responseText
));
}
}
xhr
.
send
(
JSON
.
stringify
(
data
));
}
export
function
callNetworkApiGet
(
uri
,
data
,
callBack
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
callNetworkApiGet
(
uri
,
data
,
callBack
);
return
;
}
const
baseUrl
=
'
http://staging-openapi.iteachabc.com
'
;
let
queryStr
=
'
?
'
;
const
params
=
[];
for
(
const
key
in
data
)
{
if
(
Object
.
hasOwnProperty
.
call
(
data
,
key
))
{
params
.
push
(
`
${
key
}
=
${
data
[
key
]}
`
);
}
}
queryStr
+=
params
.
join
(
"
&
"
);
const
xhr
=
new
XMLHttpRequest
();
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callBack
(
xhr
.
responseText
);
}
};
const
url
=
`
${
baseUrl
}${
uri
}${
queryStr
}
`
;
console
.
log
(
'
url =
'
+
url
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
send
();
}
function
httpHeadCall
(
requsetUrl
,
callback
)
{
let
xhr
=
new
XMLHttpRequest
();
console
.
log
(
"
Status: Send Post Request to
"
+
requsetUrl
);
try
{
xhr
.
onreadystatechange
=
()
=>
{
try
{
console
.
log
(
'
xhr.readyState:
'
,
xhr
.
readyState
);
if
(
xhr
.
readyState
==
4
)
{
if
((
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callback
(
true
);
}
else
{
callback
(
false
);
}
}
}
catch
(
e
)
{
console
.
log
(
e
)
}
};
xhr
.
open
(
"
HEAD
"
,
requsetUrl
,
true
);
xhr
.
send
();
xhr
.
timeout
=
15000
;
xhr
.
onerror
=
(
e
)
=>
{
console
.
log
(
"
汪汪汪 posterror
"
,
e
);
callback
(
false
);
};
xhr
.
ontimeout
=
(
e
)
=>
{
console
.
log
(
"
汪汪汪 ontimeout
"
,
e
);
callback
(
false
);
};
}
catch
(
e
)
{
console
.
log
(
"
Send Get Request error:
"
,
e
)
}
};
export
function
getVideoUrl
(
video_url
,
callback
)
{
const
url1
=
video_url
;
const
url2
=
url1
.
replace
(
/.mp4$/g
,
"
_l.mp4
"
);
httpHeadCall
(
url2
,
(
success
)
=>
{
if
(
success
)
{
console
.
log
(
'
return url2:
'
,
url2
);
callback
(
url2
);
}
else
{
console
.
log
(
'
return url1:
'
,
url1
);
callback
(
url1
);
}
})
};
export
function
buttonOnceClick
(
button
,
callback
,
scale
=
1.0
)
{
button
.
addComponent
(
cc
.
Button
);
const
func
=
()
=>
{
if
(
button
[
'
cantClick
'
])
{
return
;
}
button
[
'
cantClick
'
]
=
true
;
cc
.
tween
(
button
)
.
to
(
0.1
,
{
scale
:
scale
*
1.1
})
.
to
(
0.1
,
{
scale
:
scale
})
.
call
(()
=>
{
button
[
'
cantClick
'
]
=
false
;
callback
&&
callback
();
})
.
start
();
}
button
.
off
(
'
click
'
);
button
.
once
(
'
click
'
,
func
);
}
export
function
buttonOnClick
(
button
,
callback
,
scale
=
1.0
)
{
button
.
on
(
'
click
'
,
()
=>
{
if
(
button
[
'
cantClick
'
])
{
return
;
}
button
[
'
cantClick
'
]
=
true
;
callback
&&
callback
();
button
[
'
cantClick
'
]
=
false
;
});
}
export
function
asyncGetSpriteFrimeByUrl
(
url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
loader
.
load
({
url
},
(
err
,
img
)
=>
{
if
(
err
)
{
reject
(
err
);
return
;
}
const
spriteFrame
=
new
cc
.
SpriteFrame
(
img
)
resolve
(
spriteFrame
);
})
});
}
\ No newline at end of file
assets/sn03_playVideo/prefab/JJ_Video_01/Script/util_JJ_Video_01.js.meta
deleted
100644 → 0
View file @
587821a6
{
"ver": "1.0.8",
"uuid": "d950c9d5-2271-41d2-a2f6-37b3cf9d569b",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment