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
a4b14eb4
Commit
a4b14eb4
authored
Jul 08, 2022
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 删除无用的文件
parent
1c30ea24
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
207 deletions
+0
-207
NetworkHelper2.ts
assets/op_16/script/NetworkHelper2.ts
+0
-198
NetworkHelper2.ts.meta
assets/op_16/script/NetworkHelper2.ts.meta
+0
-9
No files found.
assets/op_16/script/NetworkHelper2.ts
deleted
100644 → 0
View file @
1c30ea24
export
class
NetworkHelper
{
_eventListeners
:
any
=
{};
ctor
()
{
}
on
(
eventName
,
func
)
{
this
.
_eventListeners
[
eventName
]
=
func
;
}
async
init
(
roomType
:
string
,
maxPlayers
:
number
)
{
await
this
.
initRoom
();
return
await
this
.
joinRoom
(
roomType
,
maxPlayers
);
}
async
startGame
()
{
await
this
.
startFrameSync
();
await
this
.
closeRoom
();
}
async
stopGame
()
{
await
this
.
stopFrameSync
();
await
this
.
closeRoom
();
await
this
.
leaveRoom
();
}
listenerInited
=
false
;
room
:
any
;
client
:
any
;
async
initRoom
()
{
this
.
client
=
new
(
<
any
>
(
window
)).
GOBE
.
Client
({
clientId
:
'
857970243220294656
'
,
// 客户端ID
clientSecret
:
'
489BFFB5D22BC39FDA0B1878F01F38C8049EBF68C856E25E63E7403A723A140D
'
,
// 客户端密钥
appId
:
'
105879509
'
,
// 应用的ID
openId
:
'
op_16
'
+
Math
.
random
(),
// 玩家ID
});
await
this
.
client
.
init
();
}
player
:
any
;
async
joinRoom
(
roomType
:
string
,
maxPlayers
:
number
)
{
const
matchRoomConfig
=
{
matchParams
:
{
param1
:
'
param1
'
,
},
roomType
:
roomType
,
maxPlayers
:
maxPlayers
,
};
this
.
room
=
await
this
.
client
.
matchRoom
(
matchRoomConfig
);
this
.
player
=
this
.
room
.
player
;
console
.
log
(
'
汪汪汪:
'
+
this
.
room
.
players
.
length
);
await
this
.
startFrameSync
();
console
.
log
(
'
汪汪汪2
'
);
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
));
return
this
.
player
.
playerId
;
}
async
leaveRoom
()
{
await
this
.
room
.
leave
();
console
.
log
(
"
退房成功
"
);
}
async
dismissRoom
()
{
if
(
this
.
room
.
ownerId
==
this
.
player
.
id
)
{
await
this
.
client
.
dismissRoom
();
console
.
log
(
"
房间已解散
"
);
}
}
async
closeRoom
()
{
await
this
.
client
.
cancelMatch
();
}
async
startFrameSync
()
{
await
this
.
room
.
startFrameSync
();
// return new Promise((resolve, reject) => {
// this.room.onStartFrameSync(() => {
// cc.log("开始帧同步成功,请到控制台查看具体帧同步信息");
// resolve(null);
// });
// });
}
async
stopFrameSync
()
{
await
this
.
room
.
stopFrameSync
();
console
.
log
(
"
停止帧同步成功
"
);
}
sendFrame
(
data
:
any
)
{
console
.
warn
(
'
sendFrame:
'
+
JSON
.
stringify
(
data
));
if
(
this
.
room
.
_isSyncing
)
{
this
.
room
.
sendFrame
(
JSON
.
stringify
(
data
));
}
else
{
console
.
log
(
'
is syncing = false
'
);
this
.
onRecvFrame
({
data
});
}
}
onJoinRoom
(
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
);
});
}
onLeaveRoom
(
event
)
{
console
.
log
(
"
onLeaveRoom
"
);
if
(
this
.
_eventListeners
[
"
playerLeave
"
])
{
this
.
_eventListeners
[
"
playerLeave
"
](
event
);
}
console
.
log
(
"
玩家退出
"
,
event
.
data
.
leavePlayerId
);
}
onRecvFromClient
()
{
}
onDisconnect
(
event
)
{
this
.
log
(
"
玩家掉线了:
"
+
JSON
.
stringify
(
event
));
if
(
this
.
_eventListeners
[
"
playerOffLine
"
])
{
this
.
_eventListeners
[
"
playerOffLine
"
](
event
);
}
}
onRecvFrame
(
event
)
{
if
(
this
.
_eventListeners
[
"
frameEvent
"
])
{
this
.
_eventListeners
[
"
frameEvent
"
](
event
);
}
}
onStartFrameSync
(
event
)
{
console
.
log
(
'
onStartFrameSync
'
);
if
(
this
.
_eventListeners
[
"
gameStart
"
])
{
this
.
_eventListeners
[
"
gameStart
"
](
event
);
}
}
onStopFrameSync
(
event
)
{
}
onRecvFromGameSvr
()
{
}
async
onDestroy
()
{
try
{
console
.
log
(
"
onDestroy1
"
);
// MGOBE.Listener.clear();
this
.
stopFrameSync
();
this
.
closeRoom
();
this
.
dismissRoom
();
this
.
leaveRoom
();
console
.
log
(
"
onDestroy2
"
);
}
catch
(
e
)
{
console
.
log
(
JSON
.
stringify
(
e
));
}
}
log
(
str
)
{
const
node
=
cc
.
find
(
"
middleLayer
"
);
if
(
node
)
{
node
.
getComponent
(
"
middleLayer
"
).
log
(
str
);
}
else
{
cc
.
log
(
str
);
}
}
callNetworkApiGet
(
baseUrl
,
uri
,
data
,
callBack
)
{
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
();
}
}
export
function
asyncDelay
(
time
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
tween
(
cc
.
find
(
"
Canvas
"
))
.
delay
(
time
)
.
call
(()
=>
{
resolve
(
null
);
})
.
start
();
});
}
assets/op_16/script/NetworkHelper2.ts.meta
deleted
100644 → 0
View file @
1c30ea24
{
"ver": "1.0.8",
"uuid": "e3b1625a-4a5d-493a-a856-9cce9f53169a",
"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