Unity:委托`System.Action'不带'1'参数

时间:2017-07-18 02:19:23

标签: c# unity3d

我有以下代码:

socket.On ("chat", (data) => {
                string str = data.ToString ();

                ChatData chat = JsonConvert.DeserializeObject<ChatData> (str);
                string strChatLog = "user#" + chat.id + ": " + chat.msg;

                int pos = userArr.IndexOf (chat.id);
                if (pos > -1) {
                    var InsObj = Instantiate (player, StringToVector3 (chat.msg), Quaternion.identity);
                    InsObj.name = chat.id;
                    userArr [userArr.Length + 1] = chat.id;
                }

                // Access to Unity UI is not allowed in a background thread, so let's put into a shared variable
                lock (chatLog) {
                    chatLog.Add (strChatLog);
                }
            });

当我尝试运行它时,我收到此错误:

Assets/SocketIO/SocketIOScript.cs(59,23): error CS1593: Delegate `System.Action' does not take `1' arguments

然而,当我删除这部分时:

int pos = userArr.IndexOf (chat.id);
                if (pos > -1) {
                    var InsObj = Instantiate (player, StringToVector3 (chat.msg), Quaternion.identity);
                    InsObj.name = chat.id;
                    userArr [userArr.Length + 1] = chat.id;
                }

它运作得很好。

我想知道为什么会发生这种情况,我一直试图弄明白这一点。我找到了关于它的this帖子,但这对我没什么帮助,因为我不会认为我可以指定data

编辑:

StringToVector3包含以下代码(但即使我摆脱了StringToVector3,我仍然会收到错误):

public static Vector3 StringToVector3 (string sVector)
    {
        // Remove the parentheses
        if (sVector.StartsWith ("(") && sVector.EndsWith (")")) {
            sVector = sVector.Substring (1, sVector.Length - 2);
        }

        // split the items
        string[] sArray = sVector.Split (',');

        // store as a Vector3
        Vector3 result = new Vector3 (
                             float.Parse (sArray [0]),
                             float.Parse (sArray [1]),
                             float.Parse (sArray [2]));

        return result;
    }

1 个答案:

答案 0 :(得分:0)

问题是我需要使用System.Array.IndexOf而不是userArr.IndexOf