public virtual void SetRawImageTexture2D(Texture2D texture) { m_AspectRatioFitterComponent.aspectMode = AspectRatioFitter.AspectMode.None; RawImageComponent.texture = null; if (texture == null) { RawImageComponent.texture = texture; RawImageComponent.SetNativeSize(); CalculateAspectRatio(); } else { m_AspectRatioFitterComponent.aspectRatio = 1; } }
/// <summary> /// Called whenever properties affecting the image are changed. /// </summary> public virtual void ImageChanged() { if (RawImageComponent == null) { return; } if (ColorProperty.IsUndefined(this)) { if (RawImageComponent.texture != null) { // use white color by default if image is set RawImageComponent.color = Color.white; } else { // use clear color by default if image isn't set RawImageComponent.color = Color.clear; } } var texture = RawImageComponent.texture; if (WidthProperty.IsUndefined(this) && HeightProperty.IsUndefined(this)) { // if width and height is undefined, adjust size to native size of sprite if (texture != null) { RawImageComponent.SetNativeSize(); OverrideWidth = ElementSize.FromPixels(RawImageComponent.rectTransform.sizeDelta.x); OverrideHeight = ElementSize.FromPixels(RawImageComponent.rectTransform.sizeDelta.y); } } bool isLoading = Texture != null && !Texture.IsLoaded; if (isLoading && texture == null) { // always disable image while loading RawImageComponent.enabled = false; } else { // disable raycast blocks if image is transparent RawImageComponent.enabled = RaycastBlockMode == RaycastBlockMode.Always ? true : RawImageComponent.color.a > 0; } }