Beispiel #1
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);
        }
Beispiel #2
0
        public EditorContext(VisualElement hostElement, StringObjectDictionary globals, ReactScript script, IDispatcher dispatcher, IUnityScheduler scheduler, bool isDevServer, ReactWindow editor, Action onRestart = null)
            : base(globals, script, dispatcher, scheduler, isDevServer, onRestart, true)
        {
            Editor = editor;
            Host   = new HostComponent(hostElement, this);
            InsertStyle(EditorResourcesHelper.UseragentStylesheet?.text, -1);
            Host.ResolveStyle(true);

            hostElement.styleSheets.Add(EditorResourcesHelper.UtilityStylesheet);

            dispatcher.AddCallOnLateUpdate(() =>
            {
                if (Scheduled)
                {
                    Scheduled = false;

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