示例#1
0
    public static void SaveForColor(string color)
    {
        PEThumbLight thumbLight = GameObject.FindObjectOfType <PEThumbLight>();

        if (thumbLight == null)
        {
            throw new Exception(">>>> pblight is not found!");
        }

        thumbLight.lightName = color;

        string prefabPath = "Assets/BlockEditor/Resources/ThumbLight/" + thumbLight.prefabName + ".prefab";

        UnityEditor.PrefabUtility.CreatePrefab(prefabPath, thumbLight.gameObject, UnityEditor.ReplacePrefabOptions.ReplaceNameBased);
    }
示例#2
0
    private Texture2D RenderThumb(ThumbExportElement thumbExportInfo, GameObject obj, bool destroyObj)
    {
        var prefabName = thumbExportInfo.PrefabName;

        if (obj == null)
        {
            return(null);
        }

        if (thumbLight == null || thumbLight.lightName != thumbExportInfo.light)
        {
            thumbLight = PEThumbLighting.LoadForColor(thumbExportInfo.light).GetComponent <PEThumbLight>();
        }

        obj.transform.SetParent(transParent, false);
        obj.name = prefabName;
        obj.transform.localEulerAngles = thumbExportInfo.eulerAngle;

        AdjustCamera(obj);

        mCamera.Render();

        RenderTexture.active = cameraRT;
        outTexture.ReadPixels(new Rect(0, 0, SCREEN_SIZE, SCREEN_SIZE), 0, 0);
        outTexture.Apply(false);
        RenderTexture.active = null;

        //修正alpha
        Color[] colors_opaque = outTexture.GetPixels();
        for (int j = 0; j < colors_opaque.Length; j++)
        {
            Color color = colors_opaque[j];
            colors_opaque[j] = color.a > 0 ? new Color(color.r, color.g, color.b, 1) : color;
        }
        outTexture.SetPixels(colors_opaque);
        outTexture.Apply(false);

        if (destroyObj)
        {
            DestroyImmediate(obj);
        }

        return(outTexture);
    }
示例#3
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;
    }
示例#4
0
    public static GameObject LoadForColor(string color)
    {
        PEThumbLight thumbLight = GameObject.FindObjectOfType <PEThumbLight>();

        if (thumbLight != null)
        {
            GameObject.DestroyImmediate(thumbLight.gameObject);
        }

        string prefabName = string.IsNullOrEmpty(color) ? "pblight" : "pblight_" + color;

        if (!File.Exists(Path.Combine(Application.dataPath, "BlockEditor/Resources/ThumbLight/" + prefabName + ".prefab")))
        {
            prefabName = "pblight";
        }

        GameObject lightPrefab = Resources.Load <GameObject>("ThumbLight/" + prefabName);
        GameObject lightObj    = GameObject.Instantiate(lightPrefab);

        lightObj.name = prefabName;

        return(lightObj);
    }
示例#5
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());
    }