Beispiel #1
0
            public IWindowEventsAsync Create(WindowBase window, WindowLayoutElement root)
            {
                this.root = root;

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

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

                var instance = this.component.Spawn();

                instance.SetParent(root, setTransformAsSource: false);
                instance.SetTransformAs();

                var rect = instance.transform as RectTransform;

                rect.sizeDelta        = (this.component.transform as RectTransform).sizeDelta;
                rect.anchoredPosition = (this.component.transform as RectTransform).anchoredPosition;

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

                instance.transform.SetSiblingIndex(this.sortingOrder);

                this.instance = instance;

                return(instance);
            }
            public void Unload()
            {
                //Debug.Log("Unload: " + this.componentResource.GetId() + " :: " + this.componentResource.assetPath);

                WindowSystemResources.UnloadResource_INTERNAL(this.GetReference(), this.componentResource);

                if (this.root != null)
                {
                    this.root.OnWindowUnload();
                }

                this.instance = null;
                this.root     = null;
                this.window   = null;

                /*if (this.componentResource.loadableResource == true) {
                 *
                 *      this.componentResource.Unload();
                 *
                 * } else {
                 *
                 *      // Resource was not load via Resources.Load(), so it can't be unload properly
                 *
                 * }*/
            }
Beispiel #3
0
            public IWindowEventsAsync Create(WindowBase window, WindowLayoutElement root)
            {
                this.root = root;

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

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

                var instance = this.component.Spawn();

                //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        = (this.component.transform as RectTransform).sizeDelta;
                    rect.anchoredPosition = (this.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;

                return(instance);
            }
            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);
            }
Beispiel #5
0
            public IWindowEventsAsync Create(WindowBase window, WindowLayoutElement root)
            {
                this.root = root;

                WindowComponent component = null;

                if (this.componentResource.loadableResource == true)
                {
                    component = this.componentResource.Load <WindowComponent>();
                    if (component == null)
                    {
                        Debug.LogError("[ Layout ] Be sure your UI project placed in Resources folder (ex: Assets/Resources/MyProject/UIProject.asset).");
                    }
                }
                else
                {
                    component = this.componentNoResource;
                }

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

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

                var instance = component.Spawn();

                //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;

                return(instance);
            }
Beispiel #6
0
            public IWindowEventsAsync Create(WindowBase window, WindowLayoutElement root)
            {
                this.root = root;

                WindowComponent component = null;

                if (this.componentResource.loadableResource == true)
                {
                    component = this.componentResource.Load <WindowComponent>();
                    if (component == null)
                    {
                        Debug.LogError("[ Layout ] Be sure your UI project placed in Resources folder (ex: Assets/Resources/MyProject/UIProject.asset).");
                    }
                }
                else
                {
                    component = this.componentNoResource;
                                        #if UNITY_EDITOR
                    if (component != 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.", component.name, UnityEditor.AssetDatabase.GetAssetPath(component.GetInstanceID()), window.name);
                    }
                                        #endif
                }

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

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

                var instance = component.Spawn();
                //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;

                return(instance);
            }