pub fn to_writer_pretty<W, T>(
writer: W,
value: &T,
config: PrettyConfig
) -> Result<(), Error>
Expand description
Serializes value
into writer
in a pretty way.
Examples found in repository?
examples/animation/animation_graph.rs (lines 190-194)
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
fn setup_assets_programmatically(
commands: &mut Commands,
asset_server: &mut AssetServer,
animation_graphs: &mut Assets<AnimationGraph>,
_save: bool,
) {
// Create the nodes.
let mut animation_graph = AnimationGraph::new();
let blend_node = animation_graph.add_blend(0.5, animation_graph.root);
animation_graph.add_clip(
asset_server.load("models/animated/Fox.glb#Animation0"),
1.0,
animation_graph.root,
);
animation_graph.add_clip(
asset_server.load("models/animated/Fox.glb#Animation1"),
1.0,
blend_node,
);
animation_graph.add_clip(
asset_server.load("models/animated/Fox.glb#Animation2"),
1.0,
blend_node,
);
// If asked to save, do so.
#[cfg(not(target_arch = "wasm32"))]
if _save {
let animation_graph = animation_graph.clone();
IoTaskPool::get()
.spawn(async move {
let mut animation_graph_writer = File::create(Path::join(
&FileAssetReader::get_base_path(),
Path::join(Path::new("assets"), Path::new(ANIMATION_GRAPH_PATH)),
))
.expect("Failed to open the animation graph asset");
ron::ser::to_writer_pretty(
&mut animation_graph_writer,
&animation_graph,
PrettyConfig::default(),
)
.expect("Failed to serialize the animation graph");
})
.detach();
}
// Add the graph.
let handle = animation_graphs.add(animation_graph);
// Save the assets in a resource.
commands.insert_resource(ExampleAnimationGraph(handle));
}