pub struct OverlaySurface { /* private fields */ }Expand description
A full-screen off-screen target shown on top of the game’s UI, for drawing an
overlay with the gl module.
Immediate-mode gl drawn straight from on_render sits
under the game’s screen-space UI, which the engine composites after the
cameras. An OverlaySurface instead draws into a RenderTexture that a
RawImage on a top-most OverlayCanvas composites over everything. The
target follows the screen size and is rebuilt if a scene load destroys it.
use hao_il2cpp_unity::{gl, on_render, screen, Color, OverlaySurface};
use std::sync::Mutex;
let surface = Mutex::new(OverlaySurface::new("my-overlay"));
on_render(move |_camera| {
let (w, h) = screen::size().unwrap();
let mut surface = surface.lock().unwrap();
let _ = surface.draw((w, h), Color::CLEAR, || {
gl::load_pixel_matrix(0.0, w as f32, 0.0, h as f32);
gl::draw(gl::Mode::Quads, || {
gl::color(Color::RED);
for (x, y) in [(10.0, 10.0), (110.0, 10.0), (110.0, 60.0), (10.0, 60.0)] {
let _ = gl::vertex(x, y);
}
})
});
})?;Implementations§
Source§impl OverlaySurface
impl OverlaySurface
Sourcepub fn new(name: &str) -> Self
pub fn new(name: &str) -> Self
name is the overlay GameObject’s name (useful when inspecting the scene).
Sourcepub fn draw(
&mut self,
size: (i32, i32),
clear: Color,
body: impl FnOnce() -> Result<()>,
) -> Result<()>
pub fn draw( &mut self, size: (i32, i32), clear: Color, body: impl FnOnce() -> Result<()>, ) -> Result<()>
Sourcepub fn target(&self) -> Option<RenderTexture>
pub fn target(&self) -> Option<RenderTexture>
The render texture, e.g. to bind as a material’s texture while drawing.
None until the first draw.
Sourcepub fn canvas(&self) -> Option<&OverlayCanvas>
pub fn canvas(&self) -> Option<&OverlayCanvas>
The overlay canvas, once created (after the first draw).
Auto Trait Implementations§
impl Freeze for OverlaySurface
impl RefUnwindSafe for OverlaySurface
impl Send for OverlaySurface
impl Sync for OverlaySurface
impl Unpin for OverlaySurface
impl UnsafeUnpin for OverlaySurface
impl UnwindSafe for OverlaySurface
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more