예제 #1
0
        protected override void OnPaint()
        {
            _isEditorRuntime = EditorGUILayout.Toggle("EditorRuntime", _isEditorRuntime);
            if (_isEditorRuntime)
            {
                EditorRuntime.GetInstance();
            }
            var runtime   = ScriptEngine.GetRuntime(_isEditorRuntime);
            var available = runtime != null;

            using (new EditorGUI.DisabledGroupScope(!available))
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    _text = EditorGUILayout.TextField(">", _text);
                    if (GUILayout.Button("Run", GUILayout.Width(36f)))
                    {
                        using (var ret = runtime.GetMainContext().EvalSource <ScriptValue>(_text, "eval"))
                        {
                            _rvalToString  = ret.ToString() ?? "";
                            _rvalToString += "\n\n";
                            _rvalToString += ret.JSONStringify();
                        }
                    }
                }
            }

            EditorGUILayout.TextArea(_rvalToString);

            if (!available)
            {
                EditorGUILayout.HelpBox("Runtime Not Available", MessageType.Warning);
            }
        }
예제 #2
0
        static EditorRuntime()
        {
            var prefs = Prefs.Load();

            if (prefs.editorScripting)
            {
                _instance = new EditorRuntime();
            }
        }
예제 #3
0
        static EditorRuntime()
        {
            var prefs = UnityHelper.LoadPrefs();

            if (prefs.editorScripting)
            {
                _instance = new EditorRuntime(prefs);
            }
        }
예제 #4
0
 static EditorRuntime()
 {
     _instance = new EditorRuntime();
 }
예제 #5
0
        private static void CallJavascript(AssetPostprocessor proc, string funcName, params object[] args)
        {
            var rt = EditorRuntime.GetRuntime();

            if (rt != null)
            {
                var context    = rt.GetMainContext();
                var ctx        = (JSContext)context;
                var globalThis = context.GetGlobalObject();
                var func       = JSApi.JS_GetProperty(ctx, globalThis, context.GetAtom(funcName));

                if (JSApi.JS_IsFunction(ctx, func) == 1)
                {
                    var arglist = new List <JSValue>();
                    do
                    {
                        if (proc != null)
                        {
                            var val = Values.js_push_var(ctx, proc);
                            if (val.IsException())
                            {
                                ctx.print_exception();
                                break;
                            }
                            arglist.Add(val);
                        }

                        var err = false;
                        for (var i = 0; i < args.Length; i++)
                        {
                            var val = Values.js_push_var(ctx, args[i]);
                            if (val.IsException())
                            {
                                ctx.print_exception();
                                err = true;
                                break;
                            }
                            arglist.Add(val);
                        }

                        if (err)
                        {
                            break;
                        }

                        var argv = arglist.ToArray();
                        var rval = JSApi.JS_Call(ctx, func, globalThis, argv.Length, argv);

                        if (rval.IsException())
                        {
                            ctx.print_exception();
                        }

                        JSApi.JS_FreeValue(ctx, rval);
                    } while (false);

                    for (var i = 0; i < arglist.Count; i++)
                    {
                        JSApi.JS_FreeValue(ctx, arglist[i]);
                    }
                }

                JSApi.JS_FreeValue(ctx, func);
                JSApi.JS_FreeValue(ctx, globalThis);
            }
        }