void RenderPreview() { for (int i = 0; i < sceneLights.Length; i++) { lightWasEnabled[i] = sceneLights[i].enabled; sceneLights[i].enabled = false; } RenderTexture.active = RenderTexture; instance.SetActive(true); PreviewLightA.gameObject.SetActive(true); PreviewLightB.gameObject.SetActive(true); PreviewCamera.Render(); instance.SetActive(false); PreviewLightA.gameObject.SetActive(false); PreviewLightB.gameObject.SetActive(false); for (int i = 0; i < sceneLights.Length; i++) { sceneLights[i].enabled = lightWasEnabled[i]; } }
//const float FACTOR = 0.1f; public Texture Render(Rect r, GUIStyle background, PreviewSceneManager scene, float yaw, float pitch, Vector3 position) { if (scene == null) { return(null); } using (var fog = new FogScope()) { m_previewUtility.BeginPreview(r, background); // set up the PreviewRenderUtility's mini internal scene // setup the ObjectPreview's camera scene.SetupCamera(PreviewCamera, scene.TargetPosition, yaw, pitch, position); foreach (var item in scene.EnumRenderItems) { // now, actually render out the RenderTexture //RenderMeshPreview(previewMesh, skinMeshRender.sharedMaterials); // submesh support, in case the mesh is made of multiple parts int subMeshCount = item.Mesh.subMeshCount; for (int i = 0; i < subMeshCount; i++) { m_previewUtility.DrawMesh(item.Mesh, item.Position, item.Rotation, item.Materials[i], i); } } // VERY IMPORTANT: this manually tells the camera to render and produce the render texture PreviewCamera.Render(); //m_previewUtility.Render(false, false); // reset the scene's fog from before return(m_previewUtility.EndPreview()); } }