photonview.rpc未在photonnetwork.localplayer.ismasterclient下调用
我想让主客户端执行新闻更新代码,其他客户端接收来自主客户端的更新消息,但是当我将 PhotonView.RPC()
放入 < code>if (!PhotonNetwork.LocalPlayer.IsMasterClient)
这是仅由主客户端执行的消息更新代码:
if (PhotonNetwork.LocalPlayer.IsMasterClient)
{
if (currentItem < news.newsList.Count)
{
timeGap = TimeManager.globalSec - pubTime;
if (timeGap >= 2)
{
pubTime = TimeManager.globalSec;
if (page[currentPage].Count < 4)
{
page[currentPage].Add(news.newsList[currentItem]);
hlTitle.GetComponent<TextMeshProUGUI>().text = news.newsList[currentItem].newsTitle;
hlContent.GetComponent<TextMeshProUGUI>().text = news.newsList[currentItem].newsContent;
if (currentPage == 0)
{
for (int i = 0; i < page[currentPage].Count; i++)
{
newsItems[i].GetComponent<TextMeshProUGUI>().text = page[currentPage][i].newsTitle;
}
}
currentItem++;
}
else
{
page.Add(new List<NewsIndex>());
pageSum++;
}
}
NewsCount(currentItem, pageSum);
print(itemSum);
print(pageSum)
}
}
Punrpc 中的代码:
[PunRPC]
void NewsCount(int newsNum, int pageNum)
{
itemSum = newsNum;
pageSum = pageNum;
}
其他客户端收到来自主客户端的消息:
if (!PhotonNetwork.LocalPlayer.IsMasterClient) {
view.RPC("NewsCount", RpcTarget.All, itemSum, pageSum);
print(itemSum);
print(pageSum);
}
现在的问题是它可以打印出数字但始终为 0 并且1,这意味着 view.RPC() 根本不起作用。
I'd like to make the master client execute the news updates code, and other clients receive the updates message from the master client, but I met a weird problem when I put PhotonView.RPC()
within if (!PhotonNetwork.LocalPlayer.IsMasterClient)
This is the news updates code executed only by the master client:
if (PhotonNetwork.LocalPlayer.IsMasterClient)
{
if (currentItem < news.newsList.Count)
{
timeGap = TimeManager.globalSec - pubTime;
if (timeGap >= 2)
{
pubTime = TimeManager.globalSec;
if (page[currentPage].Count < 4)
{
page[currentPage].Add(news.newsList[currentItem]);
hlTitle.GetComponent<TextMeshProUGUI>().text = news.newsList[currentItem].newsTitle;
hlContent.GetComponent<TextMeshProUGUI>().text = news.newsList[currentItem].newsContent;
if (currentPage == 0)
{
for (int i = 0; i < page[currentPage].Count; i++)
{
newsItems[i].GetComponent<TextMeshProUGUI>().text = page[currentPage][i].newsTitle;
}
}
currentItem++;
}
else
{
page.Add(new List<NewsIndex>());
pageSum++;
}
}
NewsCount(currentItem, pageSum);
print(itemSum);
print(pageSum)
}
}
Code in Punrpc:
[PunRPC]
void NewsCount(int newsNum, int pageNum)
{
itemSum = newsNum;
pageSum = pageNum;
}
Other clients receive message from master client:
if (!PhotonNetwork.LocalPlayer.IsMasterClient) {
view.RPC("NewsCount", RpcTarget.All, itemSum, pageSum);
print(itemSum);
print(pageSum);
}
Now the problem is that it can print out numbers but is constantly 0 and 1, which means the view.RPC() doesn't work at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,我有点困惑。你说
,但否!在您的代码中,所有 non-Master 客户 发送 rpc,未接收。
另一方面,我看不到主客户端发送任何内容,他只是直接调用
newscount
,这使得此方法仅在本地为主客户端执行,但实际上并未作为RPC发送到其他客户!因此,发生的事情是,您所有的非主机客户端将自己的
0
和1
发送给其他所有人,因为他们从未真正计算过这些都从未更改过。它不会影响主客户,因为他总是计算并打印自己的价值观。我只能猜测,但是如果我正确理解您,您实际上宁愿将计算出的值从主客户端发送给其他所有人。
所以我认为你想做的是
to be honest I'm a bit confused. You say
but no! In your code all the non-master clients are sending an RPC, not receiving.
And on the other hand I don't see the master client sending anything, he is rather directly calling
NewsCount
which makes this method be executed only locally for the master client but not actually send as an RPC to other clients!So what happens is that all your non-master clients send their own
0
and1
to everyone else since they never actually calculate these they never change. It doesn't affect the master client since he always calculates and prints his own values.I can only guess but if I understanding you correctly you actually rather want to send the calculated values from the master client to everyone else.
So I think what you rather wanted to do is