public Campaign(CampaignListViewController viewController, string path) : base("", "", null) { this.path = path; challenges = new List <Challenge>(); info = JsonConvert.DeserializeObject <CampaignInfo>(File.ReadAllText(path + "/info.json")); viewController.StartCoroutine(LoadSprite(viewController, "file:///" + path + "/cover.png", false)); if (File.Exists(path + "/map background.png")) { viewController.StartCoroutine(LoadSprite(viewController, "file:///" + path + "/map background.png", true)); } int i = 0; while (File.Exists(path + "/" + i + ".json")) { string rawJSON = File.ReadAllText(path + "/" + i + ".json").Replace("\n", ""); Challenge challenge = JsonConvert.DeserializeObject <Challenge>(rawJSON); challenge.rawJSON = rawJSON; challenges.Add(challenge); i++; } if (File.Exists(path + "/id")) { leaderboardID = File.ReadAllText(path + "/id"); } text = info.name; subtext = info.desc; }
protected override void DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { if (firstActivation) { SetTitle("Custom Campaigns"); showBackButton = true; _campaignFlowCoordinator = Resources.FindObjectsOfTypeAll <CampaignFlowCoordinator>().First(); _missionMapAnimationController = Resources.FindObjectsOfTypeAll <MissionMapAnimationController>().First(); _missionNodesManager = Resources.FindObjectsOfTypeAll <MissionNodesManager>().First(); _missionStagesManager = Resources.FindObjectsOfTypeAll <MissionStagesManager>().First(); _missionConnectionsGenerator = Resources.FindObjectsOfTypeAll <MissionConnectionsGenerator>().First(); _missionSelectionMapViewController = Resources.FindObjectsOfTypeAll <MissionSelectionMapViewController>().First(); _missionNodeSelectionManager = Resources.FindObjectsOfTypeAll <MissionNodeSelectionManager>().First(); _missionLevelDetailViewController = Resources.FindObjectsOfTypeAll <MissionLevelDetailViewController>().First(); _missionResultsViewController = Resources.FindObjectsOfTypeAll <MissionResultsViewController>().First(); _playButton = _missionLevelDetailViewController.GetPrivateField <Button>("_playButton"); _mapScrollView = _missionSelectionMapViewController.GetPrivateField <ScrollView>("_mapScrollView"); _mapScrollViewItemsVisibilityController = _mapScrollView.GetComponent <ScrollViewItemsVisibilityController>(); _backgroundImage = _mapScrollView.GetComponentsInChildren <Image>().First(x => x.name == "Map"); _missionSelectionNavigationController = _campaignFlowCoordinator.GetPrivateField <MissionSelectionNavigationController>("_missionSelectionNavigationController"); _gameplayModifierInfoListItemsList = _missionLevelDetailViewController.GetPrivateField <GameplayModifierInfoListItemsList>("_gameplayModifierInfoListItemsList"); _modifiersPanelGO = _missionLevelDetailViewController.GetPrivateField <GameObject>("_modifiersPanelGO"); _gameplayModifiersModel = _missionLevelDetailViewController.GetPrivateField <GameplayModifiersModelSO>("_gameplayModifiersModel"); BSMLParser.instance.Parse(Utilities.GetResourceContent(Assembly.GetExecutingAssembly(), "BeatSaberCustomCampaigns.Views.challenge-detail.bsml"), _missionLevelDetailViewController.gameObject, this); _campaignProgressModel = _campaignFlowCoordinator.GetPrivateField <CampaignProgressModel>("_campaignProgressModel"); _campaignListViewController = BeatSaberUI.CreateViewController <CampaignListViewController>(); _campaignDetailViewController = BeatSaberUI.CreateViewController <CampaignDetailViewController>(); _campaignTotalLeaderboardViewController = BeatSaberUI.CreateViewController <CampaignTotalLeaderboardViewController>(); _campaignListNavigationController = BeatSaberUI.CreateViewController <NavigationController>(); _campaignListViewController.clickedCampaign += ShowDetails; _campaignDetailViewController.clickedPlay += OpenCampaign; _campaignChallengeLeaderbaordViewController = BeatSaberUI.CreateViewController <CampaignChallengeLeaderboardViewController>(); _unlockedItemsViewController = BeatSaberUI.CreateViewController <UnlockedItemsViewController>(); } if (addedToHierarchy) { SetBaseCampaignEnabled(false); SetViewControllerToNavigationController(_campaignListNavigationController, _campaignListViewController); ProvideInitialViewControllers(_campaignListNavigationController); } }
private IEnumerator LoadSprite(CampaignListViewController viewController, string spritePath, bool isBackground) { if (!loadedTextures.ContainsKey(spritePath)) { using (var web = UnityWebRequestTexture.GetTexture(APITools.EncodePath(spritePath), true)) { yield return(web.SendWebRequest()); if (web.isNetworkError || web.isHttpError) { icon = null; } else { Texture2D tex = DownloadHandlerTexture.GetContent(web); //Sprite sprite = ; loadedTextures.Add(spritePath, tex); if (isBackground) { background = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f, 100, 1); } else { icon = tex; } } } } else { Texture2D tex = loadedTextures[spritePath]; if (isBackground) { background = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f, 100, 1); } else { icon = tex; } } if (!isBackground) { viewController.customListTableData.tableView.ReloadData(); } }