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(); } } }); }
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); }
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; }
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); }
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)); }
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); }
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); }
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); }
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); }