/// <summary> /// 异步初始化block /// </summary> /// <param name="configFile"></param> /// <param name="keyframeSpeed"></param> /// <param name="layer"></param> /// <param name="onLoadBlockInfoFinish">返回值1: AnimNode个数;返回值2:keyframe个数</param> /// <param name="LoadblockSpeed">-1为无限制</param> public IEnumerator AsyncInitBlocks(string configFile, float keyframeSpeed, string layer = "Default", Action <int, int> onLoadBlockInfoFinish = null, int LoadblockSpeed = -1) { ClearData(); InitBlockInfo(configFile); //keyframe第0帧不算,所以KeyfameInfos.Count - 1 onLoadBlockInfoFinish.InvokeGracefully(mBlockConfigInfo.AnimNodeInfos.Count, mBlockConfigInfo.KeyfameInfos.Count - 1); yield return(null); var finish = false; PPObjLoader.LoadBlocks(mBlockConfigInfo, transform, mAnimNodes, new PPObjLoader.LoadConfig { LoadSpeed = LoadblockSpeed }, () => finish = true); while (!finish) { yield return(null); } mCurLayer = layer; transform.SetLayer(LayerMask.NameToLayer(mCurLayer)); InitKeyframeMgr(keyframeSpeed); InitLight(); yield return(null); mIsBlockLoadedFinished = true; }
/// <summary> /// 外部调用,生成单个零件 /// </summary> public static PPObjLoader LoadBlock(PPPrefabInfo prefabInfo, PPBlockInfo nodeInfo, Transform parent, Action <GameObject> onFinishWithObj) { GameObject obj = new GameObject("PPObjLoader"); obj.transform.SetParent(RootObj); PPObjLoader loader = obj.AddComponent <PPObjLoader>(); loader.mPrefabInfo = prefabInfo; loader.nodeInfo = nodeInfo; loader.parent = parent; loader.onFinishWithObj = onFinishWithObj; loader.StartCoroutine(loader.AsyncLoadBlock()); return(loader); }
public static PPObjLoader LoadBlocks(PPBlockConfigInfo blockConfigInfo, Transform parent, Dictionary <int, GameObject> animNodes, LoadConfig loadConfig, Action onFinish = null) { GameObject obj = new GameObject("PPObjLoader"); obj.transform.SetParent(RootObj); PPObjLoader loader = obj.AddComponent <PPObjLoader>(); loader.mBlockConfigInfo = blockConfigInfo; loader.sectionInfo = loader.mBlockConfigInfo.SectionInfo; loader.parent = parent; loader.mAnimNodes = animNodes; loader.loadConfig = loadConfig; loader.onFinish = onFinish; loader.StartCoroutine(loader.AsyncLoadBlocks()); return(loader); }
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 InnerStartPreview() { if (m_ExportInfo == null || m_ExportInfo.thumbs == null || m_ExportInfo.thumbs.Length != 1) { yield break; } PrepareRender(); PEThumbLight[] lights = GameObject.FindObjectsOfType <PEThumbLight>(); for (int i = 1; i < lights.Length; i++) { GameObject.DestroyImmediate(lights[i].gameObject); } thumbLight = lights.Length > 0 ? lights[0] : null; GameObject obj = null; var finish = false; var exportInfo = m_ExportInfo.thumbs[0]; PPObjLoader.LoadBlock(exportInfo.PrefabInfo, exportInfo.BlockInfo, transParent, o => { finish = true; obj = o; }); while (!finish) { yield return(null); } if (obj == null) { yield break; } yield return(null); Texture2D texture = RenderThumb(m_ExportInfo.thumbs[0], obj, false); RawImage previewImage = FindObjectOfType <RawImage>(); previewImage.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, SCREEN_SIZE); previewImage.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, SCREEN_SIZE); previewImage.texture = texture; }
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()); }