예제 #1
0
    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;
    }
예제 #2
0
    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());
    }