Exemplo n.º 1
0
        private IEnumerator InitLayoutInstance(LayoutWindowType windowInstance, WindowObject root, WindowLayout windowLayout, HashSet <WindowLayout> used, System.Action onComplete, bool isInner = false)
        {
            if (((ILayoutInstance)root).windowLayoutInstance != null)
            {
                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
                yield break;
            }

            if (windowLayout.createPool == true)
            {
                WindowSystem.GetPools().CreatePool(windowLayout);
            }
            var windowLayoutInstance = WindowSystem.GetPools().Spawn(windowLayout, root.transform);

            windowLayoutInstance.isRootLayout = (isInner == false);

            if (isInner == true)
            {
                windowLayoutInstance.canvasScaler.enabled = false;
            }

            windowLayoutInstance.Setup(windowInstance);
            windowLayoutInstance.SetCanvasOrder(0);
            root.RegisterSubObject(windowLayoutInstance);
            ((ILayoutInstance)root).windowLayoutInstance = windowLayoutInstance;
            this.ApplyLayoutPreferences(this.layoutPreferences);

            windowLayoutInstance.SetTransformFullRect();

            used.Add(this.windowLayout);
            var arr = this.components;

            for (int i = 0; i < arr.Length; ++i)
            {
                var layoutComponent = arr[i];
                if (layoutComponent.windowLayout != windowLayout)
                {
                    continue;
                }

                var layoutElement = windowLayoutInstance.GetLayoutElementByTagId(layoutComponent.tag);
                if (layoutComponent.componentInstance == null)
                {
                    layoutElement.Setup(windowInstance);

                    if (layoutComponent.component.IsEmpty() == false)
                    {
                        var index     = i;
                        var resources = WindowSystem.GetResources();
                        var loaded    = false;
                        yield return(resources.LoadAsync <WindowComponent>(windowInstance, layoutComponent.component, (asset) => {
                            if (asset == null)
                            {
                                Debug.LogWarning("Component is null while component resource not empty. Skipped.");
                                return;
                            }

                            var instance = layoutElement.Load(asset);
                            instance.SetInvisible();
                            layoutComponent.componentInstance = instance;
                            arr[index] = layoutComponent;

                            instance.DoLoadScreenAsync(() => { loaded = true; });
                        }));

                        while (loaded == false)
                        {
                            yield return(null);
                        }
                    }

                    arr[i] = layoutComponent;
                }

                if (layoutElement.innerLayout != null)
                {
                    if (used.Contains(layoutElement.innerLayout) == false)
                    {
                        yield return(this.InitLayoutInstance(windowInstance, layoutElement, layoutElement.innerLayout, used, null, isInner: true));
                    }
                    else
                    {
                        Debug.LogWarning("Ignoring inner layout because of a cycle");
                    }
                }
            }

            if (onComplete != null)
            {
                onComplete.Invoke();
            }
        }
Exemplo n.º 2
0
        private IEnumerator InitLayoutInstance(LayoutWindowType windowInstance, WindowObject root, WindowLayout windowLayout, HashSet <WindowLayout> used, System.Action onComplete, bool isInner = false)
        {
            if (((ILayoutInstance)root).windowLayoutInstance != null)
            {
                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
                yield break;
            }

            if (windowLayout.createPool == true)
            {
                WindowSystem.GetPools().CreatePool(windowLayout);
            }
            var windowLayoutInstance = WindowSystem.GetPools().Spawn(windowLayout, root.transform);

            windowLayoutInstance.isRootLayout = (isInner == false);

            if (isInner == true)
            {
                windowLayoutInstance.canvasScaler.enabled = false;
            }

            windowLayoutInstance.Setup(windowInstance);
            windowLayoutInstance.SetCanvasOrder(0);
            root.RegisterSubObject(windowLayoutInstance);
            ((ILayoutInstance)root).windowLayoutInstance = windowLayoutInstance;
            this.ApplyLayoutPreferences(this.layoutPreferences);

            windowLayoutInstance.SetTransformFullRect();

            used.Add(this.windowLayout);

            this.loadingCount = 0;
            var arr = this.components;

            for (int i = 0; i < arr.Length; ++i)
            {
                var layoutComponent = arr[i];
                if (layoutComponent.windowLayout != windowLayout)
                {
                    continue;
                }

                var layoutElement = windowLayoutInstance.GetLayoutElementByTagId(layoutComponent.tag);
                layoutComponent.componentInstance = windowLayoutInstance.GetLoadedComponent(layoutComponent.tag);
                layoutElement.Setup(windowInstance);
                arr[i] = layoutComponent;

                if (layoutComponent.componentInstance == null)
                {
                    if (layoutComponent.component.IsEmpty() == false)
                    {
                        var resources = WindowSystem.GetResources();
                        var data      = new LoadingClosure()
                        {
                            index   = i,
                            element = layoutElement,
                            windowLayoutInstance = windowLayoutInstance,
                            layoutComponentItems = arr,
                            instance             = this,
                        };
                        ++this.loadingCount;
                        yield return(resources.LoadAsync <WindowComponent, LoadingClosure>(windowInstance, data, layoutComponent.component, (asset, closure) => {
                            if (asset == null)
                            {
                                Debug.LogWarning("Component is null while component resource is not empty. Skipped.");
                                return;
                            }

                            ref var item = ref closure.layoutComponentItems[closure.index];

                            var instance = closure.element.Load(asset);
                            instance.SetInvisible();
                            closure.windowLayoutInstance.SetLoadedComponent(item.tag, instance);
                            item.componentInstance = instance;

                            instance.DoLoadScreenAsync(() => { --closure.instance.loadingCount; });
                        }));