コード例 #1
0
 public IEnumerator RefreshBatchesAsync()
 {
     if (this.refreshBatches == null)
     {
         this.refreshBatches = new Action(this.RefreshBatches);
     }
     return(Parallel.Coroutine(this.refreshBatches));
 }
コード例 #2
0
 public IEnumerator UpdateDataAsync()
 {
     if (this.updateData == null)
     {
         this.updateData = new Action(this.UpdateData);
     }
     return(Parallel.Coroutine(this.updateData));
 }
コード例 #3
0
        public IEnumerator LoadIcon(ulong workshopId, string directory = null, AssetBundle bundle = null)
        {
            Skin str = null;
            AssetBundleRequest assetBundleRequest;

            TimeWarning.BeginSample("Skin.LoadIcon");
            if (bundle != null)
            {
                TimeWarning.BeginSample("ManifestName");
                str.manifestName = string.Concat("Assets/Skins/", workshopId, "/manifest.txt");
                TimeWarning.EndSample();
                TimeWarning.BeginSample("LoadAssetAsync");
                assetBundleRequest = bundle.LoadAssetAsync <TextAsset>(str.manifestName);
                TimeWarning.EndSample();
                TimeWarning.EndSample();
                yield return(assetBundleRequest);

                TimeWarning.BeginSample("Skin.LoadIcon");
                TimeWarning.BeginSample("AssetBundleRequest");
                str.manifestAsset = assetBundleRequest.asset as TextAsset;
                TimeWarning.EndSample();
                if (str.manifestAsset != null)
                {
                    TimeWarning.BeginSample("TextAsset");
                    str.manifestContent = str.manifestAsset.text;
                    TimeWarning.EndSample();
                }
                assetBundleRequest = null;
            }
            if (str.manifestContent == null && directory != null)
            {
                TimeWarning.BeginSample("ManifestName");
                str.manifestName = string.Concat(directory, "/manifest.txt");
                TimeWarning.EndSample();
                TimeWarning.BeginSample("File.Exists");
                bool flag = File.Exists(str.manifestName);
                TimeWarning.EndSample();
                if (flag)
                {
                    TimeWarning.EndSample();
                    yield return(Global.Runner.StartCoroutine(Parallel.Coroutine(new Action(str.LoadManifestFromFile))));

                    TimeWarning.BeginSample("Skin.LoadIcon");
                }
            }
            if (str.manifestContent != null)
            {
                TimeWarning.EndSample();
                yield return(Global.Runner.StartCoroutine(Parallel.Coroutine(new Action(str.DeserializeManifest))));

                TimeWarning.BeginSample("Skin.LoadIcon");
            }
            if (str.manifest == null)
            {
                UnityEngine.Debug.LogWarning(string.Concat("Invalid skin manifest: ", str.manifestName));
                TimeWarning.EndSample();
                yield break;
            }
            TimeWarning.BeginSample("Skinnable.FindForItem");
            str.Skinnable = Skinnable.FindForItem(str.manifest.ItemType);
            TimeWarning.EndSample();
            if (bundle != null)
            {
                TimeWarning.BeginSample("IconName");
                str.iconName = string.Concat("Assets/Skins/", workshopId, "/icon.png");
                TimeWarning.EndSample();
                TimeWarning.BeginSample("LoadAssetAsync");
                assetBundleRequest = bundle.LoadAssetAsync <Sprite>(str.iconName);
                TimeWarning.EndSample();
                TimeWarning.EndSample();
                yield return(assetBundleRequest);

                TimeWarning.BeginSample("Skin.LoadIcon");
                TimeWarning.BeginSample("AssetBundleRequest");
                Sprite sprite = assetBundleRequest.asset as Sprite;
                TimeWarning.EndSample();
                if (sprite != null)
                {
                    TimeWarning.BeginSample("Sprite");
                    str.sprite = sprite;
                    TimeWarning.EndSample();
                }
                assetBundleRequest = null;
            }
            if (str.sprite == null && SteamClient.IsValid)
            {
                string         empty       = string.Empty;
                InventoryDef[] definitions = SteamInventory.Definitions;
                TimeWarning.BeginSample("IconName");
                str.iconName = workshopId.ToString();
                TimeWarning.EndSample();
                if (definitions != null)
                {
                    TimeWarning.BeginSample("FindItemDefinition");
                    int length = (int)definitions.Length - 1;
                    while (length >= 0)
                    {
                        InventoryDef inventoryDef = definitions[length];
                        string       property     = inventoryDef.GetProperty("workshopdownload");
                        if (str.iconName != property)
                        {
                            length--;
                        }
                        else
                        {
                            empty = inventoryDef.IconUrlLarge;
                            break;
                        }
                    }
                    TimeWarning.EndSample();
                }
                if (!string.IsNullOrEmpty(empty))
                {
                    TimeWarning.BeginSample("UnityWebRequestTexture.GetTexture");
                    UnityWebRequest texture = UnityWebRequestTexture.GetTexture(empty);
                    texture.timeout = Mathf.CeilToInt(WorkshopSkin.DownloadTimeout);
                    TimeWarning.EndSample();
                    TimeWarning.EndSample();
                    yield return(texture.SendWebRequest());

                    TimeWarning.BeginSample("Skin.LoadIcon");
                    if (texture.isDone && !texture.isHttpError && !texture.isNetworkError)
                    {
                        TimeWarning.BeginSample("DownloadHandlerTexture.GetContent");
                        Texture2D content = DownloadHandlerTexture.GetContent(texture);
                        TimeWarning.EndSample();
                        TimeWarning.BeginSample("Sprite");
                        str.sprite = Sprite.Create(content, new Rect(0f, 0f, 512f, 512f), Vector2.zero, 100f, 0, SpriteMeshType.FullRect);
                        TimeWarning.EndSample();
                    }
                    TimeWarning.BeginSample("UnityWebRequest.Dispose");
                    texture.Dispose();
                    TimeWarning.EndSample();
                    texture = null;
                }
            }
            if (str.sprite == null && directory != null)
            {
                TimeWarning.BeginSample("IconName");
                str.iconName = string.Concat(directory, "/icon.png");
                TimeWarning.EndSample();
                TimeWarning.BeginSample("File.Exists");
                bool flag1 = File.Exists(str.iconName);
                TimeWarning.EndSample();
                if (flag1)
                {
                    TimeWarning.BeginSample("AsyncTextureLoad.Invoke");
                    AsyncTextureLoad asyncTextureLoad = new AsyncTextureLoad(str.iconName, false, false, true, false);
                    TimeWarning.EndSample();
                    TimeWarning.EndSample();
                    yield return(asyncTextureLoad);

                    TimeWarning.BeginSample("Skin.LoadIcon");
                    TimeWarning.BeginSample("AsyncTextureLoad.Texture");
                    Texture2D texture2D = asyncTextureLoad.texture;
                    TimeWarning.EndSample();
                    TimeWarning.BeginSample("Sprite");
                    str.sprite = Sprite.Create(texture2D, new Rect(0f, 0f, 512f, 512f), Vector2.zero, 100f, 0, SpriteMeshType.FullRect);
                    TimeWarning.EndSample();
                    asyncTextureLoad = null;
                }
            }
            if (str.sprite != null)
            {
                str.IconLoaded = true;
                if (str.OnIconLoaded != null)
                {
                    str.OnIconLoaded();
                }
            }
            TimeWarning.EndSample();
        }