c# - 错误: "RPC method not found" on method that was never called

标签 c# unity-game-engine photon

我有一个非常奇怪的问题。目前,我正在开发一款小型跨平台“游戏”,其中一个用户佩戴 Hololens,另一个用户坐在 PC 前。 Hololens 用户解决难题,而 PC 用户通过给出提示来帮助 Hololens 用户,例如:突出显示元素。

在应用程序中,我有一个父元素(“Puzzle”)及其子元素(“Part-X”)。 每个部分(“Part-X”)都有一个属性管理器脚本:

public class PropertyManager : MonoBehaviour
{
    private Renderer rend;
    public int identifier;
    private Color initColor;

    void Start()
    {
        rend = GetComponent<Renderer>();
        initColor = rend.material.color;
    }


    public void Highlight()
    {
        rend.material.color = Color.red;
    }

    public void Unhighlight()
    {
        rend.material.color = initColor;
    }

    [PunRPC]
    public void activeElemHandling(int viewId)
    {
        transform.parent.GetComponent<ComponentHandler>().handleActiveElement(viewId);
    }
}

父级有一个带有函数“handleActiveElement”的脚本:

public void handleActiveElement(int newActiveId)
{
    foreach (Transform child in transform)
    {
        # set highlight color for new active element and unhighlight all other elements
        if (child.GetComponent<PhotonView>().ViewID == newActiveId)
        {

            child.GetComponent<PropertyManager>().Highlight();
        }
        else
        {
            child.GetComponent<PropertyManager>().Unhighlight();
        }
    }
}

现在我用这种方式从 PC 用户处触发 RPC:

void OnMouseDown()
{
    int viewId = photonView.ViewID;
    PropertyManager manager = GetComponent<PropertyManager>();
    string functionName = nameof(manager.activeElemHandling);
    photonView.RPC(functionName, RpcTarget.All, viewId); # It works the same by providing the plain string 'activeElemHandling'

虽然结果适用于 PC 应用程序端的应用程序,但它不适用于 Hololens 应用程序端。这里我得到一个非常奇怪的错误:

RPC method 'setChildren(Int32)' not found on object with PhotonView XXXX

我从未调用过 RPC 方法“setChildren”,而且我也不想调用它。我已经研究了几个小时了,但没有找到解决方案。如果有人知道如何解决它,我非常感激。谢谢!

最佳答案

好吧,在derHugo的冲动下我解决了这个问题。非常感谢!

我需要重置双方的 RPC。这可以通过找到 PhotonServerSettings.asset-File 并打开“RPC”段来实现,其中可以通过单击“清除 RPC”来重置 RPC。并且它正在工作。

关于c# - 错误: "RPC method not found" on method that was never called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69658484/

相关文章:

c# - WebGrid 的 header 格式

c# - MongoDB 的单例

c# - 没有服务器的Unity3D内置多人游戏?

unity-game-engine - 光子语音上的回声。即使在演示中

c# - 当数组大小大于 Int32.MaxValue 时,.Length 行为与 .LongLength

c# - 如何在 Window 启动 C# 时将 wpf 应用程序移动到最小化托盘?

C#相当于Objective-C的dispatch_group和queue?

c# - 在 iPhone 上运行时,RestSharp 与 Unity3d 一起崩溃

c# - 无法启用Unity C#调试Hololens

ios - 如何使用unity SDK保持登录Facebook