Exemplo n.º 1
0
        public void OnComplete(ScriptRuntime runtime)
        {
            if (!runtime.isWorker)
            {
                _mConsole.Write(LogLevel.Info, "run");
                _rt.EvalMain(entryFileName);

                // // 测试, 获取脚本本身返回值
                // var act = _rt.EvalFile<Action>("do_from_cs");
                // if (act != null)
                // {
                //     act();
                // }
                // else
                // {
                //     Debug.LogWarning("act null");
                // }
                // var v = _rt.EvalFile<ScriptValue>("do_from_cs_v");
                // if (v != null)
                // {
                //     Debug.LogFormat("v.test = {0}", v.GetProperty<string>("test"));
                // }
                // else
                // {
                //     Debug.LogWarning("v null");
                // }
            }
        }
Exemplo n.º 2
0
 public void OnComplete(ScriptRuntime runtime)
 {
     if (!runtime.isWorker)
     {
         _runtime.EvalMain("editor/main");
     }
 }
Exemplo n.º 3
0
 public void OnComplete(ScriptRuntime runtime)
 {
     if (!runtime.isWorker)
     {
         _rt.EvalMain(entryFileName);
     }
 }
Exemplo n.º 4
0
        private void OnScriptRuntimeInitialized(ScriptRuntime runtime)
        {
            var tsconfig = GetTSConfig();

            if (tsconfig != null)
            {
                runtime.AddSearchPath(tsconfig.compilerOptions.outDir);
            }

            runtime.EvalMain(_prefs.editorEntryPoint);

            foreach (var module in _prefs.editorRequires)
            {
                runtime.ResolveModule(module);
            }

            var editorScripts = new List <JSScriptClassPathHint>();

            JSScriptFinder.GetInstance().ModuleSourceChanged += OnModuleSourceChanged;
            JSScriptFinder.GetInstance().Search(JSScriptClassType.Editor, editorScripts);
            foreach (var editorScript in editorScripts)
            {
                runtime.ResolveModule(editorScript.modulePath);
            }
        }
Exemplo n.º 5
0
 public void OnComplete(ScriptRuntime runtime)
 {
     if (!runtime.isWorker)
     {
         _runtime.EvalMain("main.js");
     }
 }
Exemplo n.º 6
0
        void Awake()
        {
            IFileSystem fileSystem;

            _mConsole = new MiniConsole(scrollRect, text, 100);
            _rt       = ScriptEngine.CreateRuntime();
            var asyncManager = new DefaultAsyncManager();
            var pathResolver = new PathResolver();

            pathResolver.AddSearchPath("node_modules");

            if (fileLoader == FileLoader.Resources)
            {
                fileSystem = new ResourcesFileSystem(_mConsole);
                pathResolver.AddSearchPath("dist"); // 这里的路径相对于 Unity Resources 空间
            }
            else if (fileLoader == FileLoader.HMR)
            {
                Debug.LogWarningFormat("功能未完成");
                fileSystem = new HttpFileSystem(_mConsole, baseUrl);
            }
            else
            {
                // 演示了一般文件系统的访问, 实际项目中典型的情况需要自行实现基于 AssetBundle(或 7z/zip) 的文件访问层
                fileSystem = new DefaultFileSystem(_mConsole);
                pathResolver.AddSearchPath("Scripts/out");
                // pathResolver.AddSearchPath("../Scripts/out");
                // _rt.AddSearchPath("Assets/Examples/Scripts/dist");
            }

            _rt.withStacktrace = stacktrace;
            if (sourceMap)
            {
                _rt.EnableSourceMap();
            }
            _rt.AddModuleResolvers();
            _rt.extraBinding = (runtime, register) =>
            {
                FSWatcher.Bind(register);
                QuickJS.Extra.WebSocket.Bind(register);
                QuickJS.Extra.XMLHttpRequest.Bind(register);
                if (!runtime.isWorker)
                {
                    var uri = new Uri(baseUrl);
                    QuickJS.Extra.DOMCompatibleLayer.Bind(register, uri);
                    QuickJS.Extra.NodeCompatibleLayer.Bind(register);
                }
            };
            _rt.Initialize(new ScriptRuntimeArgs
            {
                fileSystem          = fileSystem,
                pathResolver        = pathResolver,
                asyncManager        = asyncManager,
                logger              = _mConsole,
                byteBufferAllocator = new ByteBufferPooledAllocator(),
                binder              = DefaultBinder.GetBinder(useReflectBind),
            });
            _rt.EvalMain(entryFileName);
        }
Exemplo n.º 7
0
 public void OnComplete(ScriptRuntime runtime)
 {
     if (!runtime.isWorker)
     {
         _mConsole.Write(LogLevel.Info, "run");
         _rt.EvalMain("main.js");
     }
 }
Exemplo n.º 8
0
 public void OnComplete(ScriptRuntime runtime)
 {
     if (!runtime.isWorker)
     {
         _ready = true;
         var prefs = Prefs.Load();
         _runtime.EvalMain(prefs?.editorEntryPoint);
     }
 }
Exemplo n.º 9
0
 public void OnComplete(ScriptRuntime runtime)
 {
     if (!runtime.isWorker)
     {
         _ready = true;
         var prefs = Prefs.Load();
         if (prefs != null && !string.IsNullOrEmpty(prefs.editorEntryPoint))
         {
             _runtime.EvalMain(prefs.editorEntryPoint);
         }
     }
 }
Exemplo n.º 10
0
 public void OnComplete(ScriptRuntime runtime)
 {
     _rt.EvalMain("Assets/Examples/Scripts/out/main.js");
 }