Unity は背景が透明なスクリーンショットを生成し、スクリーンショットの背景画像は透明であり、UGUI スクロールビューがスライドするときに 3D モデルをマスクすることはできません

復刻 【Unity3D】Unity3Dカメラでスクリーンショット透過 - ジングル♂フィッシュ - Blog Garden

using System;
using UnityEngine;
using System.IO;

public class CropPicture : MonoBehaviour
{
    public Camera cropCamera; //待截图的目标摄像机
    RenderTexture renderTexture;
    Texture2D texture2D;

    void Start()
    {
        renderTexture = new RenderTexture(800, 600, 32);
        texture2D = new Texture2D(800, 600, TextureFormat.ARGB32, false);
        cropCamera.targetTexture = renderTexture;
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            RenderTexture.active = renderTexture;
            texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
            texture2D.Apply();
            RenderTexture.active = null;
            
            byte[] bytes = texture2D.EncodeToPNG();
            File.WriteAllBytes(Application.dataPath + "//pic//" + (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds + ".png", bytes);
        }
    }
}

次に、このスクリプトをメイン カメラにドラッグします。

スクリーンショットを撮る必要がある新しいカメラを作成します。なぜ新しいカメラを作成する必要があるのですか? スカイボックスを持てないからです。

次に、このカメラ オブジェクトをメイン カメラの CropPicture スクリプトの CropCamera 変数にドラッグします。

次に、スクリーンショットを撮る必要があるカメラのプロパティの無地の色を設定し、背景を透明に設定します

これは、3D モデルのスクリーンショットを生成し、キャラクターのバックパックの一覧などの ui に表示するために使用できます. 写真を表示する必要がありますが、モデルを表示する必要はありません. モデルの表示UGUIのスクロールビューがマスクで覆われなくなり、スライド時にモデルが表示されなくなる.UI上に表示されており、シェーダーを書くことでしか解決できない.シェーダーは本当に理解していない. バックパック内のモデルのスクリーンショットを動的に生成してリストに表示し、リスト項目をクリックすると、別のモデルが右側に表示されます

それを記録しなさい!

おすすめ

転載: blog.csdn.net/github_38633141/article/details/123802781
おすすめ