I have some scene objects which become assigned ownership to players by the server. Once the players have control of the objects, I need to do some initialization on the client sides, but I'm not sure how to tell when the objects are actually given from the client. Some sort of delegate or messaging for OnOwnershipTransferred(PhotonView, PhotonPlayer) or similar would be ideal, but I can't find any way to do that. Do I just have to keep testing every frame? Here's what I have now (which doesn't work - the RPC call still happens before ownership is propagated to the players).
void OnSceneChanged(Scene oldScene, Scene newScene)
{
// Check to make sure we're not in the default scene.
if (newScene != SceneManager.GetSceneByBuildIndex (0))
{
Debug.Log( "OnSceneChanged called!" );
if ( PhotonNetwork.isMasterClient )
{
// Find root objects of team hierarchies
GameObject[] teamObjects = GameObject.FindGameObjectsWithTag ("TeamRoot");
// Assign ownership to players
for (var i = 0; i < PhotonNetwork.playerList.Length; i ++)
{
teamObjects [i].GetComponent<PhotonView> ().TransferOwnership (PhotonNetwork.playerList[i]);
}
photonView.RPC ("EnableTeams", PhotonTargets.AllViaServer);
}
}
}
[PunRPC]
void EnableTeams (PhotonMessageInfo info)
{
Debug.Log ("Received EnableTeams RPC from: " + info.photonView + info.sender + " on " + info.timestamp);
GameObject[] teamObjects = GameObject.FindGameObjectsWithTag ("TeamRoot");
for (var i = 0; i < PhotonNetwork.playerList.Length; i ++)
{
teamObjects [i].GetComponent<Team> ().enabled = true;
}
}
Team Class:
void Start ()
{
Debug.Log ("Checking ownership of " + gameObject.ToString ());
// Set up game environment for local player.
if (photonView.isMine) {
//Do Stuff
}
}