Ejemplo n.º 1
0
        void RunScript(string script, bool isDevServer, ReactScript scriptObj, List <TextAsset> preload = null, Action callback = null)
        {
            if (string.IsNullOrWhiteSpace(script))
            {
                return;
            }

            Clean();

            if (engine == null)
            {
                CreateEngine();
            }
            unityContext = new UnityUGUIContext(Root, engine, Globals, scriptObj, isDevServer);
            CreateLocation(engine, scriptObj);

            List <Action> callbacks = new List <Action>()
            {
                callback
            };

            engine.SetValue("addEventListener", new Action <string, Action>((e, f) =>
            {
                if (e == "DOMContentLoaded")
                {
                    callbacks.Add(f);
                }
            }));

            engine.SetValue("Unity", new ReactUnityAPI(engine));
            engine.SetValue("RootContainer", unityContext.Host);
            engine.SetValue("Globals", Globals);
            try
            {
                if (preload != null)
                {
                    preload.ForEach(x => engine.Execute(x.text));
                }
                engine.Execute(script);
                callbacks.ForEach(x => x?.Invoke());
            }
            catch (ParserException ex)
            {
                Debug.LogError($"Parser exception in line {ex.LineNumber} column {ex.Column}");
                Debug.LogException(ex);
            }
            catch (Jint.Runtime.JavaScriptException ex)
            {
                Debug.LogError($"JS exception in line {ex.LineNumber} column {ex.Column}");
                Debug.LogException(ex);
            }
            catch (Jint.Runtime.JintException ex)
            {
                Debug.LogException(ex);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Ejemplo n.º 2
0
        void RunScript(string script)
        {
            if (string.IsNullOrWhiteSpace(script))
            {
                return;
            }

            Clean();

            if (engine == null)
            {
                CreateEngine();
            }
            unityContext = new UnityUGUIContext(DocumentRoot, engine, NamedAssets);
            engine.SetValue("Unity", typeof(ReactUnityAPI));
            engine.SetValue("RootContainer", unityContext.Host);
            engine.SetValue("NamedAssets", NamedAssets);
            engine.Execute(script);
        }
Ejemplo n.º 3
0
        void RunScript(string script)
        {
            if (string.IsNullOrWhiteSpace(script))
            {
                return;
            }

            Clean();

            if (engine == null)
            {
                CreateEngine();
            }
            unityContext = new UnityUGUIContext(Root, engine, NamedAssets);
            CreateLocation(engine);

            engine.SetValue("Unity", typeof(ReactUnityAPI));
            engine.SetValue("RootContainer", unityContext.Host);
            engine.SetValue("NamedAssets", NamedAssets);
            try
            {
                PreloadScripts.ForEach(x => engine.Execute(x.text));
                engine.Execute(script);
            }
            catch (ParserException ex)
            {
                Debug.LogError($"Parser exception in line {ex.LineNumber} column {ex.Column}");
                Debug.LogException(ex);
            }
            catch (Exception ex)
            {
                var lastNode = engine.GetLastSyntaxNode();
                Debug.LogError($"Runtime exception in {lastNode.Location.Start.Line}:{lastNode.Location.Start.Column} - {lastNode.Location.End.Line}:{lastNode.Location.End.Column}");
                Debug.LogException(ex);
            }
        }