static public void DrawTexture(Vector3 center, Vector2 size, Texture2D texture) { Mesh mesh = MeshExtensions.CreateCenterQuad(size); Material material = MaterialExtensions.CreateUnlitTransparentTextureMaterial(texture); material.SetPass(0); Graphics.DrawMeshNow( mesh, Matrix4x4.TRS( center, Quaternion.LookRotation(Camera.current.GetSpacarForward(), Vector3.up), Vector3.one ) ); }
private void Render() { Rect rect = bounds.GetPlanar(); Clear(); Camera camera = this.AddChild(new GameObject("Camera")).AddComponent <Camera>(); camera.enabled = false; camera.clearFlags = CameraClearFlags.SolidColor; camera.backgroundColor = Color.clear; camera.cullingMask = source_mask; camera.nearClipPlane = -1.0f; camera.orthographic = true; camera.orthographicSize = orthographic_size; camera.aspect = 1.0f; int number_chunks = 0; Vector2 cell_size = camera.GetOrthographicSize() - margins; rect.ProcessOverflownGrid(cell_size, delegate(int x, int y, Rect sub_rect) { if (number_chunks < maximum_number_chunks) { GameObject cell = this.AddChild(new GameObject("RenderedCell")); cell.SetPlanarPosition(sub_rect.center); camera.SetPlanarPosition(sub_rect.center); Texture2D rendered = camera.RenderToTexture2D(0); MeshFilter mesh_filter = cell.AddComponent <MeshFilter>(); MeshRenderer mesh_renderer = cell.AddComponent <MeshRenderer>(); rendered.filterMode = filter_mode; mesh_filter.mesh = MeshExtensions.CreateCenterQuad(sub_rect.GetSize() + margins); mesh_renderer.material = MaterialExtensions.CreateUnlitTransparentTextureMaterial(rendered); mesh_renderer.SetSortingLayer(destination_layer); number_chunks++; } }); camera.DestroyGameObjectAdvisory(); }