-
Notifications
You must be signed in to change notification settings - Fork 13
/
NetworkObjectManager.js
47 lines (37 loc) · 1.01 KB
/
NetworkObjectManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const UnityInstance = require('./UnityInstance');
let m_NetworkObjects = [];
function getObjects() {
return m_NetworkObjects;
}
function addObject(uInstance) {
if (!(uInstance instanceof UnityInstance)) {
throw new Error('Only Unity Instance can be added.');
}
m_NetworkObjects.push(uInstance);
}
function removeObject(uInstance) {
if (!(uInstance instanceof UnityInstance)) {
throw new Error('Only Unity Instance can be added.');
}
m_NetworkObjects.splice(m_NetworkObjects.indexOf(uInstance), 1);
}
/**
* Remove NetworkObject by ClientID
* @param {int} clientID
*/
function removeObjectByClientID(clientID) {
const newList = [];
for(let i = 0; i < m_NetworkObjects.length; i++) {
const networkObject = m_NetworkObjects[i];
if(networkObject.clientID !== clientID) {
newList.push(networkObject);
}
}
m_NetworkObjects = newList;
}
module.exports = {
getObjects,
addObject,
removeObject,
removeObjectByClientID,
};