1.9.5:
- NEW: TNManager.SaveFile, TNManager.LoadFile, TNManager.Ping.
- NEW: TNManager.playerData, synchronized across the network. SyncPlayerData() to sync it if you modified it instead of setting it.
- NEW: Added DataNode.Read(byte[] data, bool binary) for creating a data node tree from raw data.
- NEW: Added OnPing, OnPlayerSync, and OnLoadFile notifications to the Game Client.
- NEW: Custom packet handlers will now be checked first, in case you want to overwrite the default handling.
- NEW: TNServerInstance.SaveTo can now be used to save the server's state manually.
- FIX: Variety of serialization-related fixes and additions.
- FIX: Better error handling when connecting and better error messages.
The "Player Data" feature is experimental right now and is in further development / testing phase. The idea is simple. Set TNManager.playerData to something, and it will be automatically sent to everyone else, accessible via their TNet.Player.data field. This means you can have an inventory class here, achievements, player profile, metrics, etc. The only clause is that each player owns their own data. You should not be trying to change other player's data. You can set this value before connecting to the server or after -- it's up to you. Either way it's going to be sent to the server alongside your player name -- so just think of it as an extension of each player.
To make using it more convenient, I advise using the DataNode class and assigning it to the playerData like so:
DataNode node
= new DataNode
("Info");node.SetChild("Faction", 123);
node.SetChild("Main Hand", someUberSword);
TNManager.playerData = node;
Other players will then be able to access it, and if you wish to be notified, assign a delegate to TManager.client.onPlayerSync:
TManager.client.onPlayerSync += YourListener;
Your listener can then be:
void YourListener (Player p)
{
Debug.Log("Player " + p.name + " has updated their data");
DataNode node = p.data as DataNode;
if (node != null)
{
Debug.Log("Faction: " + node.GetChild<int>("Faction"));
//Debug.Log("Main Hand: " + node.GetChild<YourWeaponType>("Main Hand"));
}
}