private void PopulateList() { TransformUtils.DestroyAllChildren(_displayHolder); foreach (var mod in ModManager.Mods) { var entry = Instantiate(_listItemPrefab, _displayHolder, false); entry.GetChildByName("TopText").GetComponent <Text>().text = mod.GetModName(); entry.GetChildByName("descriptionLabel").GetComponent <Text>().text = mod.GetModDescription(); entry.GetChildByName("RightButton").GetChildByName("heading").GetComponent <Text>().text = "Disable"; entry.GetChildByName("RightButton").GetComponent <Button>().onClick = new Button.ButtonClickedEvent(); entry.GetChildByName("RightButton").GetComponent <Button>().onClick.AddListener(() => OnModButtonClick(mod)); if (mod.IsUpToDate()) { entry.GetChildByName("GrayPanel").SetActive(false); entry.GetChildByName("GrayPanelGreenText").SetActive(true); entry.GetChildByName("GrayPanelGreenText").GetComponent <Text>().text = $"v{mod.GetVersion()}"; } else { entry.GetChildByName("GrayPanelGreenText").SetActive(false); entry.GetChildByName("GrayPanel").SetActive(true); entry.GetChildByName("GrayPanel").GetChildByName("GrayPanelRedText").GetComponent <Text>().text = $"Latest: v{mod.GetLatestVersion()}"; entry.GetChildByName("GrayPanel").GetChildByName("GrayPanelGrayText").GetComponent <Text>().text = $"Current: v{mod.GetVersion()}"; } } }
static IEnumerator downloadModData(GameObject content) { UnityWebRequest webRequest = UnityWebRequest.Get("https://modbot-d8a58.firebaseio.com/mods/.json"); yield return(webRequest.SendWebRequest()); // wait for the web request to send if (webRequest.isNetworkError || webRequest.isHttpError) { yield break; } TransformUtils.DestroyAllChildren(content.transform); ModsHolder modsHolder = JsonConvert.DeserializeObject <ModsHolder>(webRequest.downloadHandler.text); GameObject modDownloadInfoPrefab = InternalAssetBundleReferences.ModsWindow.GetObject("ModDownloadInfo"); foreach (ModsHolder.ModHolder modHolder in modsHolder.Mods) { if (!modHolder.Checked) // do not want unchecked mods to come up in-game. { continue; } GameObject holder = Instantiate(modDownloadInfoPrefab); holder.transform.parent = content.transform; holder.AddComponent <ModDownloadInfoItem>().Init(modHolder); } }
/// <summary> /// Removes all of the page buttons and spawns in new ones /// </summary> public void PopulatePages() { TransformUtils.DestroyAllChildren(_pageButtonsHolder.transform); GameObject buttonPrefab = InternalAssetBundleReferences.ModsWindow.GetObject("PageButton"); foreach (Page page in _pages) { GameObject spawnedButton = GameObject.Instantiate(buttonPrefab); spawnedButton.transform.parent = _pageButtonsHolder.transform; ModdedObject moddedObject = spawnedButton.GetComponent <ModdedObject>(); moddedObject.GetObject <Text>(0).text = page.Name; moddedObject.GetObject <Button>(1).onClick.AddListener(delegate { SetPage(page); }); } }
void SetPage(Page page) { TransformUtils.DestroyAllChildren(_content.transform); page.Populate(_content, _ownerMod); }