Unity PowerUI / Jint - не можете конвертировать между onclick и функцией? - PullRequest
0 голосов
/ 10 мая 2019

Я пытаюсь использовать PowerUI с JavaScript Jint, чтобы сделать кнопку нажатой, очень просто в обычном HTML:

PowerUI.UI.Html = ( "<!doctype html><html><head><style>body,html{background:green; color:black;}</style></head><body><script>var b= document.createElement('b'); b.innerHTML = 'CLICK me maybe'; b.onclick=function(e,u) {console.log(234);}; document.body.appendChild(b);</script></body></html>");

Если я просто использую reuglar HTML (без Jint) и говорю .... работает нормально, только при назначении b.onclick = function () {} я получаю ошибку:

    JavaScript compile error  (At resources://): System.ArgumentException: Object of type 'System.Func`2[PowerUI.MouseEvent,System.Object]' cannot be converted to type 'System.Action`1[PowerUI.MouseEvent]'.
      at System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00071] in <23c160f925be47d7a4fd083a3a62c920>:0
      at System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00069] in <23c160f925be47d7a4fd083a3a62c920>:0
      at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00011] in <23c160f925be47d7a4fd083a3a62c920>:0
      at System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x0005d] in <23c160f925be47d7a4fd083a3a62c920>:0
      at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in <23c160f925be47d7a4fd083a3a62c920>:0
      at Jint.Runtime.Descriptors.Specialized.PropertyInfoDescriptor.set_Value (Jint.Native.JsValue value) [0x00074] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Runtime\Descriptors\Specialized\PropertyInfoDescriptor.cs:47
      at Jint.Runtime.Interop.ObjectWrapper.Put (System.String propertyName, Jint.Native.JsValue value, System.Boolean throwOnError) [0x00061] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Runtime\Interop\ObjectWrapper.cs:50
      at Jint.Engine.PutValue (Jint.Runtime.References.Reference reference, Jint.Native.JsValue value) [0x0005f] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Engine.cs:592
      at Jint.Runtime.ExpressionInterpreter.EvaluateAssignmentExpression (Jint.Parser.Ast.AssignmentExpression assignmentExpression) [0x000ab] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Runtime\ExpressionIntepreter.cs:61
      at Jint.Engine.EvaluateExpression (Jint.Parser.Ast.Expression expression) [0x00099] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Engine.cs:444
      at Jint.Runtime.StatementInterpreter.ExecuteExpressionStatement (Jint.Parser.Ast.ExpressionStatement expressionStatement) [0x00001] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Runtime\StatementInterpreter.cs:33
      at Jint.Engine.ExecuteStatement (Jint.Parser.Ast.Statement statement) [0x001ca] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Engine.cs:391
      at Jint.Runtime.StatementInterpreter.ExecuteStatement (Jint.Parser.Ast.Statement statement) [0x00001] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Runtime\StatementInterpreter.cs:23
      at Jint.Runtime.StatementInterpreter.ExecuteStatementList (System.Collections.Generic.IEnumerable 1[T] statementList) [0x00029] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Runtime\StatementInterpreter.cs:425
      at Jint.Runtime.StatementInterpreter.ExecuteProgram (Jint.Parser.Ast.Program program) [0x00001] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Runtime\StatementInterpreter.cs:503
      at Jint.Engine.Execute (Jint.Parser.Ast.Program program) [0x00051] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Engine.cs:322
      at Jint.Engine.Execute (System.String source) [0x00007] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\Jint\Engine.cs:302
      at PowerUI.JavaScriptEngine.Compile (System.String source) [0x0001a] in C:\Users\eivan\OneDrive\Documents\unitys\project\Achdus\Assets\PowerUI\Source\JavaScript\JavaScriptEngine.cs:213
    UnityEngine.Debug:Log(Object)
    PowerUI.UI:OnLogMessage(String) (at Assets/PowerUI/Source/Engine/UI.cs:430)
    Dom.Log:Add(String) (at Assets/PowerUI/Source/Dom/Log.cs:34)
    PowerUI.JavaScriptEngine:Compile(String) (at Assets/PowerUI/Source/JavaScript/JavaScriptEngine.cs:237)
    PowerUI.ScriptEngine:TryCompile() (at Assets/PowerUI/Source/Engine/Script Engines/ScriptEngine.cs:163)
    PowerUI.HtmlDocument:TryCompile() (at Assets/PowerUI/Source/Engine/Document/Document-Scripting.cs:98)
    PowerUI.HtmlDocument:close() (at Assets/PowerUI/Source/Engine/Document/Document.cs:297)
    PowerUI.HtmlDocument:set_innerHTML(String) (at Assets/PowerUI/Source/Engine/Document/Document.cs:697)
    PowerUI.UI:set_Html(String) (at Assets/PowerUI/Source/Engine/UI.cs:715)
    Achdus.Yaakov:CompileJavaScript(String) (at Assets/COBY.cs:323)
    COBY:Start() (at Assets/COBY.cs:311)

Это также происходит, когда я пытаюсь передать другие функции в качестве аргументов и т. Д. *

Кто-нибудь знает исправление для этого, возможно, с использованием исходного кода powerUI?

...