using UnityEngine;
using UnityEngine.UI;
public class CameraRTT
{
public RenderTexture ShowTex { get { return m_renderTexture; } }
static int Layer_ModelRTT = 9;
static int s_count = 0;
private RenderTexture m_renderTexture;
private GameObject m_gameObject;
private Camera m_camera;
public CameraRTT(int size = 512)
{
s_count++;
m_renderTexture = new RenderTexture(size, size, 24, RenderTextureFormat.ARGB32);
m_renderTexture.name = "RTTTexture" + s_count;
m_gameObject = new GameObject("RTTGameObject" + s_count);
m_gameObject.layer = Layer_ModelRTT;
m_gameObject.transform.localPosition = new Vector3(s_count * 100f, 0f, 0f);
m_gameObject.SetActive(false);
m_camera = m_gameObject.AddComponent<Camera>();
m_camera.orthographic = true;
m_camera.orthographicSize = 1;
m_camera.cullingMask = 1 << Layer_ModelRTT;
m_camera.clearFlags = CameraClearFlags.SolidColor;
}
public void ShowSingleModel(GameObject obj, RawImage uiTexture, Vector3 pos, Vector3 rot, Vector3 scale)
{
if (m_gameObject == null || m_camera == null) return;
obj.transform.parent = m_gameObject.transform;
obj.layer = Layer_ModelRTT;
obj.transform.localPosition = pos;
obj.transform.eulerAngles = rot;
obj.transform.localScale = scale;
m_camera.targetTexture = m_renderTexture;
uiTexture.texture = m_renderTexture;
m_gameObject.SetActive(true);
}
}
摄像头拍摄模型、特效给UI
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 实战需求 SwiftUI Metal入门教程之打开摄像头并实现滤波特效 (教程含完整源码) 本文价值与收获 看完本...
- 相关解释来自这里 原文答案:If you turned your camera properly when tak...