Update SyncDictionary.md

Fixed code example
This commit is contained in:
MrGadget 2019-08-27 09:05:52 -04:00 committed by GitHub
parent 1cc760497a
commit d578e720a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,7 @@ public class ExamplePlayer : NetworkBehaviour
public readonly SyncDictionaryStringItem Equipment = new SyncDictionaryStringItem(); public readonly SyncDictionaryStringItem Equipment = new SyncDictionaryStringItem();
public void OnStartServer() public override void OnStartServer()
{ {
Equipment.Add("head", new Item { name = "Helmet", hitPoints = 10, durability = 20 }); Equipment.Add("head", new Item { name = "Helmet", hitPoints = 10, durability = 20 });
Equipment.Add("body", new Item { name = "Epic Armor", hitPoints = 50, durability = 50 }); Equipment.Add("body", new Item { name = "Epic Armor", hitPoints = 50, durability = 50 });
@ -48,14 +48,14 @@ public class ExamplePlayer : NetworkBehaviour
Equipment.Add("hands", new Item { name = "Sword", hitPoints = 30, durability = 15 }); Equipment.Add("hands", new Item { name = "Sword", hitPoints = 30, durability = 15 });
} }
private void OnStartClient() public override void OnStartClient()
{ {
// Equipment is already populated with anything the server set up // Equipment is already populated with anything the server set up
// but we can subscribe to the callback in case it is updated later on // but we can subscribe to the callback in case it is updated later on
Equipment.Callback += OnEquipmentChange; Equipment.Callback += OnEquipmentChange;
} }
private void OnEquipmentChange(SyncDictionaryStringItem.Operation op, string key, Item item) void OnEquipmentChange(SyncDictionaryStringItem.Operation op, string key, Item item)
{ {
// equipment changed, perhaps update the gameobject // equipment changed, perhaps update the gameobject
Debug.Log(op + " - " + key); Debug.Log(op + " - " + key);