protected virtual void OnEnable() { // buffer object setup if (bufferObj == null) { bufferObj = OffscreenBuffer.Create(width, height, depth, rtFormat, depthMode, cullingMask, clearFlags, clearColor, replacementShader, replacementTag); } }
/// <summary> /// Creates a GameObject with an OffscreenBuffer and required Camera with the specified properties. /// </summary> public static OffscreenBuffer Create(int width, int height, int depth, RenderTextureFormat format, DepthTextureMode depthMode, LayerMask layerMask, CameraClearFlags clearFlags, Color clearColor, Shader replacementShader, string replacementTag) { GameObject tmp = new GameObject("Offscreen Buffer Camera"); // we want to do some setup before we activate so things adhere to Monobehaviour execution order. tmp.SetActive(false); tmp.AddComponent <Camera>(); OffscreenBuffer c = tmp.AddComponent <OffscreenBuffer>(); c.width = width; c.height = height; c.depth = depth; c.format = format; c.cullingMask = layerMask.value; c.clearFlags = clearFlags; c.clearColor = clearColor; if (replacementShader != null) { c.replacementShader = replacementShader; c.replacementTag = replacementTag; } tmp.SetActive(true); return(c); }