Subscribing to OnRoomPropertiesUpdate without overriding the baseclass

MrVentures
edited August 12 in DotNet
This tutorial: https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent
Shows how to subscribe to EventReceived with the following line...

PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
On the other hand, to receive room properties, you need to override OnRoomPropertiesUpdate.

Is there a way to instead receive room properties by subscribing with the aforementioned += format? For example, can I do something like this...
PhotonNetwork.NetworkingClient.RoomPropertiesUpdated += OnRoomPropUpdate;

Comments

  • Hi @MrVentures,

    You can use OnEvent for PropertiesChanged event like in LoadBalancingClient ("Assets\Photon\PhotonRealtime\Code\LoadBalancingClient.cs"):
    public virtual void OnEvent(EventData photonEvent)
    {
                int actorNr = photonEvent.Sender;
                Player originatingPlayer = (this.CurrentRoom != null) ? this.CurrentRoom.GetPlayer(actorNr) : null;
    
                switch (photonEvent.Code)
                {
                        // [...]
                        case EventCode.PropertiesChanged:
                        // whenever properties are sent in-room, they can be broadcasted as event (which we handle here)
                        // we get PLAYERproperties if actorNr > 0 or ROOMproperties if actorNumber is not set or 0
                        int targetActorNr = 0;
                        if (photonEvent.Parameters.ContainsKey(ParameterCode.TargetActorNr))
                        {
                            targetActorNr = (int)photonEvent[ParameterCode.TargetActorNr];
                        }
    
                        Hashtable gameProperties = null;
                        Hashtable actorProps = null;
                        if (targetActorNr == 0)
                        {
                            gameProperties = (Hashtable)photonEvent[ParameterCode.Properties];
                        }
                        else
                        {
                            actorProps = (Hashtable)photonEvent[ParameterCode.Properties];
                        }
    
                          // [...]
    

    So this code is what we use internally to do things for you so you won't have to understand how things work under the hood and at the end trigger the corresponding callbacks.
    But the code is open and you can use it if you want.

    Bonus: you get WHO triggered the properties change which is not available via the OnPropertiesUpdate callbacks.