Dictionary <uint, AssetResource> mLoadedAssetRes = new Dictionary <uint, AssetResource>(); //loadingid->assetresource /// <summary> /// 在指定的Image上加载assetPath的贴图并赋值 /// </summary> /// <param name="image"></param> /// <param name="assetPath"></param> public void LoadBuffIcon(RawImage image, string assetPath) { if (image == null) { return; } // 获取RawImage的InstanceID int instId = image.GetInstanceID(); // 取消之前的loading/销毁资源 uint loadingId = 0; mLoadingIDs.TryGetValue(instId, out loadingId); RemoveLoadingId(loadingId); // 获取新的loadingid if (sLoadingId == 0) { sLoadingId++; } mLoadingIDs[instId] = sLoadingId; mLoadedAssetRes[sLoadingId] = null; // 开启新的加载 MainGame.HeartBehavior.StartCoroutine(LoadTexture(image, assetPath, sLoadingId)); sLoadingId++; }
public RawImageColor(RawImage target, Color endValue, float duration, float delay, bool obeyTimescale, AnimationCurve curve, Tween.LoopType loop, Action startCallback, Action completeCallback) { //set essential properties: SetEssentials(Tween.TweenType.RawImageColor, target.GetInstanceID(), duration, delay, obeyTimescale, curve, loop, startCallback, completeCallback); //catalog custom properties: _target = target; EndValue = endValue; }
public static void RequestImage(string url, RawImage target) { var targetId = target.GetInstanceID(); if (_activeRequestsByInstance.ContainsKey(targetId)) { _activeRequestsByInstance[targetId].RemoveTarget(target); _activeRequestsByInstance.Remove(targetId); } if (_activeRequestsByUrl.ContainsKey(url)) { var request = _activeRequestsByUrl[url]; if (request.IsCompleted) { if (request.IsSuccess || request.Texture != null) { target.texture = request.Texture; } else { target.gameObject.SetActive(false); } } else { _activeRequestsByInstance[targetId] = request; request.AddTarget(target); } return; } var imageRequest = new ImageRequestCommand(url, OnCommandCompleted); imageRequest.AddTarget(target); _activeRequestsByUrl[url] = imageRequest; _activeRequestsByInstance[targetId] = imageRequest; imageRequest.Dispatch(); }