RPC 崩溃 Unity

RPC crashing Unity

我在过去的几个小时里遇到了一个非常令人不安的问题。 似乎我使用数组(int、float、byte 等)进行的每个 RPC 调用都会使整个引擎崩溃。 我已经做了一个如何重现的小例子,我想知道它是否确实是一个错误,或者我是否做错了什么:

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

    // Use this for initialization
    void Start () {
        Network.InitializeServer(4, 25000, true);
        networkView.RPC("test", RPCMode.All, new float[5]);
    }

    // Update is called once per frame
    void Update () {
    }

    [RPC]
    void test(float[] lol){
        Debug.Log("received "+lol);
    }
}

在具有网络视图的相机中仅使用此脚本就足以让事情崩溃。我做错什么了吗?? 提前致谢!

在Unity中使用RPC调用是restricted to certain types of parameters:

You can use the following variable types as parameters to RPCs:- int float string NetworkPlayer NetworkViewID Vector3 Quaternion

所以您可以做的是 serialize/convert 将数组转换为字符串,然后在另一侧返回数组。

您需要将 OnServerInitialized 功能添加到您的 class。然后你可以在这个函数中使用 networkView.RPC("test", RPCMode.All, new float[5]);

而且我在你的 class 中看不到 NetworkView 实例。

喜欢

public NetworkView networkView;
void OnServerInitialized(){
    Debug.Log("Server initialized and ready");
    networkView.RPC("test", RPCMode.All, new float[5]);
}

这是 4.6.3 和 4.6.4 中的一个错误,当我尝试在 unity5 中通过 rpc 发送字节数组时它完成了工作。希望对您有所帮助