public IImageComponent SetImage(UnityEngine.UI.Windows.Plugins.Localization.LocalizationKey key, params object[] parameters)
        {
            this.lastImageLocalization           = true;
            this.lastImageLocalizationKey        = key;
            this.lastImageLocalizationParameters = parameters;

            //this.SetImage(UnityEngine.UI.Windows.Plugins.Localization.LocalizationSystem.GetSprite(key, parameters));
            WindowSystemResources.Unload(this, this.GetResource());
            WindowSystemResources.Load(this, onDataLoaded: null, onComplete: null, customResourcePath: UnityEngine.UI.Windows.Plugins.Localization.LocalizationSystem.GetSpritePath(key, parameters));

            return(this);
        }
        private void InitInstance(System.Action <WindowComponent> callback = null, bool async = false)
        {
            if (this.instance != null)
            {
                //this.instance.OnInit();
                if (callback != null)
                {
                    callback.Invoke(this.instance);
                }
            }
            else
            {
                if (this.prefabNoResource != null)
                {
                    this.Load_INTERNAL(this.prefabNoResource);
                    if (callback != null)
                    {
                        callback.Invoke(this.instance);
                    }
                }
                else
                {
                    if (this.prefabResource.IsLoadable() == true)
                    {
                        WindowSystemResources.LoadRefCounter <WindowComponent>(this, this.prefabResource, (asset) => {
                            this.Load_INTERNAL(asset);
                            WindowSystemResources.Unload(this, this.prefabResource, resetController: false);

                            if (callback != null)
                            {
                                callback.Invoke(asset);
                            }
                        }, () => {
                            if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                            {
                                UnityEngine.Debug.LogError(string.Format("[LinkerComponent] Failed to load prefab at path `{0}`", this.prefabResource.assetPath), this);
                            }
                            if (callback != null)
                            {
                                callback.Invoke(null);
                            }
                        }, this.prefabResource.async || async);
                    }
                    else
                    {
                        if (callback != null)
                        {
                            callback.Invoke(null);
                        }
                    }
                }
            }
        }
示例#3
0
        private System.Collections.Generic.IEnumerator <byte> SetImage_INTERNAL(ResourceAuto resource, System.Action onDataLoaded = null, System.Action onComplete = null, System.Action onFailed = null)
        {
            yield return(0);

            if (this.imageCrossFadeModule.IsValid() == true)
            {
                this.imageCrossFadeModule.Prepare(this);
            }

            var oldResource = this.imageResource;
            var newResource = resource;

            this.imageResource = resource;

            // if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Loading resource: " + this.imageResource.GetId());
            WindowSystemResources.Load(this,
                                       onDataLoaded: onDataLoaded,
                                       onComplete: () => {
                //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Resource loaded: " + newResource.GetId() + " :: " + this.name, this);
                if (newResource.GetId() != oldResource.GetId())
                {
                    // if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Unloading: " + newResource.GetId() + " != " + oldResource.GetId() + " :: " + this.name, this);
                    WindowSystemResources.Unload(this, oldResource, resetController: false);
                }


                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
            },
                                       onFailed: () => {
                //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Resource loading failed: " + newResource.GetId() + " :: " + this.name, this);
                if (newResource.GetId() != oldResource.GetId())
                {
                    //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Failed, Unloading: " + this.imageResource.GetId() + " != " + oldResource.GetId() + " :: " + this.name, this);
                    WindowSystemResources.Unload(this, oldResource, resetController: false);
                }

                if (onFailed != null)
                {
                    onFailed.Invoke();
                }
            }
                                       );
        }
示例#4
0
        public IImageComponent SetImage(AutoResourceItem resource, System.Action onDataLoaded = null, System.Action onComplete = null, System.Action onFailed = null)
        {
            var oldResource = this.imageResource;

            this.imageResource = resource;

            //Debug.Log("Loading resource: " + this.imageResource.GetId());
            WindowSystemResources.Load(this,
                                       onDataLoaded: onDataLoaded,
                                       onComplete: () => {
                //Debug.Log("Resource loaded: " + newResource.GetId() + " :: " + this.name, this);
                if (this.imageResource.GetId() != oldResource.GetId())
                {
                    //Debug.Log("Unloading: " + this.imageResource.GetId() + " != " + oldResource.GetId() + " :: " + this.name, this);
                    WindowSystemResources.Unload(this, oldResource, resetController: false);
                }

                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
            },
                                       onFailed: () => {
                //Debug.Log("Resource loading failed: " + newResource.GetId() + " :: " + this.name, this);
                if (this.imageResource.GetId() != oldResource.GetId())
                {
                    //Debug.Log("Failed, Unloading: " + this.imageResource.GetId() + " != " + oldResource.GetId() + " :: " + this.name, this);
                    WindowSystemResources.Unload(this, oldResource, resetController: false);
                }

                if (onFailed != null)
                {
                    onFailed.Invoke();
                }
            }
                                       );

            return(this);
        }
        public IImageComponent Unload(ResourceBase resource)
        {
            WindowSystemResources.Unload(this, resource);

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