private Texture2D GeneratePrefabPreviewTextureAndStore(Prefab prefab) { PrefabPreviewGenerator.Get().BeginPreviewGenSession(); Texture2D prefabPreview = PrefabPreviewGenerator.Get().GeneratePreview(prefab); PrefabPreviewGenerator.Get().EndPreviewGenSession(); if (prefabPreview != null) { _prefabToPreviewTexture.Add(prefab, prefabPreview); } return(prefabPreview); }
public void GeneratePreviewsForPrefabCollection(List <Prefab> prefabs, bool showProgress) { int numPrefabs = prefabs.Count; if (numPrefabs == 0) { return; } PrefabPreviewGenerator.Get().BeginPreviewGenSession(); if (!showProgress) { foreach (var prefab in prefabs) { if (prefab == null || prefab.UnityPrefab == null || IsPreviewTextureAvailableForPrefab(prefab)) { continue; } Texture2D prefabPreview = PrefabPreviewGenerator.Get().GeneratePreview(prefab); if (prefabPreview != null) { _prefabToPreviewTexture.Add(prefab, prefabPreview); } } } else { float invPrefabCount = 1.0f / numPrefabs; for (int prefabIndex = 0; prefabIndex < numPrefabs; ++prefabIndex) { Prefab prefab = prefabs[prefabIndex]; if (prefab == null || prefab.UnityPrefab == null || IsPreviewTextureAvailableForPrefab(prefab)) { continue; } EditorUtility.DisplayProgressBar("Generating prefab previews...", "Prefab: " + prefab.UnityPrefab.name, (float)(prefabIndex + 1) * invPrefabCount); Texture2D prefabPreview = PrefabPreviewGenerator.Get().GeneratePreview(prefab); if (prefabPreview != null) { _prefabToPreviewTexture.Add(prefab, prefabPreview); } } EditorUtility.ClearProgressBar(); } PrefabPreviewGenerator.Get().EndPreviewGenSession(); }
public void GeneratePreviewForAllPrefabCategories(bool showProgress) { PrefabPreviewGenerator.Get().BeginPreviewGenSession(); if (!showProgress) { PrefabCategoryDatabase categoryDatabase = PrefabCategoryDatabase.Get(); List <PrefabCategory> allCategories = categoryDatabase.GetAllPrefabCategories(); foreach (var category in allCategories) { int numPrefabs = category.NumberOfPrefabs; if (numPrefabs == 0) { continue; } List <Prefab> allPrefabs = category.GetAllPrefabs(); foreach (var prefab in allPrefabs) { if (prefab == null || prefab.UnityPrefab == null || IsPreviewTextureAvailableForPrefab(prefab)) { continue; } Texture2D prefabPreview = PrefabPreviewGenerator.Get().GeneratePreview(prefab); if (prefabPreview != null) { _prefabToPreviewTexture.Add(prefab, prefabPreview); } } } } else { PrefabCategoryDatabase categoryDatabase = PrefabCategoryDatabase.Get(); List <PrefabCategory> allCategories = categoryDatabase.GetAllPrefabCategories(); foreach (var category in allCategories) { int numPrefabs = category.NumberOfPrefabs; if (numPrefabs == 0) { continue; } float invPrefabCount = 1.0f / numPrefabs; List <Prefab> allPrefabs = category.GetAllPrefabs(); for (int prefabIndex = 0; prefabIndex < allPrefabs.Count; ++prefabIndex) { Prefab prefab = allPrefabs[prefabIndex]; if (prefab == null || prefab.UnityPrefab == null || IsPreviewTextureAvailableForPrefab(prefab)) { continue; } EditorUtility.DisplayProgressBar("Generating prefab previews (" + category.Name + ")", "Prefab: " + prefab.UnityPrefab.name, (float)(prefabIndex + 1) * invPrefabCount); Texture2D prefabPreview = PrefabPreviewGenerator.Get().GeneratePreview(prefab); if (prefabPreview != null) { _prefabToPreviewTexture.Add(prefab, prefabPreview); } } } EditorUtility.ClearProgressBar(); } PrefabPreviewGenerator.Get().EndPreviewGenSession(); }