Example #1
0
        /// <summary>
        /// Called just before the view and its children are loaded.
        /// </summary>
        protected override void BeforeLoad()
        {
            if (IgnoreObject)
            {
                return;
            }

            base.BeforeLoad();

            if (MaskContent)
            {
                Mask = GameObject.AddComponent <UnityEngine.UI.Mask>();
            }

            if (ImageComponent == null)
            {
                // check if image color or sprite has binding
                if (BackgroundColorProperty.HasBinding(this) || BackgroundSpriteProperty.HasBinding(this) || BackgroundSprite != null)
                {
                    ImageComponent = GameObject.AddComponent <UnityEngine.UI.Image>();
                    FastMaterialChanged(); // apply fast material if specified
                }
            }

            SpriteChanged();
        }
Example #2
0
        /// <summary>
        /// Called whenever properties affecting the image are changed.
        /// </summary>
        public virtual void ImageChanged()
        {
            if (IgnoreObject)
            {
                return;
            }

            if (ImageComponent == null)
            {
                // add image component if background color is defined
                if (BackgroundColorProperty.IsUndefined(this, true))
                {
                    return;
                }

                ImageComponent = GameObject.AddComponent <UnityEngine.UI.Image>();
            }

            if (BackgroundColorProperty.IsUndefined(this))
            {
                if (ImageComponent.sprite != null || ImageComponent.overrideSprite != null)
                {
                    // use white color by default if image is set
                    ImageComponent.color = Color.white;
                }
                else
                {
                    // use clear color by default if image isn't set
                    ImageComponent.color = Color.clear;
                }
            }

            var sprite = ImageComponent.overrideSprite ?? ImageComponent.sprite;

            if (Width == null && Height == null)
            {
                // if width and height is undefined, adjust size to native size of sprite
                if (sprite != null)
                {
                    ImageComponent.SetNativeSize();
                    OverrideWidth  = ElementSize.FromPixels(ImageComponent.rectTransform.sizeDelta.x);
                    OverrideHeight = ElementSize.FromPixels(ImageComponent.rectTransform.sizeDelta.y);
                }
            }

            bool isLoading = BackgroundSprite != null && !BackgroundSprite.IsLoaded;

            if (isLoading && sprite == null)
            {
                // always disable image while loading if current sprite isn't set
                ImageComponent.enabled = false;
            }
            else
            {
                // disable raycast blocks if image is transparent
                ImageComponent.enabled = RaycastBlockMode == RaycastBlockMode.Always ? true : ImageComponent.color.a > 0;
            }
        }
Example #3
0
        /// <summary>
        /// Called whenever properties affecting the image are changed.
        /// </summary>
        public virtual void ImageChanged()
        {
            if (IgnoreObject)
            {
                return;
            }

            if (ImageComponent == null)
            {
                // add image component if background color is defined
                if (BackgroundColorProperty.IsUndefined(this, true))
                {
                    return;
                }

                ImageComponent = GameObject.AddComponent <UnityEngine.UI.Image>();
            }

            if (BackgroundColorProperty.IsUndefined(this))
            {
                if (ImageComponent.sprite != null || ImageComponent.overrideSprite != null)
                {
                    // use white color by default if image is set
                    ImageComponent.color = Color.white;
                }
                else
                {
                    // use clear color by default if image isn't set
                    ImageComponent.color = Color.clear;
                }
            }

            var  sprite    = ImageComponent.overrideSprite ?? ImageComponent.sprite;
            bool isLoading = BackgroundSprite != null && !BackgroundSprite.IsLoaded;

            if (isLoading && sprite == null)
            {
                // always disable image while loading if current sprite isn't set
                ImageComponent.enabled = false;
            }
            else
            {
                // disable raycast blocks if image is transparent
                ImageComponent.enabled = RaycastBlockMode == RaycastBlockMode.Always ? true : ImageComponent.color.a > 0;
            }
        }
Example #4
0
        /// <summary>
        /// Returns boolean indicating if background is visible.
        /// </summary>
        private bool BackgroundIsVisible()
        {
            if (BackgroundColorProperty.IsUndefined(this))
            {
                return(false);
            }

            if (BackgroundColor.a <= 0)
            {
                return(false);
            }

            if (!AlphaProperty.IsUndefined(this) && Alpha <= 0)
            {
                return(false);
            }

            return(IsVisible);
        }
Example #5
0
 set => this.SetValue(BackgroundColorProperty, value);
Example #6
0
 set { SetValue(BackgroundColorProperty, value); }
Example #7
0
this.DynamicResource(BackgroundColorProperty, nameof(BaseTheme.CardSurfaceColor));
Example #8
0
 get => (Color)GetValue(BackgroundColorProperty); set => SetValue(BackgroundColorProperty, value);
Example #9
0
 SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.PageBackgroundColor));