Skip to content

Commit e477a5a

Browse files
committed
1.1.2
Fixed initial serialization not sending all properties. Fixed many logs without a log filter. Fixed some changes made to the TinyNetGameManagerEditor not being saved.
1 parent ab0688b commit e477a5a

File tree

9 files changed

+56
-36
lines changed

9 files changed

+56
-36
lines changed

Assets/TinyBirdNet/Editor/TinyNetGameManagerEditor.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,43 @@ namespace TinyBirdNet {
88
public class TinyNetGameManagerEditor : Editor {
99

1010
static GUIContent connectKeyLabel = new GUIContent("Connect Key:", "Insert here a unique key per version of your game, if the key mismatches the player will be denied connection.");
11+
static GUIContent networkFramesLabel = new GUIContent("Update Network every X Fixed Frames", "This will change how often the server sends the current state of the game to clients.");
12+
static GUIContent logFilterLabel = new GUIContent("LogFilter:", "Your console will only display logs of this level or higher.");
1113

1214
SerializedProperty _registeredPrefabs;
1315
SerializedProperty _maxNumberOfPlayers;
16+
SerializedProperty _networkEveryXFixedFrames;
17+
SerializedProperty _multiplayerConnectKey;
18+
SerializedProperty _currentLogFilter;
1419

1520
void OnEnable() {
1621
_registeredPrefabs = serializedObject.FindProperty("registeredPrefabs");
22+
1723
_maxNumberOfPlayers = serializedObject.FindProperty("maxNumberOfPlayers");
24+
25+
_networkEveryXFixedFrames = serializedObject.FindProperty("NetworkEveryXFixedFrames");
26+
27+
_multiplayerConnectKey = serializedObject.FindProperty("multiplayerConnectKey");
28+
29+
_currentLogFilter = serializedObject.FindProperty("currentLogFilter");
1830
}
1931

2032
public override void OnInspectorGUI() {
2133
serializedObject.Update();
2234

2335
TinyNetGameManager netGameManager = target as TinyNetGameManager;
2436

25-
EditorGUILayout.LabelField("Update Network every X Fixed Frames");
26-
netGameManager.NetworkEveryXFixedFrames = EditorGUILayout.IntSlider(netGameManager.NetworkEveryXFixedFrames, 1, 60);
37+
//EditorGUILayout.LabelField("Update Network every X Fixed Frames");
38+
EditorGUILayout.LabelField(networkFramesLabel);
39+
EditorGUILayout.PropertyField(_networkEveryXFixedFrames, GUIContent.none);
40+
//netGameManager.NetworkEveryXFixedFrames = EditorGUILayout.IntSlider(netGameManager.NetworkEveryXFixedFrames, 1, 60);
2741

2842
EditorGUILayout.Space();
2943

3044
EditorGUILayout.PropertyField(_maxNumberOfPlayers);
3145

32-
netGameManager.multiplayerConnectKey = EditorGUILayout.TextField(connectKeyLabel, netGameManager.multiplayerConnectKey);
46+
EditorGUILayout.PropertyField(_multiplayerConnectKey, connectKeyLabel);
47+
//netGameManager.multiplayerConnectKey = EditorGUILayout.TextField(connectKeyLabel, netGameManager.multiplayerConnectKey);
3348

3449
EditorGUILayout.Space();
3550

@@ -41,7 +56,8 @@ public override void OnInspectorGUI() {
4156

4257
EditorGUILayout.Space();
4358

44-
netGameManager.currentLogFilter = (LogFilter)EditorGUILayout.EnumPopup("LogFilter:", netGameManager.currentLogFilter);
59+
EditorGUILayout.PropertyField(_currentLogFilter, logFilterLabel);
60+
//netGameManager.currentLogFilter = (LogFilter)EditorGUILayout.EnumPopup("LogFilter:", netGameManager.currentLogFilter);
4561

4662
serializedObject.ApplyModifiedProperties();
4763
}

Assets/TinyBirdNet/Editor/TinyNetScenePostProcessor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEditor;
1+
using TinyBirdUtils;
2+
using UnityEditor;
23
using UnityEditor.Callbacks;
34
using UnityEngine;
45

@@ -15,7 +16,7 @@ public static void OnPostProcessScene() {
1516
// if we had a [ConflictComponent] attribute that would be better than this check.
1617
// also there is no context about which scene this is in.
1718
if (tnis[i].GetComponent<TinyNetGameManager>() != null) {
18-
Debug.LogError("TinyNetGameManager has a TinyNetIdentity component. This will cause the TinyNetGameManager object to be disabled, so it is not recommended.");
19+
if (TinyNetLogLevel.logError) { TinyLogger.LogError("TinyNetGameManager has a TinyNetIdentity component. This will cause the TinyNetGameManager object to be disabled, so it is not recommended."); }
1920
}
2021

2122
if (tnis[i].isClient || tnis[i].isServer) {

Assets/TinyBirdNet/Example/MainMenu.unity

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ MonoBehaviour:
313313
m_Script: {fileID: 11500000, guid: d6dbe83d791db234d8c50fdc1e46609e, type: 3}
314314
m_Name:
315315
m_EditorClassIdentifier:
316-
NetworkEveryXFixedFrames: 20
316+
multiplayerConnectKey: TinyBirdNet TPS Example 1.1
317+
NetworkEveryXFixedFrames: 1
317318
registeredPrefabs:
318319
- {fileID: 1003412172681446, guid: 2988858db036b6a42a8832c52ac6e5a6, type: 2}
319320
- {fileID: 1057121294660296, guid: 3d4ccdbf287c1dc4e910d17a2f69307f, type: 2}
@@ -645,7 +646,7 @@ RectTransform:
645646
m_PrefabInternal: {fileID: 0}
646647
m_GameObject: {fileID: 1998987611}
647648
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
648-
m_LocalPosition: {x: 526.5, y: 273, z: 0}
649+
m_LocalPosition: {x: 478.5, y: 273, z: 0}
649650
m_LocalScale: {x: 1, y: 1, z: 1}
650651
m_Children:
651652
- {fileID: 1148536499}

Assets/TinyBirdNet/TinyNetBehaviour.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public TinyNetIdentity NetIdentity {
5353
_netIdentity = GetComponent<TinyNetIdentity>();
5454

5555
if (_netIdentity == null) {
56-
TinyLogger.LogError("There is no TinyNetIdentity on this object. Please add one.");
56+
if (TinyNetLogLevel.logError) { TinyLogger.LogError("There is no TinyNetIdentity on this object. Please add one."); }
5757
}
5858

5959
return _netIdentity;
@@ -196,13 +196,15 @@ public virtual void TinySerialize(NetDataWriter writer, bool firstStateUpdate) {
196196
writer.Put(NetworkID);
197197
}
198198

199-
writer.Put(TinyNetStateSyncer.DirtyFlagToInt(_dirtyFlag));
199+
if (!firstStateUpdate) {
200+
writer.Put(TinyNetStateSyncer.DirtyFlagToInt(_dirtyFlag));
201+
}
200202

201203
Type type;
202204
int maxSyncVar = propertiesName.Length;
203205

204206
for (int i = 0; i < maxSyncVar; i++) {
205-
if (_dirtyFlag[i] == false) {
207+
if (!firstStateUpdate && _dirtyFlag[i] == false) {
206208
continue;
207209
}
208210

@@ -241,17 +243,17 @@ public virtual void TinyDeserialize(NetDataReader reader, bool firstStateUpdate)
241243
NetworkID = reader.GetInt();
242244
}
243245

244-
int dFlag = reader.GetInt();
245-
246-
Debug.Log(TinyNetStateSyncer.Display(dFlag));
246+
if (!firstStateUpdate) {
247+
int dFlag = reader.GetInt();
247248

248-
TinyNetStateSyncer.IntToDirtyFlag(dFlag, DirtyFlag);
249+
TinyNetStateSyncer.IntToDirtyFlag(dFlag, _dirtyFlag);
250+
}
249251

250252
Type type;
251253
int maxSyncVar = propertiesName.Length;
252254

253255
for (int i = 0; i < maxSyncVar; i++) {
254-
if (DirtyFlag[i] == false) {
256+
if (!firstStateUpdate && _dirtyFlag[i] == false) {
255257
continue;
256258
}
257259

Assets/TinyBirdNet/TinyNetClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected override void RegisterMessageHandlers() {
6565

6666
public virtual bool StartClient() {
6767
if (_netManager != null) {
68-
TinyLogger.LogError("StartClient() called multiple times.");
68+
if (TinyNetLogLevel.logError) { TinyLogger.LogError("StartClient() called multiple times."); }
6969
return false;
7070
}
7171

@@ -74,13 +74,13 @@ public virtual bool StartClient() {
7474

7575
ConfigureNetManager(true);
7676

77-
TinyLogger.Log("[CLIENT] Started client");
77+
if (TinyNetLogLevel.logDev) { TinyLogger.Log("[CLIENT] Started client"); }
7878

7979
return true;
8080
}
8181

8282
public virtual void ClientConnectTo(string hostAddress, int hostPort) {
83-
TinyLogger.Log("[CLIENT] Attempt to connect at adress: " + hostAddress + ":" + hostPort);
83+
if (TinyNetLogLevel.logDev) { TinyLogger.Log("[CLIENT] Attempt to connect at adress: " + hostAddress + ":" + hostPort); }
8484

8585
recycleWriter.Reset();
8686
recycleWriter.Put(TinyNetGameManager.instance.multiplayerConnectKey);

Assets/TinyBirdNet/TinyNetIdentity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void SetAssetGUID(GameObject prefab) {
143143

144144
void OnValidate() {
145145
if (_serverOnly && _localPlayerAuthority) {
146-
TinyLogger.LogWarning("Disabling Local Player Authority for " + gameObject + " because it is server-only.");
146+
if (TinyNetLogLevel.logWarn) { TinyLogger.LogWarning("Disabling Local Player Authority for " + gameObject + " because it is server-only."); }
147147
_localPlayerAuthority = false;
148148
}
149149

Assets/TinyBirdNet/TinyNetScene.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,15 @@ public virtual void OnConnectionRequest(ConnectionRequest request) {
325325
}
326326

327327
public virtual void OnPeerConnected(NetPeer peer) {
328-
TinyLogger.Log("[" + TYPE + "] We have new peer: " + peer.EndPoint + " connectId: " + peer.ConnectId);
328+
if (TinyNetLogLevel.logDev) { TinyLogger.Log("[" + TYPE + "] We have new peer: " + peer.EndPoint + " connectId: " + peer.ConnectId); }
329329

330330
TinyNetConnection nConn = CreateTinyNetConnection(peer);
331331

332332
OnConnectionCreated(nConn);
333333
}
334334

335335
public virtual void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) {
336-
TinyLogger.Log("[" + TYPE + "] disconnected from: " + peer.EndPoint + " because " + disconnectInfo.Reason);
336+
if (TinyNetLogLevel.logDev) { TinyLogger.Log("[" + TYPE + "] disconnected from: " + peer.EndPoint + " because " + disconnectInfo.Reason); }
337337

338338
TinyNetConnection nConn = GetTinyNetConnection(peer);
339339
OnDisconnect(nConn);
@@ -342,11 +342,11 @@ public virtual void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectIn
342342
}
343343

344344
public virtual void OnNetworkError(NetEndPoint endPoint, int socketErrorCode) {
345-
TinyLogger.Log("[" + TYPE + "] error " + socketErrorCode + " at: " + endPoint);
345+
if (TinyNetLogLevel.logError) { TinyLogger.LogError("[" + TYPE + "] error " + socketErrorCode + " at: " + endPoint); }
346346
}
347347

348348
public virtual void OnNetworkReceive(NetPeer peer, NetDataReader reader, DeliveryMethod deliveryMethod) {
349-
TinyLogger.Log("[" + TYPE + "] received message " + TinyNetMsgType.MsgTypeToString(ReadMessageAndCallDelegate(reader, peer)) + " from: " + peer.EndPoint + " method: " + deliveryMethod.ToString());
349+
if (TinyNetLogLevel.logDev) { TinyLogger.Log("[" + TYPE + "] received message " + TinyNetMsgType.MsgTypeToString(ReadMessageAndCallDelegate(reader, peer)) + " from: " + peer.EndPoint + " method: " + deliveryMethod.ToString()); }
350350
}
351351

352352
/// <summary>
@@ -356,23 +356,23 @@ public virtual void OnNetworkReceive(NetPeer peer, NetDataReader reader, Deliver
356356
/// <param name="reader"></param>
357357
/// <param name="messageType"></param>
358358
public virtual void OnNetworkReceiveUnconnected(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType) {
359-
TinyLogger.Log("[" + TYPE + "] Received Unconnected message from: " + remoteEndPoint);
359+
if (TinyNetLogLevel.logDev) { TinyLogger.Log("[" + TYPE + "] Received Unconnected message from: " + remoteEndPoint); }
360360

361361
if (messageType == UnconnectedMessageType.DiscoveryRequest) {
362362
OnDiscoveryRequestReceived(remoteEndPoint, reader);
363363
}
364364
}
365365

366366
public virtual void OnNetworkLatencyUpdate(NetPeer peer, int latency) {
367-
TinyLogger.Log("[" + TYPE + "] Latency update for peer: " + peer.EndPoint + " " + latency + "ms");
367+
if (TinyNetLogLevel.logDev) { TinyLogger.Log("[" + TYPE + "] Latency update for peer: " + peer.EndPoint + " " + latency + "ms"); }
368368
}
369369

370370
/*public virtual void OnNetworkReceive(NetPeer peer, NetDataReader reader) {
371371
TinyLogger.Log("[" + TYPE + "] On network receive from: " + peer.EndPoint);
372372
}*/
373373

374374
protected virtual void OnDiscoveryRequestReceived(NetEndPoint remoteEndPoint, NetDataReader reader) {
375-
TinyLogger.Log("[" + TYPE + "] Received discovery request. Send discovery response");
375+
if (TinyNetLogLevel.logDev) { TinyLogger.Log("[" + TYPE + "] Received discovery request. Send discovery response"); }
376376
_netManager.SendDiscoveryResponse(new byte[] { 1 }, remoteEndPoint);
377377
}
378378

Assets/TinyBirdNet/TinyNetServer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public override void TinyNetUpdate() {
5050

5151
public virtual bool StartServer(int port, int maxNumberOfPlayers) {
5252
if (_netManager != null) {
53-
TinyLogger.LogError("StartServer() called multiple times.");
53+
if (TinyNetLogLevel.logError) { TinyLogger.LogError("StartServer() called multiple times."); }
5454
return false;
5555
}
5656

@@ -59,7 +59,7 @@ public virtual bool StartServer(int port, int maxNumberOfPlayers) {
5959

6060
ConfigureNetManager(true);
6161

62-
TinyLogger.Log("[SERVER] Started server at port: " + port + " with maxNumberOfPlayers: " + maxNumberOfPlayers);
62+
if (TinyNetLogLevel.logDev) { TinyLogger.Log("[SERVER] Started server at port: " + port + " with maxNumberOfPlayers: " + maxNumberOfPlayers); }
6363

6464
return true;
6565
}
@@ -463,7 +463,7 @@ public bool SpawnAllObjects() {
463463
continue;
464464

465465
if (tni2.gameObject == null) {
466-
if (TinyNetLogLevel.logDebug) { TinyLogger.LogError("Log this? Something is wrong if this happens?"); }
466+
if (TinyNetLogLevel.logError) { TinyLogger.LogError("Log this? Something is wrong if this happens?"); }
467467
continue;
468468
}
469469

@@ -492,7 +492,7 @@ void OnRequestAddPlayerMessage(TinyNetMessageReader netMsg) {
492492
netMsg.ReadMessage(s_TinyNetRequestAddPlayerMessage);
493493

494494
if (s_TinyNetRequestAddPlayerMessage.amountOfPlayers <= 0) {
495-
if (TinyNetLogLevel.logDebug) { TinyLogger.LogError("OnRequestAddPlayerMessage() called with amountOfPlayers <= 0"); }
495+
if (TinyNetLogLevel.logError) { TinyLogger.LogError("OnRequestAddPlayerMessage() called with amountOfPlayers <= 0"); }
496496
return;
497497
}
498498

@@ -511,7 +511,7 @@ void OnRequestRemovePlayerMessage(TinyNetMessageReader netMsg) {
511511
netMsg.ReadMessage(s_TinyNetRequestRemovePlayerMessage);
512512

513513
if (s_TinyNetRequestRemovePlayerMessage.playerControllerId <= 0) {
514-
if (TinyNetLogLevel.logDebug) { TinyLogger.LogError("OnRequestRemovePlayerMessage() called with playerControllerId <= 0"); }
514+
if (TinyNetLogLevel.logError) { TinyLogger.LogError("OnRequestRemovePlayerMessage() called with playerControllerId <= 0"); }
515515
return;
516516
}
517517

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ The goal of TinyBirdNet is to create an API similar to Unet's HLAPI while using
99
- Free for noncommercial projects! Try it fully without paying.
1010
- No additional charges for CCU, bandwith, nothing, it's yours to use.
1111

12-
**Version: 1.1.1**
13-
- Updated LiteNetLib to master branch commit 74160c322ba4c94da1df0d395d2e012b020e68f1
14-
- Now uses pure LiteNetLib, no custom modifications.
15-
- Application GUID is now stored into peer.Tag.
12+
**Version: 1.1.2**
13+
- Fixed initial serialization not sending all properties.
14+
- Fixed many logs without a log filter.
15+
- Fixed some changes made to the TinyNetGameManagerEditor not being saved.
1616

1717
**Supports Unity 2017 and above**
1818

0 commit comments

Comments
 (0)