public void OnPlayerEnteredRoom(Player newPlayer)
        {
            bool isRejoiningMaster = newPlayer.IsMasterClient;
            bool amMasterClient    = PhotonNetwork.IsMasterClient;

            // Nothing to do if this isn't the master joining, nor are we the master.
            if (!isRejoiningMaster && !amMasterClient)
            {
                return;
            }

            var views = PhotonNetwork.PhotonViewCollection;

            // Get a slice big enough for worst case - all views with no compression...extra byte per int for varint bloat.

            if (amMasterClient)
            {
                reusableIntList.Clear();
            }

            foreach (var view in views)
            {
                // TODO: make this only if the new actor affects this?
                view.RebuildControllerCache();

                //// If this is the master, and some other player joined - notify them of any non-creator ownership
                if (amMasterClient)
                {
                    int viewOwnerId = view.OwnerActorNr;
                    // TODO: Ideally all of this would only be targetted at the new player.
                    if (viewOwnerId != view.CreatorActorNr)
                    {
                        reusableIntList.Add(view.ViewID);
                        reusableIntList.Add(viewOwnerId);
                        //PhotonNetwork.TransferOwnership(view.ViewID, viewOwnerId);
                    }
                }
                // Master rejoined - reset all ownership. The master will be broadcasting non-creator ownership shortly
                else if (isRejoiningMaster)
                {
                    view.ResetOwnership();
                }
            }

            if (amMasterClient && reusableIntList.Count > 0)
            {
                PhotonNetwork.OnwershipUpdate(reusableIntList.ToArray(), newPlayer.ActorNumber);
            }
        }
        public void OnJoinedRoom()
        {
            if (PhotonNetwork.ViewCount == 0)
            {
                return;
            }

            var views = PhotonNetwork.PhotonViewCollection;

            bool amMasterClient    = PhotonNetwork.IsMasterClient;
            bool amRejoiningMaster = amMasterClient && PhotonNetwork.CurrentRoom.PlayerCount > 1;

            if (amRejoiningMaster)
            {
                reusableIntList.Clear();
            }

            // If this is the master rejoining, reassert ownership of non-creator owners
            foreach (var view in views)
            {
                int viewOwnerId   = view.OwnerActorNr;
                int viewCreatorId = view.CreatorActorNr;

                // Scene objects need to set their controller to the master.
                view.RebuildControllerCache();

                // Rejoining master should enforce its world view, and override any changes that happened while it was soft disconnected
                if (amRejoiningMaster)
                {
                    if (viewOwnerId != viewCreatorId)
                    {
                        reusableIntList.Add(view.ViewID);
                        reusableIntList.Add(viewOwnerId);
                    }
                }
            }

            if (amRejoiningMaster && reusableIntList.Count > 0)
            {
                PhotonNetwork.OnwershipUpdate(reusableIntList.ToArray());
            }
        }