之前的面试的时候有被问到,像4月4号清明节的时候,很多软件的界面都变成灰色,想要实现这个有什么思路,当时由于紧张,没有什么思路,后面想想,用屏幕后处理是可以实现的,像很多游戏,主角死亡后,游戏画面变灰,会不会也是这么实现的呢?话不多说,直接上代码:
CS代码:
首先我要准备渲染RenderTexture的材质,这里我们使用一个可以在屏幕后处理中使用的通用基类。
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
public class PostEffectsBase : MonoBehaviour {
protected void Start() {
CheckResources();
}
protected void CheckResources() {
bool isSupported = CheckSupport();
if (isSupported == false) {
NotSupported();
}
}
// 检测设备是否支持屏幕特效和渲染纹理
protected bool CheckSupport() {
if (SystemInfo.supportsImageEffects == false || SystemInfo.supportsRenderTextures == false) {
Debug.LogWarning("This platform does not support image effects or render textures.