예제 #1
0
        private static IEnumerator LoadSkin(ulong workshopId)
        {
            int         bundleIndex = WorkshopSkin.GetBundleIndex(workshopId);
            AssetBundle assetBundle = WorkshopSkin.bundles[bundleIndex];

            TimeWarning.BeginSample("WorkshopSkin.LoadSkin");
            TimeWarning.BeginSample("ItemCache.Get");
            Item item = WorkshopSkin.ItemCache[workshopId];

            TimeWarning.EndSample();
            TimeWarning.BeginSample("SkinCache.Get");
            Skin skin = WorkshopSkin.SkinCache[workshopId];

            TimeWarning.EndSample();
            if (skin.IconRequested && !skin.IconLoaded)
            {
                TimeWarning.EndSample();
                yield return(Global.Runner.StartCoroutine(skin.LoadIcon(workshopId, item.Directory, assetBundle)));

                TimeWarning.BeginSample("WorkshopSkin.LoadSkin");
            }
            if (skin.AssetsRequested && !skin.AssetsLoaded)
            {
                TimeWarning.EndSample();
                yield return(Global.Runner.StartCoroutine(skin.LoadAssets(workshopId, item.Directory, assetBundle)));

                TimeWarning.BeginSample("WorkshopSkin.LoadAssets");
            }
            if (!skin.AssetsRequested && skin.AssetsLoaded)
            {
                TimeWarning.BeginSample("Skin.UnloadAssets");
                skin.UnloadAssets();
                TimeWarning.EndSample();
            }
            if (skin.AssetsLoaded && WorkshopSkin.RefreshQueue.Contains(workshopId))
            {
                ListHashSet <WorkshopSkin> workshopSkins = WorkshopSkin.RefreshQueue[workshopId];
                while (workshopSkins.Count > 0)
                {
                    WorkshopSkin workshopSkin = workshopSkins[0];
                    workshopSkins.RemoveAt(0);
                    workshopSkin.ApplySkin(skin, workshopId);
                    TimeWarning.EndSample();
                    yield return(null);

                    TimeWarning.BeginSample("WorkshopSkin.LoadAssets");
                }
                WorkshopSkin.RefreshQueue.Remove(workshopId);
                workshopSkins = null;
            }
            TimeWarning.EndSample();
        }
예제 #2
0
        private static IEnumerator LoadItem(ulong workshopId)
        {
            int         bundleIndex = WorkshopSkin.GetBundleIndex(workshopId);
            AssetBundle assetBundle = WorkshopSkin.bundles[bundleIndex];

            if (assetBundle == null)
            {
                AssetBundleCreateRequest assetBundleCreateRequest = WorkshopSkin.bundleRequests[bundleIndex];
                if (assetBundleCreateRequest == null)
                {
                    TimeWarning.BeginSample("AssetBundle.LoadFromFileAsync");
                    AssetBundleCreateRequest[] assetBundleCreateRequestArray = WorkshopSkin.bundleRequests;
                    int num = bundleIndex;
                    AssetBundleCreateRequest assetBundleCreateRequest1 = AssetBundle.LoadFromFileAsync(string.Concat("Bundles/textures/textures.", bundleIndex, ".bundle"));
                    AssetBundleCreateRequest assetBundleCreateRequest2 = assetBundleCreateRequest1;
                    assetBundleCreateRequestArray[num] = assetBundleCreateRequest1;
                    assetBundleCreateRequest           = assetBundleCreateRequest2;
                    TimeWarning.EndSample();
                }
                yield return(assetBundleCreateRequest);

                TimeWarning.BeginSample("BundleRequest");
                AssetBundle[] assetBundleArray = WorkshopSkin.bundles;
                int           num1             = bundleIndex;
                AssetBundle   assetBundle1     = WorkshopSkin.bundleRequests[bundleIndex].assetBundle;
                AssetBundle   assetBundle2     = assetBundle1;
                assetBundleArray[num1] = assetBundle1;
                assetBundle            = assetBundle2;
                TimeWarning.EndSample();
            }
            TimeWarning.BeginSample("WorkshopSkin.LoadItem");
            TimeWarning.BeginSample("ItemCache.Get");
            Item item = WorkshopSkin.ItemCache[workshopId];

            TimeWarning.EndSample();
            TimeWarning.BeginSample("Item.Installed");
            bool isInstalled = item.IsInstalled;

            TimeWarning.EndSample();
            if (!isInstalled && assetBundle != null)
            {
                TimeWarning.BeginSample("Bundle.Contains");
                isInstalled = assetBundle.Contains(string.Concat("Assets/Skins/", workshopId, "/manifest.txt"));
                TimeWarning.EndSample();
            }
            if (!isInstalled)
            {
                TimeWarning.BeginSample("Item.Download");
                bool flag = item.Download(true);
                TimeWarning.EndSample();
                if (flag)
                {
                    TimeWarning.BeginSample("Stopwatch.StartNew");
                    Stopwatch stopwatch = Stopwatch.StartNew();
                    TimeWarning.EndSample();
                    TimeWarning.BeginSample("Item.Installed");
                    while (!item.IsInstalled && stopwatch.Elapsed.TotalSeconds < (double)WorkshopSkin.DownloadTimeout)
                    {
                        TimeWarning.EndSample();
                        TimeWarning.EndSample();
                        yield return(WorkshopSkin.waitForSeconds);

                        TimeWarning.BeginSample("WorkshopSkin.LoadItem");
                        TimeWarning.BeginSample("Item.Installed");
                    }
                    TimeWarning.EndSample();
                    TimeWarning.BeginSample("Item.Installed");
                    isInstalled = item.IsInstalled;
                    TimeWarning.EndSample();
                    stopwatch = null;
                }
                if (!flag)
                {
                    UnityEngine.Debug.LogWarning(string.Concat("Skin download failed: ", workshopId));
                }
                else if (!isInstalled)
                {
                    UnityEngine.Debug.LogWarning(string.Concat("Skin download timed out: ", workshopId));
                }
            }
            if (isInstalled)
            {
                WorkshopSkin.SkinQueue.Enqueue(workshopId);
                if (WorkshopSkin.SkinQueue.Count == 1)
                {
                    Global.Runner.StartCoroutine(WorkshopSkin.SkinQueueCoroutine());
                }
            }
            TimeWarning.EndSample();
        }