private void OnDestroy() { if (!m_Image.IsDestroyed()) { DestroyImmediate(m_Image); } }
public void SetTitleEffect(uint titleId, RawImage rawImg) { if (null == rawImg) { return; } // 低配下不使用称号特效 if (QualitySetting.GraphicLevel == (int)EGraphLevel.LOW) { rawImg.gameObject.SetActive(false); rawImg.texture = null; return; } var dbTitleItem = GetData(titleId); if (null == dbTitleItem) { rawImg.gameObject.SetActive(false); rawImg.texture = null; return; } var effectInfo = xc.DBManager.Instance.GetDB <xc.DBTitleEffect>().GetData(dbTitleItem.EffectId); if (null == effectInfo) { rawImg.gameObject.SetActive(false); rawImg.texture = null; return; } string effectName = effectInfo.Name; // **.png // 当前特效名 string curEffectName = null; if (rawImg.texture != null) { curEffectName = string.Format("{0}.png", rawImg.texture.name); if (curEffectName.Equals(effectName)) { rawImg.gameObject.SetActive(true); return; } } rawImg.gameObject.SetActive(false); var effectImagePath = string.Format("Assets/Res/Effects/Textures/{0}", effectInfo.Name); SGameEngine.ResourceLoader.Instance.LoadAssetAsync(effectImagePath, (asset_res) => { Texture effectTexture = asset_res.asset_ as Texture; if (effectTexture != null) { if (null == rawImg || rawImg.IsDestroyed() || !rawImg.transform.parent.gameObject.activeSelf) { if (asset_res != null) { asset_res.destroy(); asset_res = null; } } else { rawImg.gameObject.SetActive(true); rawImg.texture = effectTexture; // 设置大小 var rt = rawImg.GetComponent <RectTransform>(); if (rt != null) { rt.sizeDelta = effectInfo.FrameSize; } var frameCom = rawImg.transform.GetComponent <UGUIFrameAnimation>(); if (frameCom != null) { uint col = (uint)effectInfo.Arg.x; uint row = (uint)effectInfo.Arg.y; if (col > 0 && row > 0) { frameCom.enabled = false; frameCom.FrameCount = 16; frameCom.OneFrameWidth = 1f / col; frameCom.OneFrameHeight = 1f / row; frameCom.RectXSpace = 1f / col; frameCom.RectYSpace = 1f / row; frameCom.ColNum = col; frameCom.FrameInterval = 0.05f; frameCom.IsLoop = true; frameCom.StartFrame = 0; frameCom.enabled = true; } } } } else { if (asset_res != null) { asset_res.destroy(); asset_res = null; } } }); }
public static ICompletable BindAsCompletable(this IBinder This, RawImage image, Uri uri, bool isOptional = false, Loadzup.Options options = null, bool keepVisible = false, float?fadeDuration = null, bool isPriority = false) { if (image == null) { return(Completable.Empty()); } if (uri == null) { if (isOptional) { return(Completable.Empty()); } return(Completable.Throw( new BindException( $"Cannot bind required image {image.gameObject.name} in view {This.View.GameObject.name} to null Uri."))); } if (fadeDuration != null) { image.color = Color.clear; } else { image.enabled = keepVisible; } return(This.Loader .With(This.DefaultImageHttpCachePolicy) .WithCancellationOnDestroy(This.View) .WithQueuing(isPriority) .Load <Texture2D>(uri, options) .Catch <Texture2D, Exception>(ex => Observable .Throw <Texture2D>(new BindException( $"Failed to load image {image.gameObject.name} in view {This.View.GetType().Name} from {uri}", ex))) .Do(x => { if (image.IsDestroyed()) { if (uri.Scheme == Scheme.Http || uri.Scheme == Scheme.Https || uri.Scheme == Scheme.StreamingAsset || uri.Scheme == Scheme.StreamingFile) { Object.Destroy(x); } return; } image.texture = x; image.enabled = true; if (fadeDuration != null) { Observable.NextFrame() .Then(_ => image.TweenColorTo(Color.white, fadeDuration.Value)) .SubscribeAndForget() .AddTo(This); } if (uri.Scheme == Scheme.Http || uri.Scheme == Scheme.Https || uri.Scheme == Scheme.StreamingAsset || uri.Scheme == Scheme.StreamingFile) { Disposable .Create(() => Object.Destroy(x)) .AddTo(This); } }) .AutoDetach() .AsCompletable()); }