Я новичок в Unity и уже несколько дней пытаюсь понять, что я делаю не так.
Моя цель — сделать снимок экрана «мини-карта» (на самом деле в коде это turretCamera), которая находится в правом верхнем углу экрана. Его ширина 768 пикселей, высота 432 пикселя.
Я оставляю ниже свой сценарий, любая помощь приветствуется:
ОТРЕДАКТИРОВАНО >:
Теперь координаты написаны хорошо, но проблема остаётся та же.
void Start()
{
// Configurar el modelo y el trabajador
Model model = ModelLoader.Load(modelAsset);
worker = WorkerFactory.CreateWorker(WorkerFactory.Type.ComputePrecompiled, model);
// Configurar la render texture
// Changes made due to @derHugo's appointment
cameraTopLeftCorner = turretCamera.ViewportToScreenPoint(new Vector3(0, 1, turretCamera.nearClipPlane));
cameraBottomRightCorner = turretCamera.ViewportToScreenPoint(new Vector3(1, 0, turretCamera.nearClipPlane));
targetTextureWidth = cameraBottomRightCorner.x - cameraTopLeftCorner.x;
targetTextureHeight = cameraTopLeftCorner.y - cameraBottomRightCorner.y;
renderTexture = new RenderTexture(Mathf.CeilToInt(targetTextureWidth), Mathf.CeilToInt(targetTextureHeight), 24);
tmpRenderTexture = turretCamera.targetTexture;
turretCamera.targetTexture = renderTexture;
// cameraa.targetTexture = null;
}
private void OnGUI()
{
// ************Screenshot camera************
Texture2D texture2D = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false);
RenderTexture.active = renderTexture;
Rect RoI = new Rect(cameraTopLeftCorner.x, cameraTopLeftCorner.y, targetTextureWidth, targetTextureHeight);
Debug.Log("ROI");
Debug.Log(RoI.xMin +", " + RoI.yMin);
Debug.Log(RoI.xMax + ", " + RoI.yMax);
texture2D.ReadPixels(RoI, 0, 0);
texture2D.Apply();
// ************Screenshot camera************
// rest of code...
Подробнее здесь: https://stackoverflow.com/questions/786 ... -1792-1008
Попытка прочитать пиксели за пределами RenderTexture! Чтение (1792, -1008, 2560, -576) из (768, 432) ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Файл CSS мешает ширине панели навигации при размерах экрана менее 768 пикселей.
Anonymous » » в форуме CSS - 0 Ответы
- 61 Просмотры
-
Последнее сообщение Anonymous
-