RenderMode

enumeration

切换到手册

描述

Canvas 的 RenderMode。

//Attach this script to your Canvas GameObject

using UnityEngine;

public class Example : MonoBehaviour { enum RenderModeStates { camera, overlay, world }; RenderModeStates m_RenderModeStates;

Canvas m_Canvas;

// Use this for initialization void Start() { m_Canvas = GetComponent<Canvas>(); }

// Update is called once per frame void Update() { //Press the space key to switch between render mode states if (Input.GetKeyDown(KeyCode.Space)) { ChangeState(); } }

void ChangeState() { switch (m_RenderModeStates) { case RenderModeStates.camera: m_Canvas.renderMode = RenderMode.ScreenSpaceCamera; m_RenderModeStates = RenderModeStates.overlay; break;

case RenderModeStates.overlay: m_Canvas.renderMode = RenderMode.ScreenSpaceOverlay; m_RenderModeStates = RenderModeStates.world; break; case RenderModeStates.world: m_Canvas.renderMode = RenderMode.WorldSpace; m_RenderModeStates = RenderModeStates.camera;

break; } } }

变量

ScreenSpaceOverlay使用 2D Canvas 在场景末端渲染。
ScreenSpaceCamera使用在 Canvas 上配置的 Camera 渲染。
WorldSpace使用场景中可渲染该层的任意 Camera 渲染。