-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
62 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use fyrox::{asset::event::ResourceEvent, asset::manager::ResourceManager}; | ||
use std::sync::mpsc::channel; | ||
|
||
// ANCHOR: subscribe_to_events | ||
pub fn subscribe_to_events(resource_manager: &ResourceManager) { | ||
let (sender, receiver) = channel(); | ||
resource_manager.state().event_broadcaster.add(sender); | ||
|
||
while let Ok(event) = receiver.try_recv() { | ||
match event { | ||
ResourceEvent::Loaded(_) => {} | ||
ResourceEvent::Reloaded(_) => {} | ||
ResourceEvent::Added(_) => {} | ||
ResourceEvent::Removed(_) => {} | ||
} | ||
} | ||
} | ||
|
||
// ANCHOR_END: subscribe_to_events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod custom; | ||
pub mod events; | ||
pub mod model; | ||
pub mod sound; | ||
pub mod state; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Events | ||
|
||
Resource manager is able to notify its subscribers about specific events of resources. There are four kinds of resource | ||
events: | ||
|
||
1) `Loaded` - occurs when a resource was fully loaded without any errors. | ||
2) `Reloaded` - occurs when a resource was already fully loaded, but was reloaded by an explicit request. | ||
3) `Added` - occurs when a resource was just added to the resource manager. This event is fired right after a resource | ||
was requested from the manager. | ||
4) `Removed` - occurs when a resource was removed from the resource manager. This event is fired when the resource | ||
manager removes and unloads an unused resource. | ||
|
||
To subscribe for resource events use the event broadcaster: | ||
|
||
```rust | ||
{{#include ../code/snippets/src/resource/events.rs:subscribe_to_events}} | ||
``` |