【问题标题】:How to covert an C# array to unityscript如何将 C# 数组转换为 unityscript
【发布时间】:2012-07-31 14:48:16
【问题描述】:

我正在尝试使用 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"] 课程在第一个按钮中显示,而在另一个按钮中什么也没有?

我做错了什么?

【问题讨论】:

  • 在unity3d论坛找到你的问题forum.unity3d.com/threads/…
  • 你做错的是没有使用 C#。 Prime 的东西不是为你正在使用的憎恶而设计的。

标签: c# unity3d unityscript


【解决方案1】:

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

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

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

【讨论】:

  • 是的,它们甚至可以是对象表示法。最好找到文档
  • // 显示带有给定标题、消息和一组按钮的标准 Apple 警报。必须至少包含一个按钮。公共静态无效showAlertWithTitleMessageAndButtons(字符串标题,字符串消息,字符串[]按钮)
  • 虽然看起来像 C# 签名,但 JavaScript 可能不同。尝试使用单独的参数,或使用对象表示法,看看会发生什么。
  • 没有对象表示法。我们不是在谈论 Web JS。这是 UnityScript。 Prime31 没有计划。
【解决方案2】:

关闭您提供的文档:

 // 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"]);

【讨论】:

  • @Jesper Mansa 那么文档错误或不完整,或者您提供了 c# 文档。正如有人在评论中所说,这可能只是 c#。您能否通过访问该对象来证明您可以使用 EtceteraBinding 对象。
【解决方案3】:

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

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

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

【讨论】:

    【解决方案4】:

    这个呢:

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

    【讨论】:

      【解决方案5】:

      试试这个:

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

      【讨论】:

        猜你喜欢
        • 2015-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多