4.x syntax

This commit is contained in:
Paul Pacheco 2019-01-30 07:55:34 -06:00
parent 7d081da541
commit 138dfaa6e1

View File

@ -19,9 +19,9 @@ public static class NetworkServer
// original HLAPI has .localConnections list with only m_LocalConnection in it // original HLAPI has .localConnections list with only m_LocalConnection in it
// (for downwards compatibility because they removed the real localConnections list a while ago) // (for downwards compatibility because they removed the real localConnections list a while ago)
// => removed it for easier code. use .localConection now! // => removed it for easier code. use .localConection now!
public static NetworkConnection localConnection { get { return s_LocalConnection; } } public static NetworkConnection localConnection => s_LocalConnection;
public static int serverHostId { get { return s_ServerHostId; } } public static int serverHostId => s_ServerHostId;
// <connectionId, NetworkConnection> // <connectionId, NetworkConnection>
public static Dictionary<int, NetworkConnection> connections = new Dictionary<int, NetworkConnection>(); public static Dictionary<int, NetworkConnection> connections = new Dictionary<int, NetworkConnection>();
@ -29,8 +29,8 @@ public static class NetworkServer
public static bool dontListen; public static bool dontListen;
public static bool active { get { return s_Active; } } public static bool active => s_Active;
public static bool localClientActive { get { return s_LocalClientActive; } } public static bool localClientActive => s_LocalClientActive;
public static void Reset() public static void Reset()
{ {
@ -141,8 +141,10 @@ internal static int AddLocalClient(LocalClient localClient)
return -1; return -1;
} }
s_LocalConnection = new ULocalConnectionToClient(localClient); s_LocalConnection = new ULocalConnectionToClient(localClient)
s_LocalConnection.connectionId = 0; {
connectionId = 0
};
AddConnection(s_LocalConnection); AddConnection(s_LocalConnection);
s_LocalConnection.InvokeHandlerNoData((short)MsgType.Connect); s_LocalConnection.InvokeHandlerNoData((short)MsgType.Connect);
@ -412,8 +414,10 @@ static void GenerateError(NetworkConnection conn, byte error)
{ {
if (handlers.ContainsKey((short)MsgType.Error)) if (handlers.ContainsKey((short)MsgType.Error))
{ {
ErrorMessage msg = new ErrorMessage(); ErrorMessage msg = new ErrorMessage
msg.value = error; {
value = error
};
// write the message to a local buffer // write the message to a local buffer
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
@ -589,8 +593,10 @@ static void FinishPlayerForConnection(NetworkConnection conn, NetworkIdentity id
Spawn(playerGameObject); Spawn(playerGameObject);
} }
OwnerMessage owner = new OwnerMessage(); OwnerMessage owner = new OwnerMessage
owner.netId = identity.netId; {
netId = identity.netId
};
conn.Send((short)MsgType.Owner, owner); conn.Send((short)MsgType.Owner, owner);
} }
@ -732,8 +738,10 @@ internal static void ShowForConnection(NetworkIdentity identity, NetworkConnecti
internal static void HideForConnection(NetworkIdentity identity, NetworkConnection conn) internal static void HideForConnection(NetworkIdentity identity, NetworkConnection conn)
{ {
ObjectDestroyMessage msg = new ObjectDestroyMessage(); ObjectDestroyMessage msg = new ObjectDestroyMessage
msg.netId = identity.netId; {
netId = identity.netId
};
conn.Send((short)MsgType.ObjectHide, msg); conn.Send((short)MsgType.ObjectHide, msg);
} }
@ -848,14 +856,16 @@ internal static void SendSpawnMessage(NetworkIdentity identity, NetworkConnectio
// 'identity' is a prefab that should be spawned // 'identity' is a prefab that should be spawned
if (identity.sceneId == 0) if (identity.sceneId == 0)
{ {
SpawnPrefabMessage msg = new SpawnPrefabMessage(); SpawnPrefabMessage msg = new SpawnPrefabMessage
msg.netId = identity.netId; {
msg.assetId = identity.assetId; netId = identity.netId,
msg.position = identity.transform.position; assetId = identity.assetId,
msg.rotation = identity.transform.rotation; position = identity.transform.position,
rotation = identity.transform.rotation,
// serialize all components with initialState = true // serialize all components with initialState = true
msg.payload = identity.OnSerializeAllSafely(true); payload = identity.OnSerializeAllSafely(true)
};
// conn is != null when spawning it for a client // conn is != null when spawning it for a client
if (conn != null) if (conn != null)
@ -871,14 +881,16 @@ internal static void SendSpawnMessage(NetworkIdentity identity, NetworkConnectio
// 'identity' is a scene object that should be spawned again // 'identity' is a scene object that should be spawned again
else else
{ {
SpawnSceneObjectMessage msg = new SpawnSceneObjectMessage(); SpawnSceneObjectMessage msg = new SpawnSceneObjectMessage
msg.netId = identity.netId; {
msg.sceneId = identity.sceneId; netId = identity.netId,
msg.position = identity.transform.position; sceneId = identity.sceneId,
msg.rotation = identity.transform.rotation; position = identity.transform.position,
rotation = identity.transform.rotation,
// include synch data // include synch data
msg.payload = identity.OnSerializeAllSafely(true); payload = identity.OnSerializeAllSafely(true)
};
// conn is != null when spawning it for a client // conn is != null when spawning it for a client
if (conn != null) if (conn != null)
@ -1031,8 +1043,10 @@ static void DestroyObject(NetworkIdentity identity, bool destroyServerObject)
identity.clientAuthorityOwner.RemoveOwnedObject(identity); identity.clientAuthorityOwner.RemoveOwnedObject(identity);
} }
ObjectDestroyMessage msg = new ObjectDestroyMessage(); ObjectDestroyMessage msg = new ObjectDestroyMessage
msg.netId = identity.netId; {
netId = identity.netId
};
SendToObservers(identity, (short)MsgType.ObjectDestroy, msg); SendToObservers(identity, (short)MsgType.ObjectDestroy, msg);
identity.ClearObservers(); identity.ClearObservers();