public void SetImage(Sprite sprite, bool preserveAspect, bool withPivotsAndSize = false) { if (this.image != null) { this.image.sprite = sprite; this.image.preserveAspect = preserveAspect; if (withPivotsAndSize == true && sprite != null) { var rect = (this.transform as RectTransform); rect.sizeDelta = sprite.rect.size; rect.pivot = sprite.GetPivot(); rect.anchoredPosition = Vector2.zero; } } }
public IImageComponent SetImage(Sprite sprite, bool preserveAspect, bool withPivotsAndSize, System.Action onComplete = null) { if (this.image != null) { this.image.preserveAspect = preserveAspect; if (withPivotsAndSize == true && sprite != null) { var rect = (this.transform as RectTransform); rect.sizeDelta = sprite.rect.size; rect.pivot = sprite.GetPivot(); rect.anchoredPosition = Vector2.zero; } if (this.imageCrossFadeModule.IsValid() == true) { this.imageCrossFadeModule.FadeTo(sprite, onComplete); } else { this.image.sprite = sprite; if (onComplete != null) onComplete.Invoke(); } } else { if (onComplete != null) onComplete.Invoke(); } return this; }