private IEnumerator <WaitForEndOfFrame> OnFileCreated(object sender, FileSystemEventArgs e) { yield return(new WaitForEndOfFrame()); SharedCoroutineStarter.instance.StartCoroutine(_platformLoader.LoadFromFileAsync(e.FullPath, (CustomPlatform platform, string path) => { _platformManager.HandlePlatformLoaded(platform, path); if (_platformListsView.allListTables != null) { if (platform.icon == null) { platform.icon = _platformManager.fallbackCover; } CustomListTableData.CustomCellInfo cell = new CustomListTableData.CustomCellInfo(platform.platName, platform.platAuthor, platform.icon); foreach (CustomListTableData listTable in _platformListsView.allListTables) { listTable.data.Add(cell); listTable.tableView.ReloadData(); } } if (apiRequest) { _platformManager.apiRequestIndex = _platformManager.allPlatforms.IndexOf(platform); apiRequest = false; } })); }
/// <summary> /// Loads all platforms or their descritpors if a cache file exists /// </summary> private void Reload() { if (!Directory.Exists(customPlatformsFolderPath)) { Directory.CreateDirectory(customPlatformsFolderPath); } allPlatforms = new List <CustomPlatform>(); string[] bundlePaths = Directory.GetFiles(customPlatformsFolderPath, "*.plat"); Sprite[] allSprites = Resources.FindObjectsOfTypeAll <Sprite>(); Sprite lvlInsaneCover = allSprites.First(x => x.name == "LvlInsaneCover"); fallbackCover = allSprites.First(x => x.name == "FeetIcon"); CustomPlatform defaultPlatform = new GameObject("Default Platform").AddComponent <CustomPlatform>(); defaultPlatform.transform.parent = transform; defaultPlatform.platName = "Default Environment"; defaultPlatform.platAuthor = "Beat Saber"; defaultPlatform.icon = lvlInsaneCover; allPlatforms.Add(defaultPlatform); if (File.Exists(customPlatformsInfoCacheFilePath)) { LoadPlatformInfosFromFile(); foreach (string path in bundlePaths.Select(x => Path.GetFullPath(x)).Except(allPlatforms.Select(x => x.fullPath))) { StartCoroutine(_platformLoader.LoadFromFileAsync(path, HandlePlatformLoaded)); } } else { foreach (string path in bundlePaths) { string fullPath = Path.GetFullPath(path); StartCoroutine(_platformLoader.LoadFromFileAsync(fullPath, HandlePlatformLoaded)); } } }
/// <summary> /// Changes to a specific <see cref="CustomPlatform"/> /// </summary> /// <param name="index">The index of the new <see cref="CustomPlatform"/> in the list <see cref="AllPlatforms"/></param> internal void ChangeToPlatform(int index) { if (!_platformManager.allPlatforms[index].requirements.All(x => _platformManager.allPluginNames.Contains(x))) { _siraLog.Warning("Missing requirement for platform " + _platformManager.allPlatforms[index].name); ChangeToPlatform(0); return; } _siraLog.Info("Switching to " + _platformManager.allPlatforms[index].name); _platformManager.activePlatform?.gameObject.SetActive(false); DestroyCustomObjects(); _platformManager.activePlatform = _platformManager.allPlatforms[index]; SharedCoroutineStarter.instance.StartCoroutine(WaitAndSpawn()); IEnumerator WaitAndSpawn() { if (_platformManager.activePlatform.transform.childCount == 0 && index != 0) { yield return(SharedCoroutineStarter.instance.StartCoroutine(_platformLoader.LoadFromFileAsync(_platformManager.activePlatform.fullPath, _platformManager.HandlePlatformLoaded))); } yield return(new WaitForEndOfFrame()); if (index != 0) { _platformManager.activePlatform.gameObject.SetActive(true); AddManagers(_platformManager.activePlatform); SpawnCustomObjects(); } else { _platformManager.activePlatform = null; } _hider.HideObjectsForPlatform(_platformManager.allPlatforms[index]); } }