Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
op_16
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
op_16
Commits
0d49d541
Commit
0d49d541
authored
Jun 20, 2022
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
parent
fe3c99e7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
58 deletions
+19
-58
NetworkHelper.ts
assets/op_16/script/NetworkHelper.ts
+19
-58
No files found.
assets/op_16/script/NetworkHelper.ts
View file @
0d49d541
...
...
@@ -77,27 +77,28 @@ export class NetworkHelper {
console
.
log
(
'
加入房间成功 room =
'
,
room
);
const
playerMe
=
room
.
playerList
.
find
(
player
=>
player
.
isLocal
);
const
masterPlayer
=
room
.
playerList
.
find
(
player
=>
player
.
isMaster
);
const
masterId
=
masterPlayer
.
userId
const
masterId
=
masterPlayer
.
userId
;
const
playerId
=
playerMe
.
userId
;
this
.
room
=
new
FakeRoom
(
masterId
);
this
.
room
.
players
.
push
(
this
.
room
.
player
);
this
.
player
=
this
.
room
.
player
;
this
.
client
.
on
(
globalThis
.
Play
.
Event
.
PLAYER_ROOM_LEFT
,
(
event
)
=>
{
this
.
room
.
on
(
'
Leave
'
,
event
);
this
.
onLeaveRoom
({
data
:
{
leavePlayerId
:
event
.
leftPlayer
.
userId
}
}
);
});
this
.
room
.
onJoin
(
this
.
onJoinRoom
.
bind
(
this
)
);
this
.
room
.
onLeave
(
this
.
onLeaveRoom
.
bind
(
this
)
);
this
.
room
.
onStartFrameSync
(
this
.
onStartFrameSync
.
bind
(
this
));
this
.
room
.
onStopFrameSync
(
this
.
onStopFrameSync
.
bind
(
this
)
);
this
.
room
.
onRecvFrame
(
this
.
onRecvFrame
.
bind
(
this
)
);
this
.
room
.
onDisconnect
(
this
.
onDisconnect
.
bind
(
this
));
this
.
room
.
onDismiss
(
this
.
onDisconnect
.
bind
(
this
));
this
.
client
.
on
(
globalThis
.
Play
.
Event
.
PLAYER_ROOM_JOINED
,
(
event
)
=>
{
this
.
onJoinRoom
({
playerId
:
event
.
newPlayer
.
userId
}
);
}
);
this
.
client
.
on
(
globalThis
.
Play
.
Event
.
CUSTOM_EVENT
,
(
event
)
=>
{
this
.
onRecvFrame
({
data
:
event
.
eventData
}
);
}
);
//
this.room.onDisconnect(this.onDisconnect.bind(this));
//
this.room.onDismiss(this.onDisconnect.bind(this));
return
playerId
;
}
async
leaveRoom
()
{
await
this
.
client
.
close
();
console
.
log
(
"
退房成功
"
);
}
...
...
@@ -108,7 +109,11 @@ export class NetworkHelper {
}
async
closeRoom
()
{
// 设置房间不可见
await
this
.
client
.
setRoomVisible
(
false
);
console
.
log
(
this
.
client
.
room
.
visible
);
}
async
startFrameSync
()
{
console
.
log
(
"
开始帧同步成功
"
);
}
...
...
@@ -118,14 +123,16 @@ export class NetworkHelper {
}
sendFrame
(
data
:
any
)
{
this
.
onRecvFrame
({
data
});
this
.
client
.
sendEvent
(
0
,
data
,
{
receiverGroup
:
globalThis
.
Play
.
ReceiverGroup
.
All
,
});
}
onJoinRoom
(
event
)
{
console
.
log
(
"
新玩家加入
"
,
event
);
if
(
this
.
_eventListeners
[
"
playerJoin
"
])
{
this
.
_eventListeners
[
"
playerJoin
"
](
event
);
}
console
.
log
(
"
新玩家加入
"
,
JSON
.
stringify
(
event
));
this
.
room
.
players
.
forEach
(
player
=>
{
console
.
log
(
'
player.playerId =
'
,
player
.
playerId
);
});
...
...
@@ -224,50 +231,4 @@ class FakeRoom {
this
.
player
=
{
playerId
:
playerId
};
this
.
ownerId
=
playerId
;
}
on
(
event
,
data
)
{
const
eventNameList
=
[
'
Leave
'
,
'
StartFrameSync
'
,
'
StopFrameSync
'
,
'
RecvFrame
'
,
'
Disconnect
'
,
'
Dismiss
'
,
];
eventNameList
.
forEach
(
eventName
=>
{
if
(
event
==
eventName
)
{
const
func
=
this
[
`_on
${
event
}
`
];
func
&&
func
(
data
);
}
});
}
_onJoin
;
onJoin
(
func
:
Function
)
{
this
.
_onJoin
=
func
;
}
_onLeave
;
onLeave
(
func
:
Function
)
{
this
.
_onLeave
=
func
;
}
_onStartFrameSync
;
onStartFrameSync
(
func
:
Function
)
{
this
.
_onStartFrameSync
=
func
;
}
_onStopFrameSync
;
onStopFrameSync
(
func
:
Function
)
{
this
.
_onStopFrameSync
=
func
;
}
_onRecvFrame
;
onRecvFrame
(
func
:
Function
)
{
this
.
_onRecvFrame
=
func
;
}
_onDisconnect
;
onDisconnect
(
func
:
Function
)
{
this
.
_onDisconnect
=
func
;
}
_onDismiss
;
onDismiss
(
func
:
Function
)
{
this
.
_onDismiss
=
func
;
}
}
\ 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