PUN变更仅影响本地玩家,不影响其他客户 [英] PUN Changes affect local players only, not other clients

查看:265
本文介绍了PUN变更仅影响本地玩家,不影响其他客户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其他客户在玩家游戏中的行为方式一直存在一些问题.基本上,如果有影响到每个客户的变更,它将起作用.但是,它将仅正确显示在本地播放器的屏幕上.其他播放器(显示在客户端屏幕上)保持不变.

I've been having some issues with how other clients behave in a player's game. Basically, if there's a change that affects every client, it will work. However, it will only show up correctly on the local player's screen. Other players (as they appear on a client's screen) remain unchanged.

例如,假设我将一个名为"test"的布尔值设置为false.房间中的每个玩家都必须同时将此布尔值设为true.每个玩家自己的角色的测试"设置为true,但是本地玩家屏幕上的其他客户端将其布尔值显示为 false .

For example, let's say I have a boolean called "test" set to false. Every player in the room at the same time is meant to turn this boolean to true. Each player's own character gets "test" set to true, but other clients on a local player's screen show their boolean as false.

我如何经历以下每个玩家的示例:

Example of how I go through every player below:

foreach (var item in PhotonNetwork.PlayerList)
            {
                var itemPhotonView = (PhotonView)item.TagObject;

                itemPhotonView.RPC("SetPlayerTeam", item, citiString);
            }

我希望上面的代码能够遍历每个字符,即使不是本地玩家也是如此.我相信它可以实现,但是我不确定100%.

I want the code above to go through every character, even if not a local player. I believe it accomplishes it, but I'm not 100% sure.

public override void OnPlayerPropertiesUpdate(Player target, ExitGames.Client.Photon.Hashtable changedProps)
        {
            if (changedProps.ContainsKey("team"))
            {
                var targetPhotonView = (PhotonView)target.TagObject;
                targetPhotonView.RPC("ChangeTeamObjs", target, changedProps);
            }

        }

我肯定知道的上述代码不会更改非本地客户端.我不确定是否应该像第一个示例那样使用"foreach"方法,因为我什至不确定是否能实现它.有什么想法吗?

The code above I know for sure does not change non-local clients. I'm unsure if I should use the 'foreach' method like the first example because I'm not even sure if that will accomplish it. Any ideas?

推荐答案

通过将rpc的目标定义为所有人,可以以更有效的方式将rpc发送给所有人,这将防止网络流量过载,并且仅发送一个rpc.

Sending rpc to all can be done in a more efficient way, by defining the target of the rpc to be everyone, this will prevent overloading the network traffic, and only one rpc is sent.

https://doc.photonengine.com/en -us/pun/v2/gameplay/rpcsandraiseevent#targets__buffering_and_order

PhotonView photonView = PhotonView.Get(this);
photonView.RPC("ChangeTeamObjs", RpcTarget.All, , item, citiString);

再见

吉恩

这篇关于PUN变更仅影响本地玩家,不影响其他客户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆