public void Create(WindowBase window, Transform root, float depth, int raycastPriority, int orderInLayer, System.Action callback, bool async)
        {
            if (this.stopped == true)
            {
                return;
            }

            this.window = window;

            System.Action <WindowLayout> onLoaded = (layout) => {
                if (this.stopped == true)
                {
                    return;
                }

                var instance = layout.Spawn(activeByDefault: false);
                instance.transform.SetParent(root);
                instance.transform.localPosition = Vector3.zero;
                instance.transform.localRotation = Quaternion.identity;
                instance.transform.localScale    = Vector3.one;

                var rect = instance.transform as RectTransform;
                rect.sizeDelta        = (layout.transform as RectTransform).sizeDelta;
                rect.anchoredPosition = (layout.transform as RectTransform).anchoredPosition;

                var layoutPreferences = this.layoutPreferences;
                if (this.allowCustomLayoutPreferences == true)
                {
                    layoutPreferences = WindowSystem.GetCustomLayoutPreferences() ?? this.layoutPreferences;
                }

                instance.Setup(window);
                instance.Init(depth, raycastPriority, orderInLayer);
                instance.SetLayoutPreferences(this.scaleMode, this.fixedScaleResolution, layoutPreferences);

                this.instance = instance;

                ME.Utilities.CallInSequence(() => {
                    if (this.stopped == true)
                    {
                        return;
                    }

                    instance.gameObject.SetActive(true);
                    callback.Invoke();
                }, this.components, (component, c) => {
                    component.Create(window, instance.GetRootByTag(component.tag), (comp) => c.Invoke(), async);
                }, waitPrevious: true);
            };

            WindowLayout loadedComponent = null;

            if (this.layoutResource.IsLoadable() == true)
            {
                WindowSystemResources.LoadRefCounter <WindowLayout>(this, (layout) => {
                    loadedComponent = layout;
                    onLoaded.Invoke(loadedComponent);

                    WindowSystemResources.Unload(this, this.GetResource(), resetController: false);
                }, () => {
                                        #if UNITY_EDITOR
                    Debug.LogWarningFormat("[ Layout ] Resource request failed {0} [{1}].", UnityEditor.AssetDatabase.GetAssetPath(this.layout.GetInstanceID()), window.name);
                                        #endif
                }, async);
                return;
            }
            else
            {
                loadedComponent = this.layoutNoResource;
                                #if UNITY_EDITOR
                if (loadedComponent != null)
                {
                    Debug.LogWarningFormat("[ Layout ] Resource `{0}` [{1}] should be placed in `Resources` folder to be loaded/unloaded automaticaly. Window `{2}` requested this resource. This warning shown in editor only.", loadedComponent.name, UnityEditor.AssetDatabase.GetAssetPath(loadedComponent.GetInstanceID()), window.name);
                }
                                #endif
            }

            onLoaded.Invoke(loadedComponent);
        }
        public IImageComponent Unload(ResourceBase resource)
        {
            WindowSystemResources.Unload(this, resource);

            return(this);
        }
            public void Create(WindowBase window, WindowLayoutElement root, System.Action <WindowComponent> callback = null, bool async = false, System.Action <WindowObjectElement> onItem = null)
            {
                if (this.stopped == true)
                {
                    return;
                }

                this.window = window;
                this.root   = root;

                System.Action <WindowComponent> onLoaded = (component) => {
                    if (this.stopped == true)
                    {
                        return;
                    }

                    if (component == null && this.root == null)
                    {
                        if (callback != null)
                        {
                            callback.Invoke(null);
                        }
                        return;
                    }

                    if (component == null)
                    {
                        this.root.Setup(null, this);
                        if (callback != null)
                        {
                            callback.Invoke(null);
                        }
                        return;
                    }

                    //Debug.Log("Unpack component: " + component.name);
                    var instance = component.Spawn(activeByDefault: false);
                    //instance.SetComponentState(WindowObjectState.NotInitialized);
                    instance.SetParent(root, setTransformAsSource: false, worldPositionStays: false);
                    instance.SetTransformAs();

                    if (this.componentParameters != null)
                    {
                        instance.Setup(this.componentParameters);
                    }

                    var rect = instance.transform as RectTransform;
                    if (rect != null)
                    {
                        rect.sizeDelta        = (component.transform as RectTransform).sizeDelta;
                        rect.anchoredPosition = (component.transform as RectTransform).anchoredPosition;
                    }

                    this.root.Setup(instance, this);
                    instance.Setup(window);

                    if (instance.autoRegisterInRoot == true && root.autoRegisterSubComponents == true)
                    {
                        root.RegisterSubComponent(instance);
                    }

                    instance.transform.SetSiblingIndex(this.sortingOrder);

                    this.instance = instance;
                    instance.DoLoad(async, onItem, () => {
                        if (this.stopped == true)
                        {
                            return;
                        }

                        //if (instance != null) instance.gameObject.SetActive(true);
                        if (callback != null)
                        {
                            callback.Invoke(this.instance as WindowComponent);
                        }
                    });
                };

                WindowComponent loadedComponent = null;

                if (this.componentResource.IsLoadable() == true)
                {
                    WindowSystemResources.LoadRefCounter <WindowComponent>(this, (component) => {
                        loadedComponent = component;
                        onLoaded.Invoke(loadedComponent);

                        WindowSystemResources.Unload(this, this.GetResource(), resetController: false);
                    }, () => {
                                                #if UNITY_EDITOR
                        Debug.LogWarningFormat("[ Layout ] Resource request failed {0} [{1}].", UnityEditor.AssetDatabase.GetAssetPath(this.component.GetInstanceID()), window.name);
                                                #endif
                    }, async);
                    return;
                }
                else
                {
                    loadedComponent = this.componentNoResource;
                                        #if UNITY_EDITOR
                    if (loadedComponent != null)
                    {
                        Debug.LogWarningFormat("[ Layout ] Resource `{0}` [{1}] should be placed in `Resources` folder to be loaded/unloaded automaticaly. Window `{2}` requested this resource. This warning shown in editor only.", loadedComponent.name, UnityEditor.AssetDatabase.GetAssetPath(loadedComponent.GetInstanceID()), window.name);
                    }
                                        #endif
                }

                onLoaded.Invoke(loadedComponent);
            }