如何将C#数组转换为unityscript

时间:2012-07-31 14:48:17

标签: c# unity3d unityscript

我正在尝试使用Unity3D制作智能手机应用程序并使用unityscript。我从Prime31购买了一些插件,它们都运行正常,但示例脚本是用C#编写的。

我想将下面的示例转换为JS:

var buttons = new string[] { "Save", "Cancel" };
EtceteraBinding.showAlertWithTitleMessageAndButtons( "Alert!", "Do you want to save?", buttons );

我试过这样的话:

var buttons:String[];
buttons=["Save","Cancel"];
EtceteraBinding.showAlertWithTitleMessageAndButtons( "Alert!", "Do you want to save?", buttons );

这不好,当然["Save","Cancel"]显示在第一个按钮而另一个没有显示?

我做错了什么?

5 个答案:

答案 0 :(得分:1)

您有showAlertWithTitleMessageAndButtons()的任何文档吗?

也许在JavaScript中,参数不同。例如,按钮标题可能作为单独的参数而不是数组传递:

showAlertWithTitleMessageAndButtons("Alert", "Something", "buttonTitle1", "buttontTitle2")

答案 1 :(得分:1)

取消您提供的文件:

 // Shows a standard Apple alert with the given title, message and an array of buttons. At least one button must be included. 
 public static void showAlertWithTitleMessageAndButtons( string title, string message, string[] buttons )

你应该可以使用:

EtceteraBinding.showAlertWithTitleMessageAndButtons( "Alert!", "Do you want to save?", ["Save", "Cancel"]);

答案 2 :(得分:0)

试试这个,我有Prime31插件,这对我编译很好。

var test : String[] = ["One", "Two"];
EtceteraBinding.showAlertWithTitleMessageAndButtons("Name","Stuff", test);

如果它不起作用,你在Unity中会遇到什么错误?

答案 3 :(得分:-2)

这个怎么样:

var buttons = new Array("Save","Cancel");

答案 4 :(得分:-2)

试试这个:

var buttons = new Array();
buttons.push("Save");
buttons.push("Cancel");