Пример #1
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;
            }
        }
Пример #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;
            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;
            }
        }
Пример #3
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);
        }