private void PrepareRender() { PPObjLoader.ReleaseAll(); Transform parent = GameObject.Find("ThumbAnchor").transform; while (parent.childCount > 0) { GameObject.DestroyImmediate(parent.GetChild(0).gameObject); } mCamera = GetComponent <Camera>(); Color cameraColor = mCamera.backgroundColor; cameraColor.a = 0; mCamera.backgroundColor = cameraColor; SCREEN_SIZE = m_ExportInfo.scaleFactor * SIZE; if (cameraRT != null && cameraRT.width != SCREEN_SIZE) { mCamera.targetTexture = null; cameraRT.Release(); GameObject.DestroyImmediate(cameraRT); cameraRT = null; GameObject.DestroyImmediate(outTexture); outTexture = null; } if (cameraRT == null) { cameraRT = new RenderTexture(SCREEN_SIZE, SCREEN_SIZE, 24, RenderTextureFormat.ARGB32); } cameraRT.antiAliasing = 8; mCamera.targetTexture = cameraRT; if (outTexture == null) { outTexture = new Texture2D(SCREEN_SIZE, SCREEN_SIZE, TextureFormat.RGBA32, false); } transParent = GameObject.Find("ThumbAnchor").transform; }
private IEnumerator InnerStartRender() { if (m_ExportInfo == null || m_ExportInfo.thumbs == null || m_ExportInfo.thumbs.Length == 0) { onFinish.InvokeGracefully(null, "导入信息为空"); yield break; } PrepareRender(); PEThumbLight[] lights = GameObject.FindObjectsOfType <PEThumbLight>(); for (int i = 0; i < lights.Length; i++) { GameObject.DestroyImmediate(lights[i].gameObject); } thumbLight = null; for (int i = 0; i < m_ExportInfo.thumbs.Length; i++) { var thumbExportInfo = m_ExportInfo.thumbs[i]; string thumbName = thumbExportInfo.BlockInfo.Thumb.IsNotNullAndEmpty() ? thumbExportInfo.BlockInfo.Thumb : thumbExportInfo.PrefabName; var outPutPath = m_ExportInfo.saveFolder; if (!Directory.Exists(outPutPath)) { Directory.CreateDirectory(outPutPath); } string thumbPath = Path.Combine(outPutPath, (thumbName + ".png").ToLower()); Debug.LogFormat(">>>>> Export prefab_thumb {0} to thumb {1}", thumbName, thumbPath); // UnityEditor.EditorUtility.DisplayProgressBar("导出缩略图", prefabName, (float) i / m_ExportInfo.thumbs.Length); GameObject obj = null; var finish = false; PPObjLoader.LoadBlock(thumbExportInfo.PrefabInfo, thumbExportInfo.BlockInfo, transParent, o => { finish = true; obj = o; }); while (!finish) { yield return(null); } if (obj == null) { continue; } yield return(null); thumbPath.DeleteFileIfExists(); Texture2D texture = RenderThumb(thumbExportInfo, obj, true); File.WriteAllBytes(thumbPath, texture.EncodeToPNG()); if (!thumbFiles.ContainsKey(thumbPath)) { thumbFiles.Add(thumbPath, ""); } } PPObjLoader.ReleaseAll(); yield return(UploadFiles()); }