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 Forget for OverlaySurface
impl Freeze for OverlaySurface
impl Move for OverlaySurface
impl RefUnwindSafe for OverlaySurface
impl Send for OverlaySurface
impl Sync for OverlaySurface
impl Unpin for OverlaySurface
impl UnsafeUnpin for OverlaySurfacewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
&'static Il2Cpp: UnsafeUnpin,
*mut c_void: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more