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(); }
public static IEnumerator Coroutine(Action action) { TimeWarning.BeginSample("Parallel.Coroutine"); IAsyncResult asyncResult = action.BeginInvoke(null, null); while (!asyncResult.IsCompleted) { TimeWarning.EndSample(); yield return(null); TimeWarning.BeginSample("Parallel.Coroutine"); } action.EndInvoke(asyncResult); TimeWarning.EndSample(); }
public static void Apply(GameObject obj, Skinnable skinnable, Material[] Materials) { TimeWarning.BeginSample("Skin.Apply"); if (Materials == null) { TimeWarning.EndSample(); return; } if (obj == null) { TimeWarning.EndSample(); return; } MaterialReplacement.ReplaceRecursive(obj, skinnable.SourceMaterials, Materials); TimeWarning.EndSample(); }
internal void ReadDefaults() { TimeWarning.BeginSample("Skin.ReadDefaults"); if (this.AssetsLoaded) { this.UnloadAssets(); } if (this.Skinnable != null && this.Skinnable.Groups != null) { if (this.DefaultMaterials == null || (int)this.DefaultMaterials.Length != (int)this.Skinnable.Groups.Length) { this.DefaultMaterials = new Material[(int)this.Skinnable.Groups.Length]; } if (this.Materials == null || (int)this.Materials.Length != (int)this.Skinnable.Groups.Length) { this.Materials = new Material[(int)this.Skinnable.Groups.Length]; } for (int i = 0; i < (int)this.DefaultMaterials.Length; i++) { Skinnable.Group groups = this.Skinnable.Groups[i]; if (groups != null) { this.DefaultMaterials[i] = groups.Material; } } for (int j = 0; j < (int)this.Materials.Length; j++) { if (this.DefaultMaterials[j] != null) { Material[] materials = this.Materials; Material material = new Material(this.DefaultMaterials[j]); Material material1 = material; materials[j] = material; Material material2 = material1; material2.DisableKeyword("_COLORIZELAYER_ON"); material2.SetInt("_COLORIZELAYER_ON", 0); material2.name = string.Concat(this.DefaultMaterials[j].name, " (Editing)"); } else { UnityEngine.Debug.LogWarning(string.Concat("Missing skin for ", this.Skinnable.ItemName)); } } } TimeWarning.EndSample(); }
public void LoadIntoTexture(Texture2D tex) { if (!this.isValid) { return; } if (tex.width != this.width || tex.height != this.height || (int)tex.format != this.format) { return; } TimeWarning.BeginSample("Texture2D.LoadRawTextureData"); tex.LoadRawTextureData(this.buffer, this.size); TimeWarning.EndSample(); TimeWarning.BeginSample("Texture2D.Apply"); tex.Apply(false); TimeWarning.EndSample(); TimeWarning.BeginSample("Native.FreeTexture"); AsyncTextureLoad.FreeTexture(ref this.buffer); TimeWarning.EndSample(); }
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); }
private void DoTick() { float[] buffer = this.curList.Values.Buffer; InvokeAction[] invokeActionArray = this.curList.Keys.Buffer; int count = this.curList.Count; float single = Time.time; for (int i = 0; i < count; i++) { if (single >= buffer[i]) { InvokeAction invokeAction = invokeActionArray[i]; if (!invokeAction.sender || this.delList.Contains(invokeAction)) { this.QueueRemove(invokeAction); } else { if (invokeAction.repeat < 0f) { this.QueueRemove(invokeAction); } else { float single1 = single + invokeAction.repeat; if (invokeAction.random > 0f) { single1 += UnityEngine.Random.Range(-invokeAction.random, invokeAction.random); } buffer[i] = single1; } TimeWarning.BeginSample(invokeAction.action.Method.Name); invokeAction.action(); TimeWarning.EndSample(); } } } }
private void ApplySkin(Skin skin, ulong workshopId) { TimeWarning.BeginSample("WorkshopSkin.ApplySkin"); if (!this) { TimeWarning.EndSample(); return; } if (!base.gameObject) { TimeWarning.EndSample(); return; } if (WorkshopSkin.AllowApply) { skin.Apply(base.gameObject); this.UpdateSkinReference(skin, workshopId); } if (this.OnRefresh != null) { this.OnRefresh(); } TimeWarning.EndSample(); }
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(); }
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(); }