pub struct Asset {
pub path: String,
pub guid: UnityGuid,
pub content: AssetType,
pub importer_type: ImporterType,
}Expand description
An asset to be included in a Unity package
Fields§
§path: StringPath where the asset will be placed in Unity (e.g., “Assets/Terrain/heightmap.raw”)
guid: UnityGuidThe asset’s GUID
content: AssetTypeThe asset content
importer_type: ImporterTypeImport settings
Implementations§
Source§impl Asset
impl Asset
Sourcepub fn binary(path: impl Into<String>, data: Vec<u8>) -> Self
pub fn binary(path: impl Into<String>, data: Vec<u8>) -> Self
Create a new binary asset (raw files, images, etc.)
Sourcepub fn text(path: impl Into<String>, content: impl Into<String>) -> Self
pub fn text(path: impl Into<String>, content: impl Into<String>) -> Self
Create a new text asset (JSON, scripts, etc.)
Sourcepub fn with_guid(self, guid: UnityGuid) -> Self
pub fn with_guid(self, guid: UnityGuid) -> Self
Set a custom GUID (for reproducible builds or specific requirements)
Sourcepub fn with_random_guid(self) -> Self
pub fn with_random_guid(self) -> Self
Set a random GUID instead of path-derived one
Sourcepub fn with_importer(self, importer: ImporterType) -> Self
pub fn with_importer(self, importer: ImporterType) -> Self
Override the importer type
Sourcepub fn content_bytes(&self) -> Option<Vec<u8>>
pub fn content_bytes(&self) -> Option<Vec<u8>>
Get the asset content as bytes
Sourcepub fn binary_from_slice(path: impl Into<String>, data: &[u8]) -> Self
pub fn binary_from_slice(path: impl Into<String>, data: &[u8]) -> Self
Create a binary asset from a byte slice (convenience for &u8)
Sourcepub fn from_file(
unity_path: impl Into<String>,
file_path: impl AsRef<Path>,
) -> Result<Self>
pub fn from_file( unity_path: impl Into<String>, file_path: impl AsRef<Path>, ) -> Result<Self>
Create an asset by reading a file from disk
The Unity path is the destination path in the Unity project. The file path is the source file on disk to read.
Automatically detects whether content is text or binary based on extension.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Asset
impl RefUnwindSafe for Asset
impl Send for Asset
impl Sync for Asset
impl Unpin for Asset
impl UnwindSafe for Asset
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