Version: 2017.1
public static void Viewport (Rect pixelRect);

Descripción

Set the rendering viewport.

All rendering is constrained to be inside the passed pixelRect. If the Viewport is modified, all the rendered content inside of it gets stretched.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Material mat; private bool stretch = false; void Update() { if (Input.GetKeyDown(KeyCode.Space)) if (stretch) stretch = false; else stretch = true; } void OnPostRender() { if (!mat) { Debug.LogError("Please Assign a material on the inspector"); return; } GL.PushMatrix(); mat.SetPass(0); GL.LoadPixelMatrix(); if (stretch) GL.Viewport(new Rect(0, 0, Screen.width, Screen.height)); else GL.Viewport(new Rect(0, 0, Screen.width / 2, Screen.height)); GL.Color(Color.red); GL.Begin(GL.QUADS); GL.Vertex3(0, 0, 0); GL.Vertex3(0, Screen.height, 0); GL.Vertex3(Screen.width, Screen.height, 0); GL.Vertex3(Screen.width, 0, 0); GL.Color(Color.yellow); GL.End(); GL.Begin(GL.TRIANGLES); GL.Vertex3(Screen.width / 2, Screen.height / 4, 1); GL.Vertex3(Screen.width / 4, Screen.height / 2, 1); GL.Vertex3(Screen.width - Screen.width / 4, Screen.height / 2, 1); GL.End(); GL.PopMatrix(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961