Esempio n. 1
0
        /// <summary>
        /// Loads the view. Called internally.
        /// </summary>
        protected void LoadInternal(bool initiatedLoad)
        {
            if (IsLoaded)
            {
                return;
            }

            if (LoadMode.HasFlag(LoadMode.Manual) && !initiatedLoad)
            {
                return;
            }

            BeforeLoad();

            foreach (var child in LayoutChildren.ToList())
            {
                child.LoadInternal(false);
            }

            _isLoaded = true;
            AfterChildrenLoaded();
            Initialize();

            LoadDependencyProperties();
            UpdateBindings();

            AfterLoad();

            Loaded?.Invoke(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Called when the texture is changed.
        /// </summary>
        protected virtual void TextureChanged()
        {
            if (GameObject == null)
            {
                return;
            }

            if (LoadMode.HasFlag(LoadMode.HiddenWhileLoading))
            {
                if (Texture != null && Texture.IsLoaded)
                {
                    RawImageComponent.enabled = true;
                }
            }

            // uncomment for tracking texture sets
            //var spriteInfo = Sprite == null ? "null" : String.Format("{0} (IsLoaded: {1})", Sprite.Id, Sprite.IsLoaded);
            //Debugger.Info(String.Format("{0}: Setting Sprite = {1}", Name, spriteInfo), LogCategory.Delight);

            var texture = Texture?.UnityObject;

            if (texture != null && RawImageComponent == null)
            {
                RawImageComponent = GameObject.AddComponent <UnityEngine.UI.RawImage>();
                FastMaterialChanged(); // apply fast material if specified
            }

            if (RawImageComponent != null)
            {
                RawImageComponent.texture = texture;
            }

            ImageChanged();
        }
Esempio n. 3
0
        /// <summary>
        /// Loads the view asynchronously.
        /// </summary>
        protected async Task LoadAsyncInternal(bool initiatedLoad, bool parentAwaitAssets)
        {
            if (IsLoaded)
            {
                return;
            }

            if (LoadMode.HasFlag(LoadMode.Manual) && !initiatedLoad)
            {
                return;
            }

            BeforeLoad();

            bool awaitAssets = parentAwaitAssets || LoadMode.HasFlag(LoadMode.AwaitAssets);
            await Task.WhenAll(LayoutChildren.ToList().Select(x => x.LoadAsyncInternal(false, awaitAssets)));

            _isLoaded = true;
            AfterChildrenLoaded();
            Initialize();

            if (awaitAssets)
            {
                await LoadDependencyPropertiesAsync();
            }
            else
            {
                LoadDependencyProperties();
            }
            UpdateBindings();

            AfterLoad();

            Loaded?.Invoke(this);
        }
Esempio n. 4
0
        /// <summary>
        /// Called after the view is loaded.
        /// </summary>
        protected override void AfterLoad()
        {
            if (IgnoreObject)
            {
                return;
            }
            base.AfterLoad();

            // enable to have fonts pop in instead
            if (LoadMode.HasFlag(LoadMode.HiddenWhileLoading))
            {
                if (Font != null && !Font.IsLoaded)
                {
                    // hide text while loading
                    TextMeshProUGUI.enabled = false;
                }
            }

            if (AutoSize != AutoSize.None)
            {
                // adjust size initially to text
                TextChanged();
            }

            //Debug.Log( "#Delight# Loading Label " + Name );
        }
Esempio n. 5
0
 public async void Start()
 {
     if (!LoadMode.HasFlag(LoadMode.Manual))
     {
         await Load();
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Enables font when loaded.
 /// </summary>
 public virtual void FontChanged()
 {
     if (LoadMode.HasFlag(LoadMode.HiddenWhileLoading))
     {
         if (Font != null && Font.IsLoaded)
         {
             TextComponent.enabled = true;
         }
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Enables font when loaded.
        /// </summary>
        public virtual void FontChanged()
        {
            if (LoadMode.HasFlag(LoadMode.HiddenWhileLoading))
            {
                if (Font != null && Font.IsLoaded)
                {
                    TextMeshProUGUI.enabled = true;
                }
            }

            //Debug.Log( "#Delight# Loading Font: " + Name );
            //TextMeshProUGUI.ForceMeshUpdate();
        }
Esempio n. 8
0
        protected override void AfterLoad()
        {
            base.AfterLoad();

            // enable to have fonts pop in instead
            if (LoadMode.HasFlag(LoadMode.HiddenWhileLoading))
            {
                if (Sprite != null && !Sprite.IsLoaded)
                {
                    // hide image while loading
                    ImageComponent.enabled = false;
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Called after the view is loaded.
        /// </summary>
        protected override void AfterLoad()
        {
            base.AfterLoad();
            if (IgnoreObject)
            {
                return;
            }

            if (LoadMode.HasFlag(LoadMode.HiddenWhileLoading))
            {
                CanvasGroup.alpha = 1; // revert to default
            }

            // update layout and visibility
            VisibilityChanged();
            UpdateLayout(false);
        }
Esempio n. 10
0
        /// <summary>
        /// Called when the sprite is changed.
        /// </summary>
        protected virtual void SpriteChanged()
        {
            if (GameObject == null)
            {
                return;
            }

            if (LoadMode.HasFlag(LoadMode.HiddenWhileLoading))
            {
                if (Sprite != null && Sprite.IsLoaded)
                {
                    ImageComponent.enabled = true;
                }
            }

            // uncomment for tracking sprite sets
            //var spriteInfo = Sprite == null ? "null" : String.Format("{0} (IsLoaded: {1})", Sprite.Id, Sprite.IsLoaded);
            //Debugger.Info(String.Format("{0}: Setting Sprite = {1}", Name, spriteInfo), LogCategory.Delight);

            var sprite = Sprite?.UnityObject;

            if (sprite != null && ImageComponent == null)
            {
                ImageComponent = GameObject.AddComponent <UnityEngine.UI.Image>();
                FastMaterialChanged(); // apply fast material if specified
            }

            if (ImageComponent != null)
            {
                ImageComponent.sprite = sprite;

                if (sprite != null && TypeProperty.IsUndefined(this))
                {
                    // if type is undefined auto-detect if sprite is sliced
                    if (sprite.border != Vector4.zero)
                    {
                        ImageComponent.type = UnityEngine.UI.Image.Type.Sliced;
                    }
                }
            }

            ImageChanged();
        }
Esempio n. 11
0
        /// <summary>
        /// Called after the view is loaded.
        /// </summary>
        protected override void AfterLoad()
        {
            if (IgnoreObject)
            {
                return;
            }
            base.AfterLoad();

            // enable to have fonts pop in instead
            if (LoadMode.HasFlag(LoadMode.HiddenWhileLoading))
            {
                if (Font != null && !Font.IsLoaded)
                {
                    // hide text while loading
                    TextComponent.enabled = false;
                }
            }

            // adjust size initially to text
            TextChanged();
        }
Esempio n. 12
0
        /// <summary>
        /// Called before the view is loaded.
        /// </summary>
        protected override void BeforeLoad()
        {
            // if adjusting size to parent EnableScriptEvents needs to be true before scene object is loaded
            AdjustToParentChanged();

            // load scene object
            base.BeforeLoad();

            // initialize root canvas
            if (LayoutRoot == null)
            {
                var parentUIView = this.FindParent <UIView>(x => !x.IgnoreObject);
                if (parentUIView == null)
                {
                    // we are the root view
                    if (typeof(LayoutRoot).IsAssignableFrom(GetType()))
                    {
                        // we are the layout root
                        LayoutRoot = this as LayoutRoot;
                    }
                    else
                    {
                        // create new layout root
                        var layoutRoot = new LayoutRoot();
                        layoutRoot.Load();
                        LayoutRoot   = layoutRoot;
                        LayoutParent = LayoutRoot;

                        if (!IgnoreObject)
                        {
                            GameObject.transform.SetParent(layoutRoot.GameObject.transform, false);
                        }
                    }
                }
                else
                {
                    // use the same layout root as parent UIView
                    LayoutRoot = parentUIView.LayoutRoot;
                }
            }

            if (IgnoreObject)
            {
                return;
            }

            // add rect transform
            var rectTransform = GameObject.GetComponent <RectTransform>();

            if (rectTransform == null)
            {
                rectTransform = GameObject.AddComponent <RectTransform>();
            }
            RectTransform = rectTransform;

            // if hidden while loading set canvas alpha to zero
            if (LoadMode.HasFlag(LoadMode.HiddenWhileLoading))
            {
                // to change alpha we need a canvas group attached
                if (CanvasGroup == null)
                {
                    var canvasGroup = GameObject.GetComponent <CanvasGroup>();
                    CanvasGroup = canvasGroup == null?GameObject.AddComponent <CanvasGroup>() : canvasGroup;
                }

                CanvasGroup.alpha = 0;
            }
        }