예제 #1
0
 private void UpdateSkinReference(Skin skin, ulong workshopId)
 {
     if (this.AppliedSkin == skin)
     {
         return;
     }
     if (this.AppliedSkin != null)
     {
         this.AppliedSkin.references--;
         if (this.AppliedSkin.references < 0)
         {
             UnityEngine.Debug.LogWarning("Skin has less than 0 references, this should never happen");
         }
         else if (this.AppliedSkin.references == 0 && !WorkshopSkin.RefreshQueue.Contains(this.AppliedWorkshopID) && WorkshopSkin.AllowUnload && this.AppliedSkin.AssetsRequested)
         {
             this.AppliedSkin.AssetsRequested = false;
             WorkshopSkin.LoadOrUnloadSkinAssets(this.AppliedWorkshopID);
         }
     }
     this.AppliedSkin       = skin;
     this.AppliedWorkshopID = workshopId;
     if (this.AppliedSkin != null)
     {
         this.AppliedSkin.references++;
     }
 }
예제 #2
0
        public static void Reset(GameObject gameobj)
        {
            WorkshopSkin component = gameobj.GetComponent <WorkshopSkin>();

            if (component != null)
            {
                component.UpdateSkinReference(null, (ulong)0);
            }
            MaterialReplacement.Reset(gameobj);
        }
예제 #3
0
        private static IEnumerator SkinQueueCoroutine()
        {
            while (WorkshopSkin.SkinQueue.Count > 0)
            {
                ulong num = WorkshopSkin.SkinQueue.Peek();
                yield return(Global.Runner.StartCoroutine(WorkshopSkin.LoadSkin(num)));

                WorkshopSkin.SkinQueue.Dequeue();
            }
        }
예제 #4
0
 private static void LoadOrUnloadSkinAssets(ulong workshopId)
 {
     if (workshopId == 0)
     {
         return;
     }
     WorkshopSkin.ItemQueue.Enqueue(workshopId);
     if (WorkshopSkin.ItemQueue.Count == 1)
     {
         Global.Runner.StartCoroutine(WorkshopSkin.ItemQueueCoroutine());
     }
 }
예제 #5
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();
        }
예제 #6
0
        public static void Apply(GameObject gameobj, ulong workshopId, Action callback = null)
        {
            if (!SteamClient.IsValid)
            {
                return;
            }
            WorkshopSkin component = gameobj.GetComponent <WorkshopSkin>();

            if (component == null)
            {
                component = gameobj.AddComponent <WorkshopSkin>();
            }
            component.Apply(workshopId, callback);
        }
        public static Sprite Find(ulong workshopId, Sprite placeholder = null, Action callback = null)
        {
            Skin skin = WorkshopSkin.GetSkin(workshopId);

            if (!skin.IconLoaded)
            {
                if (callback != null)
                {
                    skin.OnIconLoaded = callback;
                }
                if (placeholder != null)
                {
                    return(placeholder);
                }
            }
            return(skin.sprite);
        }
예제 #8
0
        private void EnqueueSkinRefresh(ulong workshopId)
        {
            if (workshopId == 0)
            {
                return;
            }
            ListHashSet <WorkshopSkin> workshopSkins = null;

            if (!WorkshopSkin.RefreshQueue.TryGetValue(workshopId, out workshopSkins))
            {
                ListDictionary <ulong, ListHashSet <WorkshopSkin> > refreshQueue = WorkshopSkin.RefreshQueue;
                ListHashSet <WorkshopSkin> workshopSkins1 = new ListHashSet <WorkshopSkin>(8);
                workshopSkins = workshopSkins1;
                refreshQueue.Add(workshopId, workshopSkins1);
            }
            workshopSkins.Add(this);
            WorkshopSkin.LoadFromWorkshop(workshopId);
        }
예제 #9
0
        private static void LoadFromWorkshop(ulong workshopId)
        {
            if (WorkshopSkin.ItemCache.Contains(workshopId))
            {
                TimeWarning.BeginSample("SkinCache.Get");
                Skin item = WorkshopSkin.SkinCache[workshopId];
                TimeWarning.EndSample();
                if (!item.AssetsRequested && WorkshopSkin.RefreshQueue.Contains(workshopId))
                {
                    item.AssetsRequested = true;
                    WorkshopSkin.LoadOrUnloadSkinAssets(workshopId);
                }
                return;
            }
            TimeWarning.BeginSample("Workshop.GetItem");
            Item item1 = new Item(workshopId);

            TimeWarning.EndSample();
            TimeWarning.BeginSample("ItemCache.Add");
            WorkshopSkin.ItemCache.Add(workshopId, item1);
            TimeWarning.EndSample();
            TimeWarning.BeginSample("Skin.New");
            Skin skin = new Skin();

            TimeWarning.EndSample();
            TimeWarning.BeginSample("SkinCache.Add");
            WorkshopSkin.SkinCache.Add(workshopId, skin);
            TimeWarning.EndSample();
            if (!skin.IconRequested)
            {
                skin.IconRequested = true;
            }
            if (!skin.AssetsRequested && WorkshopSkin.RefreshQueue.Contains(workshopId))
            {
                skin.AssetsRequested = true;
            }
            WorkshopSkin.LoadOrUnloadSkinAssets(workshopId);
        }
예제 #10
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();
        }
예제 #11
0
 public static Skin GetSkin(ulong workshopId)
 {
     WorkshopSkin.LoadFromWorkshop(workshopId);
     return(WorkshopSkin.SkinCache[workshopId]);
 }
예제 #12
0
 public static Item GetItem(ulong workshopId)
 {
     WorkshopSkin.LoadFromWorkshop(workshopId);
     return(WorkshopSkin.ItemCache[workshopId]);
 }