예제 #1
0
        public UnityUGUIContext(RectTransform hostElement, Jint.Engine engine, StringObjectDictionary assets, ReactScript script, bool isDevServer)
        {
            Engine      = engine;
            Globals     = assets;
            Script      = script;
            IsDevServer = isDevServer;

            Parser    = new StylesheetParser(true, true, true, true, true);
            StyleTree = new StyleTree(Parser);

            Host           = new HostComponent(hostElement, this);
            Host.Tag       = "_root";
            RootLayoutNode = Host.Layout;

            InsertStyle(ResourcesHelper.UseragentStylesheet?.text, -1);
            Host.ResolveStyle(true);

            MainThreadDispatcher.AddCallOnLateUpdate(() =>
            {
                if (Scheduled)
                {
                    RootLayoutNode.CalculateLayout();
                    Scheduled = false;

                    for (int i = 0; i < ScheduledCallbacks.Count; i++)
                    {
                        ScheduledCallbacks[i]?.Invoke();
                    }
                }
            });
        }
예제 #2
0
        public virtual ReactScript CreateStaticScript(string path)
        {
            var src = new ReactScript();

            src.ScriptSource = IsDevServer ? ScriptSource.Url : Script.ScriptSource;
            src.UseDevServer = IsDevServer;
            src.SourcePath   = ResolvePath(path);

            return(src);
        }
예제 #3
0
        private IDisposable LoadAndRun(ReactScript script, bool disableWarnings = false)
        {
            dispatcher = Application.isPlaying ? RuntimeDispatcher.Create() as IDispatcher : new EditorDispatcher();
            runner = new ReactUnityRunner();
            var watcherDisposable = script.GetScript((code, isDevServer) =>
            {
                ctx = new UGUIContext(Root, Globals, script, dispatcher, new UnityScheduler(dispatcher), isDevServer, Render);
                runner.RunScript(code, ctx, BeforeStart, AfterStart);
            }, dispatcher, true, disableWarnings);

            return watcherDisposable;
        }
예제 #4
0
        private IDisposable LoadAndRun(ReactScript script, List <TextAsset> preload, Action callback = null, bool disableWarnings = false)
        {
            dispatcher = Application.isPlaying ? RuntimeDispatcher.Create() as IDispatcher : new EditorDispatcher();
            runner     = new ReactUnityRunner();
            var watcherDisposable = script.GetScript((code, isDevServer) =>
            {
                ctx = new UGUIContext(Root, Globals, script, dispatcher, new UnityScheduler(dispatcher), isDevServer, Restart);
                runner.RunScript(code, ctx, preload, callback);
            }, dispatcher, true, disableWarnings);

            return(watcherDisposable);
        }
예제 #5
0
        void CreateLocation(Jint.Engine engine, ReactScript script)
        {
            var location = new DomProxies.Location(script.SourceLocation, Restart);

            engine.SetValue("location", location);

#if UNITY_EDITOR
            engine.SetValue("WebSocket", typeof(WebSocketProxy));
            engine.SetValue("oldXMLHttpRequest", typeof(XMLHttpRequest));
            engine.Execute(@"XMLHttpRequest = function() { return new oldXMLHttpRequest('" + location.origin + @"'); }");
#endif
            engine.SetValue("document", new DocumentProxy(unityContext, this, location.origin));
        }
예제 #6
0
        public ReactContext(StringObjectDictionary globals, ReactScript script, IDispatcher dispatcher,
                            IUnityScheduler scheduler, bool isDevServer, Action onRestart, bool mergeLayouts = false)
        {
            Globals           = globals;
            Script            = script;
            IsDevServer       = isDevServer;
            Scheduler         = scheduler;
            Dispatcher        = dispatcher;
            OnRestart         = onRestart ?? (() => { });
            this.mergeLayouts = mergeLayouts;

            Parser    = new StylesheetParser(true, true, true, true, true);
            StyleTree = new StyleTree(Parser);
        }
예제 #7
0
        private void LoadAndRun(ReactScript script, List <TextAsset> preload, Action callback = null, bool disableWarnings = false)
        {
            MainThreadDispatcher.Initialize();
            int debounce = -1;

            ScriptWatchDisposable = script.GetScript((code, isDevServer) =>
            {
                if (debounce >= 0)
                {
                    MainThreadDispatcher.StopDeferred(debounce);
                }
                debounce = MainThreadDispatcher.Timeout(() => RunScript(code, isDevServer, script, preload, callback), 0.5f);
            }, out var result, true, disableWarnings);
            RunScript(result, false, script, preload, callback);
        }
예제 #8
0
        public UGUIContext(RectTransform hostElement, GlobalRecord globals, ReactScript script, IDispatcher dispatcher, IUnityScheduler scheduler, bool isDevServer, Action onRestart)
            : base(globals, script, dispatcher, scheduler, isDevServer, onRestart)
        {
            Host           = new HostComponent(hostElement, this);
            RootLayoutNode = Host.Layout;

            InsertStyle(ResourcesHelper.UseragentStylesheet?.text, -1);
            Host.ResolveStyle(true);

            Action callback = () =>
            {
                if (LayoutScheduled)
                {
                    RootLayoutNode.CalculateLayout();
                    LayoutScheduled = false;
                }
            };

            dispatcher.OnEveryLateUpdate(callback);
        }
예제 #9
0
        public UGUIContext(RectTransform hostElement, StringObjectDictionary globals, ReactScript script, IDispatcher dispatcher, IUnityScheduler scheduler, bool isDevServer, Action onRestart)
            : base(globals, script, dispatcher, scheduler, isDevServer, onRestart)
        {
            Host           = new HostComponent(hostElement, this);
            RootLayoutNode = Host.Layout;

            InsertStyle(ResourcesHelper.UseragentStylesheet?.text, -1);
            Host.ResolveStyle(true);

            Action callback = () =>
            {
                if (Scheduled)
                {
                    RootLayoutNode.CalculateLayout();
                    Scheduled = false;

                    for (int i = 0; i < ScheduledCallbacks.Count; i++)
                    {
                        ScheduledCallbacks[i]?.Invoke();
                    }
                }
            };

            dispatcher.AddCallOnLateUpdate(callback);
        }