Loading a Component
Basic
Use Component.Create()
.
You can load from ReadOnlySpan<byte>
or ReadOnlySequence<byte>
.
using WaaS.ComponentModel.Models;
Span<byte> bytes = System.IO.File.LoadAllBytes("foo.wasm");
var component = Component.Create(bytes);
Streaming
Not supported at the moment.
Loading as an Asset Unity
When you import a file with the extension *.wasm
into a Unity project, it is automatically loaded as a WaaS.Unity.ComponentAsset
.
info
Both modules and components have the extension *.wasm
, but they are automatically distinguished upon import.
Modules can be assigned as [SerializeField]
and loaded with ComponentAsset.LoadComponent()
or ComponentAsset.LoadComponentAsync()
.
using UnityEngine;
using WaaS.Unity;
[SerializeField] private ComponentAsset componentAsset;
// synchronous
var component = componentAsset.LoadComponent();
// asynchronous
var component = await componentAsset.LoadComponentAsync();
By enabling Deserialize On Load
in the settings of ComponentAsset
, the module is preloaded synchronously when the asset is loaded.
This reduces the waiting time for ComponentAsset.LoadComponent()
.