Custom Room and Player properties

Options
MauroGiusti
edited January 2015 in DotNet
How do I add custom properties to the player and the room using the .Net client?

Ideally, I would like to inherit a class from Player and Room, declare my properties there (maybe using an attribute that states those are to be serialized and sent to the other clients), override the virtual CreatePlayer and CreateRoom in my custom LoadBalancingClient child and find these properties on all the clients.

What I seem to understand, instead is that you need to pass a Hashtable to OpCreateRoom?

Thanks -

Comments

  • In the demo-loadbalancing sample, I see that the DemoPlayer class has multiple ways to set the player properties, this is a bit confusing -

    The properties are set in DemoClient constructor, with SetCustomProperties:
    this.LocalPlayer.SetCustomProperties(new Hashtable() { { "class", "tank" + (SupportClass.ThreadSafeRandom.Next() % 99) } });
    

    At the same time, the DemoPlayer class has properties of its own (posX, posY, color) and a SendPlayerInfo method -

    Do they serve different purpose and why?

    Thanks.
  • vadim
    Options
    SendPlayerInfo has nothing to do with custom properties. It uses events to share data with other clients.

    Setting player custom properties in DemoClient constructor (before connecting and joining the room) allows to have these properties set right from the very game start. You can set them also anytime later while you are in the room.
    Same for rooms. Properties can be set during being in room or before creating room. But in latter case custom properties put in OpCreateRoom call parameter instead of calling SetCustomProperties.

    You can extend Room and Player but need to deal with Photon properties update yourself. For instance implement setters for class properties so that SetCustomProperties called with new value.