PUN2 question regarding sending information to a playerRoomList prefab from the Main room UI script

Options

In short im setting some values in the room UI eg player colour, avatar, whatever.

I want to then send those changes to whichever player room listing prefab is the owner of that listing AND update to all of the rest of the room players.

I'm a noob when it comes to this stuff, i have checked all demos, my current project is based off the asteroids demo, which uses player colour but it's assigned based on the player id rather than choice.

Is this something i would need hashtables for as i have not yet learned those but seen them in demo projects, or is it a slightly annoying case of from the main room ui, find all player room list prefabs in the scene, check which one i own and update that way(although same issue is how do i update that so everyone sees it).

I can provide more details, current script setups etc if needed.

For reference my current scripts in question are

-LobbyMainPanel.cs - provides all ui buttons for login, room creation, roomlist, and rooms themselves.

-PlayerListingEntry.cs - the prefab that is instantiated inside a room to show player names etc.


That top part is my priority, i will eventually need to send those new customization details eg, colour, avatar etc to the spawned player prefab in the game scene, but im hoping whatever i learn for the above will translate to that.

Thanks.

Answers

  • Tobias
    Options

    This sounds like a job for Custom Player Properties. They update everone and there is an event when they fire, so you could update the UI.

  • Craigus
    Craigus
    edited January 2022
    Options

    I know this is a late reply, but 4 days later i still can't quite understand how i should get the results that i am after.

    I have done this inside my playerlisting prefab

    playerColorImage.color = customization.GetColor((int)_customProperties["BallColour"]);

            PhotonNetwork.LocalPlayer.CustomProperties = _customProperties;


    Wether or not that is correct im still not sure, but i have absolutly no idea how from another script (The main UI one) i can call a function called ApplyCustomization using a button on the ui and send it to the owned player listing (to apply the colour) and then update that for all players in the room to see the new colour of that player.


    The closest i can get to is

    public void ApplyCustomization()

        {

            foreach (GameObject entry in playerListEntries.Values)

            {

                entry.GetComponent<PlayerListEntry>()._customProperties["BallColour"] = currentColour;

                entry.GetComponent<PlayerListEntry>().UpdateCustomizations(currentColour);

            }

        }


    But the issues with this are, A. it's changing the colour of everyone, and B. it's not showing that for all the players, only the one im using. I know that it's incorrect to do the foreach as it's calling that on each listing, but i just dont know how to do it correclty, it seems every tutorial on this matter has things like the buttons to change player colour actually inside the player listing rather than on seperate UI. Any help would mean the world.

    [UPDATE]

    Little update before i sleep.

    I have moved the hashtable decleration over to the mainui script

    which now looks like this

    _customProperties["BallColour"] = currentColour;

            PhotonNetwork.LocalPlayer.SetCustomProperties(_customProperties);


            foreach (GameObject entry in playerListEntries.Values)

            {

                entry.GetComponent<PlayerListEntry>().UpdateCustomizations();

            }


    And the player listing function looks like this

    ballColour = (int)lobbyMain._customProperties["BallColour"];

            playerColorImage.color = customization.GetColor(ballColour);


    Thought i was onto the right track but it's still updating both player images on the local client

    and not updating anything for the room.

  • Tobias
    Options

    How about you first make sure updating the player properties does what you want / need? You could (e.g.) simply Debug.Log all player's Custom Properties or show them on screen or whatever.

    Then, as a next step, you make sure you got a list of objects related to each player and the right assignment.

    Last but not least, you try to modify the objects player by player and make sure this works.

    Tie everything together.

    Us Photonians can't check or debug custom code for your game, sorry.