void SetVisiblePolySet(PolySetType type) { m_CurrentSet = type; App.PolyAssetCatalog.RequestRefresh(m_CurrentSet); ResetPageIndex(); RefreshPage(); }
public void RequestRefresh(PolySetType type) { // We don't update featured except on startup. if (type != PolySetType.Featured && App.GoogleIdentity.LoggedIn) { m_AssetSetByType[type].m_RefreshRequested = true; } }
private IEnumerator <Null> RefreshAssetSet(PolySetType type) { List <AssetDetails> models = new List <AssetDetails>(); // When the list is empty, make it the actual list acted upon so that results start // showing up immediately. if (m_AssetSetByType[type].m_Models.Count == 0) { m_AssetSetByType[type].m_Models = models; } AssetLister lister = VrAssetService.m_Instance.ListAssets(type); while (lister.HasMore || models.Count == 0) { using (var cr = lister.NextPage(models, m_ThumbnailSuffix)) { while (true) { try { if (!cr.MoveNext()) { break; } } catch (VrAssetServiceException e) { ControllerConsoleScript.m_Instance.AddNewLine(e.Message); Debug.LogException(e); yield break; } yield return(cr.Current); } } if (models.Count == 0) { break; } } // As the assets may already have models loaded into them, just add any new models and // remove old ones. var newIds = new HashSet <string>(models.Select(m => m.AssetId)); var oldIds = new HashSet <string>(m_AssetSetByType[type].m_Models.Select(m => m.AssetId)); // These must be reified; if they are left as lazy IEnumerables, O(n^2) behavior results HashSet <string> toAdd = SetMinus(newIds, oldIds); HashSet <string> toRemove = SetMinus(oldIds, newIds); m_AssetSetByType[type].m_Models.RemoveAll(m => toRemove.Contains(m.AssetId)); m_AssetSetByType[type].m_Models.InsertRange(0, models.Where(m => toAdd.Contains(m.AssetId))); if (CatalogChanged != null) { CatalogChanged(); } }
protected override void OnStart() { // Initialize icons. PolyModelButton[] rPanelButtons = m_Mesh.GetComponentsInChildren <PolyModelButton>(); foreach (PolyModelButton icon in rPanelButtons) { GameObject go = icon.gameObject; icon.SetButtonGrayscale(icon); go.SetActive(false); Icons.Add(icon); } m_CurrentSet = PolySetType.Featured; // Make sure Poly gallery button starts at greyscale when panel is initialized m_PolyGalleryRenderer.material.SetFloat("_Grayscale", 1); App.PolyAssetCatalog.RequestRefresh(m_CurrentSet); App.PolyAssetCatalog.CatalogChanged += OnPolyAssetCatalogChanged; }
// Works specifically with PolySetButtons. public void ButtonPressed(PolySetType rType) { SetVisiblePolySet(rType); }
protected override void RefreshPage() { m_NoLikesMessage.SetActive(false); m_NoAuthoredModelsMessage.SetActive(false); m_NotLoggedInMessage.SetActive(false); if (VrAssetService.m_Instance.NoConnection) { m_NoPolyConnectionMessage.SetActive(true); RefreshPanelText(); base.RefreshPage(); return; } if (!VrAssetService.m_Instance.Available) { m_OutOfDateMessage.SetActive(true); RefreshPanelText(); base.RefreshPage(); return; } #if UNITY_ANDROID && OCULUS_SUPPORTED if (OVRPlugin.GetSystemHeadsetType() == OVRPlugin.SystemHeadset.Oculus_Quest) { m_NotSupportedMessage.SetActive(true); RefreshPanelText(); base.RefreshPage(); return; } #endif m_NumPages = ((App.PolyAssetCatalog.NumCloudModels(m_CurrentSet) - 1) / Icons.Count) + 1; int numCloudModels = App.PolyAssetCatalog.NumCloudModels(m_CurrentSet); if (m_LastPageIndexForLoad != PageIndex || m_LastSetTypeForLoad != m_CurrentSet) { // Unload the previous page's models. // This function may be called multiple times as icons load, only unload the old models once, // otherwise the current page's models will be thrashed. m_LastPageIndexForLoad = PageIndex; m_LastSetTypeForLoad = m_CurrentSet; // Destroy previews so only the thumbnail is visible. for (int i = 0; i < Icons.Count; i++) { ((ModelButton)Icons[i]).DestroyModelPreview(); } App.PolyAssetCatalog.UnloadUnusedModels(); } for (int i = 0; i < Icons.Count; i++) { PolyModelButton icon = (PolyModelButton)Icons[i]; // Set sketch index relative to page based index int iMapIndex = m_IndexOffset + i; // Init icon according to availability of sketch GameObject go = icon.gameObject; if (iMapIndex < numCloudModels) { PolyAssetCatalog.AssetDetails asset = App.PolyAssetCatalog.GetPolyAsset(m_CurrentSet, iMapIndex); go.SetActive(true); if (icon.Asset != null && asset.AssetId != icon.Asset.AssetId) { icon.DestroyModelPreview(); } icon.SetPreset(asset, iMapIndex); // Note that App.UserConfig.Flags.PolyModelPreload falls through to // App.PlatformConfig.EnablePolyPreload if it isn't set in Tilt Brush.cfg. if (App.UserConfig.Flags.PolyModelPreload) { icon.RequestModelPreload(PageIndex); } } else { go.SetActive(false); } } bool internetError = App.PolyAssetCatalog.NumCloudModels(PolySetType.Featured) == 0; m_InternetError.SetActive(internetError); RefreshPanelText(); switch (m_CurrentSet) { case PolySetType.User: if (!internetError) { if (App.GoogleIdentity.LoggedIn) { if (numCloudModels == 0) { m_NoAuthoredModelsMessage.SetActive(true); } } else { m_NotLoggedInMessage.SetActive(true); } } break; case PolySetType.Liked: if (!internetError) { if (App.GoogleIdentity.LoggedIn) { if (numCloudModels == 0) { m_NoLikesMessage.SetActive(true); } } else { m_NotLoggedInMessage.SetActive(true); } } break; } base.RefreshPage(); }
public AssetDetails GetPolyAsset(PolySetType type, int index) { return(m_AssetSetByType[type].m_Models[index]); }
public int NumCloudModels(PolySetType type) { return(m_AssetSetByType[type].m_Models.Count()); }