public IImageComponent SetMaterial(Material material, bool setMainTexture = false, System.Action onComplete = null) { MovieSystem.UnregisterOnUpdateMaterial(this.ValidateMaterial); if (material == null) { if (this.image != null) { this.image.material = null; this.image.SetMaterialDirty(); } else if (this.rawImage != null) { this.rawImage.material = null; this.rawImage.SetMaterialDirty(); } if (onComplete != null) { onComplete.Invoke(); } return(this); } MovieSystem.RegisterOnUpdateMaterial(this.ValidateMaterial); if (this.image != null) { if (this.image.enabled == false) { this.image.enabled = true; } var tex = material.mainTexture; if (this.imageCrossFadeModule.IsValid() == true) { this.imageCrossFadeModule.FadeTo <Image>(this, material, () => { if (setMainTexture == true) { var sprite = Sprite.Create(tex as Texture2D, new Rect(0f, 0f, tex.width, tex.height), Vector2.one * 0.5f); this.image.sprite = sprite; } this.image.SetMaterialDirty(); if (onComplete != null) { onComplete.Invoke(); } }, ImageCrossFadeModule.DataType.Material); } else { if (setMainTexture == true) { var sprite = Sprite.Create(tex as Texture2D, new Rect(0f, 0f, tex.width, tex.height), Vector2.one * 0.5f); this.image.sprite = sprite; } this.image.material = material; this.image.SetMaterialDirty(); if (onComplete != null) { onComplete.Invoke(); } } } else if (this.rawImage != null) { if (this.rawImage.enabled == false) { this.rawImage.enabled = true; } var tex = material.mainTexture; if (this.imageCrossFadeModule.IsValid() == true) { this.imageCrossFadeModule.FadeTo <RawImage>(this, material, () => { if (setMainTexture == true) { this.rawImage.texture = tex; } this.rawImage.SetMaterialDirty(); if (onComplete != null) { onComplete.Invoke(); } }, ImageCrossFadeModule.DataType.Material); } else { if (setMainTexture == true) { this.rawImage.texture = tex; } this.rawImage.material = material; this.rawImage.SetMaterialDirty(); if (onComplete != null) { onComplete.Invoke(); } } } return(this); }