// UpdateIcons() is called repeatedly by Update() until these three conditions are met: // 1: The SketchSet has loaded all the requested icons // 2: The textures for all the buttons have been set // 3: (Cloud only) The SketchSet has downloaded the corresponding .tilt files. // Until the .tilt file is downloaded we set a fade on the button, and need to keep updating // until the file is downloaded. private void UpdateIcons() { m_AllIconTexturesAssigned = true; m_AllSketchesAreAvailable = true; // Poll sketch catalog until icons have loaded foreach (BaseButton baseButton in Icons) { LoadSketchButton icon = baseButton as LoadSketchButton; if (icon == null) { continue; } int iSketchIndex = icon.SketchIndex; if (m_SketchSet.IsSketchIndexValid(iSketchIndex)) { icon.FadeIn = m_SketchSet.GetSketchSceneFileInfo(iSketchIndex).Available ? 1f : 0.5f; if (!icon.ThumbnailLoaded) { Texture2D rTexture = null; string[] authors; string description; if (m_SketchSet.GetSketchIcon(iSketchIndex, out rTexture, out authors, out description)) { if (rTexture != null) { // Pass through aspect ratio of image so we don't get squished // thumbnails from Poly m_ImageAspect = (float)rTexture.width / rTexture.height; float aspect = m_ImageAspect; icon.SetButtonTexture(rTexture, aspect); } else { icon.SetButtonTexture(m_UnknownImageTexture); } // Mark the texture as assigned regardless of actual bits being valid icon.ThumbnailLoaded = true; ; List <string> lines = new List <string>(); lines.Add(icon.Description); SceneFileInfo info = m_SketchSet.GetSketchSceneFileInfo(iSketchIndex); if (info is PolySceneFileInfo polyInfo && polyInfo.License != VrAssetService.kCreativeCommonsLicense) { lines.Add(String.Format("© {0}", authors[0])); lines.Add("All Rights Reserved"); } else { // Include primary author in description if available if (authors != null && authors.Length > 0) { lines.Add(authors[0]); } // Include an actual description if (description != null) { lines.Add(App.ShortenForDescriptionText(description)); } } icon.SetDescriptionText(lines.ToArray()); } else { // While metadata has not finished loading, check if this file is valid bool bFileValid = false; SceneFileInfo rInfo = m_SketchSet.GetSketchSceneFileInfo(iSketchIndex); if (rInfo != null) { bFileValid = rInfo.Exists; } // If this file isn't valid, just keep the defaults and move on if (!bFileValid) { icon.SetButtonTexture(m_UnknownImageTexture); icon.ThumbnailLoaded = true; } else { m_AllIconTexturesAssigned = false; } if (!rInfo.Available) { m_AllSketchesAreAvailable = false; } } } } }
protected override void RefreshPage() { m_SketchSet.RequestOnlyLoadedMetadata(GetIconLoadIndices()); m_AllIconTexturesAssigned = false; m_AllSketchesAreAvailable = false; // Disable all. foreach (var i in m_IconsOnFirstPage) { i.SetActive(false); } foreach (var i in m_IconsOnNormalPage) { i.SetActive(false); } // Base Refresh updates the modal parts of the panel, and we always want those refreshed. base.RefreshPage(); bool polyDown = VrAssetService.m_Instance.NoConnection && (m_CurrentSketchSet == SketchSetType.Curated || m_CurrentSketchSet == SketchSetType.Liked); m_NoPolyConnectionMessage.SetActive(polyDown); bool outOfDate = !polyDown && !VrAssetService.m_Instance.Available && (m_CurrentSketchSet == SketchSetType.Curated || m_CurrentSketchSet == SketchSetType.Liked); m_OutOfDateMessage.SetActive(outOfDate); if (outOfDate || polyDown) { m_NoSketchesMessage.SetActive(false); m_NoDriveSketchesMessage.SetActive(false); m_NotLoggedInMessage.SetActive(false); m_NoLikesMessage.SetActive(false); m_ContactingServerMessage.SetActive(false); m_NoShowcaseMessage.SetActive(false); return; } bool refreshIcons = m_SketchSet.NumSketches > 0; // Show no sketches if we don't have sketches. m_NoSketchesMessage.SetActive( (m_CurrentSketchSet == SketchSetType.User) && (m_SketchSet.NumSketches <= 0)); m_NoDriveSketchesMessage.SetActive( (m_CurrentSketchSet == SketchSetType.Drive) && (m_SketchSet.NumSketches <= 0)); // Show sign in popup if signed out for liked or drive sketchsets bool showNotLoggedIn = !App.GoogleIdentity.LoggedIn && (m_CurrentSketchSet == SketchSetType.Liked || m_CurrentSketchSet == SketchSetType.Drive); refreshIcons = refreshIcons && !showNotLoggedIn; m_NotLoggedInMessage.SetActive(showNotLoggedIn && m_CurrentSketchSet == SketchSetType.Liked); m_NotLoggedInDriveMessage.SetActive(showNotLoggedIn && m_CurrentSketchSet == SketchSetType.Drive); // Show no likes text & gallery button if we don't have liked sketches. m_NoLikesMessage.SetActive( (m_CurrentSketchSet == SketchSetType.Liked) && (m_SketchSet.NumSketches <= 0) && !m_SketchSet.IsActivelyRefreshingSketches && App.GoogleIdentity.LoggedIn); // Show Contacting Server if we're talking to Poly. m_ContactingServerMessage.SetActive( (m_CurrentSketchSet == SketchSetType.Curated || m_CurrentSketchSet == SketchSetType.Liked || m_CurrentSketchSet == SketchSetType.Drive) && (m_SketchSet.NumSketches <= 0) && (m_SketchSet.IsActivelyRefreshingSketches && App.GoogleIdentity.LoggedIn)); // Show Showcase error if we're in Showcase and don't have sketches. m_NoShowcaseMessage.SetActive( (m_CurrentSketchSet == SketchSetType.Curated) && (m_SketchSet.NumSketches <= 0) && !m_SketchSet.IsActivelyRefreshingSketches); // Refresh all icons if necessary. if (!refreshIcons) { return; } for (int i = 0; i < Icons.Count; i++) { LoadSketchButton icon = Icons[i] as LoadSketchButton; // Default to loading image icon.SetButtonTexture(m_LoadingImageTexture); icon.ThumbnailLoaded = false; // Set sketch index relative to page based index int iSketchIndex = m_IndexOffset + i; if (iSketchIndex >= m_SketchSet.NumSketches) { iSketchIndex = -1; } icon.SketchIndex = iSketchIndex; icon.ResetScale(); // Init icon according to availability of sketch GameObject go = icon.gameObject; if (m_SketchSet.IsSketchIndexValid(iSketchIndex)) { string sSketchName = m_SketchSet.GetSketchName(iSketchIndex); icon.SetDescriptionText(App.ShortenForDescriptionText(sSketchName)); SceneFileInfo info = m_SketchSet.GetSketchSceneFileInfo(iSketchIndex); if (info.Available) { m_SketchSet.PrecacheSketchModels(iSketchIndex); } if (info.TriangleCount is int triCount) { icon.WarningVisible = triCount > QualityControls.m_Instance.AppQualityLevels.WarningPolySketchTriangles; } else { icon.WarningVisible = false; } go.SetActive(true); } else { go.SetActive(false); } } }