简体   繁体   English

使用Photon Unity Networking通过网络更快地进行RPC发送的方法

[英]Way for faster RPC sending via network with Photon Unity Networking

I am creating 2D top-down shooter using Unity and PUN2. 我正在使用Unity和PUN2创建2D自上而下的射击游戏。 My problem is, RPC calls are taking too much time. 我的问题是,RPC调用花费太多时间。 My example is whenever player got hit by other players bullet(detected by OnTriggerEnter2D), he sends RPC_message to other players that he got hit, so they could see an effect of hit on him(his decrased HP bar). 我的示例是,每当某个玩家被其他玩家的子弹击中(通过OnTriggerEnter2D检测到)时,他都会向其他受到其攻击的玩家发送RPC_message消息,这样他们就可以看到对他的打击效果(他的HP栏已降低)。 The time between hit and decrasing HP bar is too long in my opinion, its about 1 second. 在我看来,击中HP音柱和使其弯曲之间的时间太长,大约是1秒。 This causes some trouble while player is getting hit by multiple players with multiple bullets, it is making game less dynamic. 当玩家被具有多个子弹的多个玩家击中时,这会引起一些麻烦,这会使游戏的动态性降低。 Is it any way to speed up an RPC function call? 有什么办法可以加快RPC函数调用的速度吗? My idea was to synchronize hp values using Object Synchronization, or trying this on collision detection, but im not sure if this gonna be efficient enough. 我的想法是使用“对象同步”来同步hp值,或者在冲突检测上尝试此操作,但不确定是否足够有效。

you haven't to send hit message with RPC.Just sync Health by using OnPhotonSerializeView : 您尚未通过RPC发送匹配消息。只需使用OnPhotonSerializeView同步运行OnPhotonSerializeView

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
    if (stream.IsWriting)
    {
        stream.SendNext(Health);
    }
    else
    {
        Health = (float)stream.ReceiveNext();
    }
}

I made an example about Photon for beginners in my github 在github中为初学者制作了一个有关Photon的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM