TriLib  1.9.0
TriLib Unity Package
TriLib.AssetLoaderZip Class Reference

Represents an Asset Loader which handles ZIP files (extracting them locally) and has synchronous and asynchronous methods. If you wish to simply load files from ZIP files without extracting them, use AssetLoader or AssetLoaderAsync instead. More...

Inheritance diagram for TriLib.AssetLoaderZip:
TriLib.AssetLoaderBase

Public Member Functions

GameObject LoadFromFile (string filename, AssetLoaderOptions options=null, GameObject wrapperGameObject=null, AssimpInterop.ProgressCallback progressCallback=null)
 Loads a UnityEngine.GameObject from input filename with defined options. More...
 
Thread LoadFromFileAsync (string filename, AssetLoaderOptions options=null, GameObject wrapperGameObject=null, ObjectLoadedHandle onAssetLoaded=null, AssimpInterop.ProgressCallback progressCallback=null)
 Asynchronously loads a UnityEngine.GameObject from input filename with defined options. More...
 
- Public Member Functions inherited from TriLib.AssetLoaderBase
void TriggerOnAvatarCreated (Avatar avatar, Animator animator)
 
void Dispose ()
 

Additional Inherited Members

- Static Public Member Functions inherited from TriLib.AssetLoaderBase
static bool IsExtensionSupported (string extension)
 Checks whether the given file extension is supported. More...
 
static string GetSupportedFileExtensions ()
 Returns a string of supported file extensions. More...
 
- Public Attributes inherited from TriLib.AssetLoaderBase
NodeData RootNodeData
 Main scene TriLib.NodeData. More...
 
MaterialData [] MaterialData
 Processed TriLib.MaterialData list. More...
 
MeshData [] MeshData
 Processed TriLib.MeshData list. More...
 
AnimationData [] AnimationData
 Processed TriLib.AnimationData list. More...
 
CameraData [] CameraData
 Processed TriLib.CameraData list. More...
 
AssimpMetadata [] Metadata
 Processed TriLib.AssimpMetadata list. More...
 
Dictionary< string, string > NodesPath
 Processed nodes path dictionary. More...
 
Dictionary< string, Material > LoadedMaterials
 Loaded UnityEngine.Material for a given name dictionary. More...
 
Dictionary< string, Texture2D > LoadedTextures
 Loaded UnityEngine.Texture2D for a given name dictionary. More...
 
Dictionary< SkinnedMeshRenderer, IList< string > > LoadedBoneNames
 Loaded bone names for a given UnityEngine.SkinnedMeshRenderer dictionary. More...
 
Dictionary< string, MeshDataMeshDataConnections
 UnityEngine.GameObject and MeshData relationship dictionary used to apply blend-shape animations. More...
 
Dictionary< string, EmbeddedTextureData > EmbeddedTextures
 Loaded EmbeddedTextureData for a given name dictionary. More...
 
uint NodeId
 Used to temporarily store nodes id. More...
 
bool HasBoneInfo
 Used to temporarily indicate if there are any bones assigned to loaded meshes. More...
 
bool HasBlendShapes
 Used to temporarily indicate if there are any blend shapes assigned to loaded meshes. More...
 
- Static Public Attributes inherited from TriLib.AssetLoaderBase
static ConcurrentList< FileLoadData > FilesLoadData = new ConcurrentList<FileLoadData>()
 Stores a FileLoadData reference list for callbacks. More...
 
static Material StandardBaseMaterial
 Base Diffuse UnityEngine.Material used to load materials. More...
 
static Material StandardSpecularMaterial
 Base Specular UnityEngine.Material used to load materials. More...
 
static Material StandardBaseAlphaMaterial
 Base Diffuse Alpha UnityEngine.Material used to load materials. More...
 
static Material StandardSpecularAlphaMaterial
 Base Specular Alpha UnityEngine.Material used to load materials. More...
 
static Material StandardBaseCutoutMaterial
 Base Diffuse Cutout UnityEngine.Material used to load materials. More...
 
static Material StandardBaseFadeMaterial
 Base Diffuse Fade UnityEngine.Material used to load materials. More...
 
static Material StandardSpecularCutoutMaterial
 Base Specular Cutout UnityEngine.Material used to load materials. More...
 
static Material StandardSpecularFadeMaterial
 Base Specular Fade UnityEngine.Material used to load materials. More...
 
static Material StandardRoughnessMaterial
 Base Roughness UnityEngine.Material used to load materials. More...
 
static Material StandardRoughnessCutoutMaterial
 Base Roughness Cutout UnityEngine.Material used to load materials. More...
 
static Material StandardRoughnessFadeMaterial
 Base Roughness Fade UnityEngine.Material used to load materials. More...
 
static Material StandardRoughnessAlphaMaterial
 Base Roughness Alpha UnityEngine.Material used to load materials. More...
 
static Texture2D NotFoundTexture
 UnityEngine.Texture used to show when no texture is found. More...
 
- Protected Member Functions inherited from TriLib.AssetLoaderBase
void TriggerOnMeshCreated (uint meshIndex, Mesh mesh)
 Triggers the on mesh created event. More...
 
void TriggerOnMaterialCreated (uint materialIndex, bool isOverriden, Material material)
 Triggers the on material created event. More...
 
void TriggerOnTextureLoaded (string sourcePath, Material material, string propertyName, Texture2D texture)
 Triggers the on texture loaded event. More...
 
void TriggerOnAnimationClipCreated (uint animationClipIndex, AnimationClip animationClip)
 Triggers the on animation clip created event. More...
 
void TriggerOnObjectLoaded (GameObject loadedGameObject)
 Triggers the on object loaded event. More...
 
void TriggerOnMetadataProcessed (AssimpMetadataType metadataType, uint metadataIndex, string metadataKey, object metadataValue)
 Triggers the on metadata processed event. More...
 
void TriggerOnBlendShapeKeyCreated (Mesh mesh, string name, Vector3[] vertices, Vector3[] normals, Vector4[] tangents, Vector4[] biTangents)
 Triggers the on blend-shape key created event. More...
 
void InternalLoadFromMemory (byte[] fileBytes, string filename, string basePath, AssetLoaderOptions options=null, bool usesWrapperGameObject=false, AssimpInterop.DataCallback dataCallback=null, AssimpInterop.ExistsCallback existsCallback=null, LoadTextureDataCallback loadTextureDataCallback=null, AssimpInterop.ProgressCallback progressCallback=null, FileLoadData customFileLoadData=null)
 Internally loads a file from memory into its data representation. More...
 
void InternalLoadFromMemoryAndZip (byte[] data, string assetExtension, string basePath, AssetLoaderOptions options=null, bool usesWrapperGameObject=false, AssimpInterop.DataCallback dataCallback=null, AssimpInterop.ExistsCallback existsCallback=null, LoadTextureDataCallback loadTextureDataCallback=null, AssimpInterop.ProgressCallback progressCallback=null, string filename=null)
 Internally loads a model from memory with custom embedded texture loading for ZIP files. More...
 
void InternalLoadFromFile (string filename, string basePath, AssetLoaderOptions options=null, bool usesWrapperGameObject=false, AssimpInterop.ProgressCallback progressCallback=null)
 Internally loads a file from file system into it's data representation. More...
 
GameObject BuildGameObject (AssetLoaderOptions options, string basePath=null, GameObject wrapperGameObject=null)
 Builds the UnityEngine.GameObject from pre-loaded data. More...
 
virtual void SetupSkinnedMeshRendererTransforms (GameObject gameObject)
 Setups the UnityEngine.SkinnedMeshRenderer bone transforms. More...
 
virtual void ProcessMetadata (AssimpMetadata metadata)
 Processes the given metadata by triggering the OnMetadataProcessed event. More...
 
virtual void SetupAnimations (GameObject gameObject, AssetLoaderOptions options)
 Setups animation components and UnityEngine.AnimationClip clips into the given UnityEngine.GameObject. More...
 
virtual GameObject TransformNodeData (NodeData nodeData, AssetLoaderOptions options, GameObject existingGameObject=null)
 Transforms given TriLib.NodeData into a UnityEngine.GameObject. More...
 
virtual void CreateMeshComponents (GameObject gameObject, AssetLoaderOptions options, Mesh mesh, bool hasBoneInfo, Material[] combinedMaterials, IList< string > boneNames=null, Material singleMaterial=null, MeshData meshData=null, string connectionKey=null)
 Creates mesh rendering components into given UnityEngine.GameObject. More...
 
virtual void TransformCameraData (GameObject gameObject, CameraData cameraData, AssetLoaderOptions options)
 Transforms the given TriLib.CameraData into a UnityEngine.Camera. More...
 
virtual void TransformAnimationData (AnimationData animationData, AssetLoaderOptions options, GameObject gameObject, bool useWrapperGameObject=false)
 Transforms the given TriLib.AnimationData into a UnityEngine.AnimationClip. More...
 
virtual void TransformMeshData (MeshData meshData, AssetLoaderOptions options)
 Transforms the given TriLib.MeshData into a UnityEngine.Mesh. More...
 
virtual bool IsUsingHDRP ()
 Checks if project is using HDRP render pipeline. More...
 
virtual string RemapMaterialProperty (string property)
 Override this method to rename Material Property names when using different Rendering Pipelines or working with custom Materials. More...
 
virtual void TransformMaterialData (MaterialData materialData, AssetLoaderOptions options, string basePath=null)
 Transforms the given TriLib.MaterialData into a UnityEngine.Material. More...
 
virtual Material LoadMaterial (string name, AssetLoaderOptions options, bool hasAlpha, bool hasSpecular)
 Creates a new UnityEngine.Material or loads an existing UnityEngine.Material with the given name. More...
 
virtual Texture2D LoadTextureFromFile (string path, string name, AssetLoaderOptions options, EmbeddedTextureData embeddedTextureData, TextureWrapMode textureWrapMode, ref bool hasAlphaChannel, bool isNormalMap, bool checkAlphaChannel=false)
 Creates a new UnityEngine.Texture2D or loads an existing UnityEngine.Texture2D with the given path. More...
 
virtual void BuildMaterials (string basePath, AssetLoaderOptions options, LoadTextureDataCallback loadTextureDataCallback=null)
 Builds the TriLib.MaterialData list for given scene. More...
 
EmbeddedTextureData LoadTextureData (string path, string basePath)
 Tries to load texture data from the given path, searching from basePath. More...
 
EmbeddedTextureData LoadEmbeddedTextureData (IntPtr texture, string textureName)
 Loads an embedded texture data. More...
 
virtual string FixNodeName (string name, uint nodeId)
 Generates a unique node name, if the given name is empty. More...
 
virtual string FixName (string name, uint id)
 Generates a unique name, if the given name is empty. More...
 
virtual string FixName (string name)
 Generates a unique name using GUIDs, if the given name is empty. More...
 
void ReleaseImport ()
 Releases allocated resources. More...
 
- Protected Attributes inherited from TriLib.AssetLoaderBase
const string AssimpFilenameMagicString = "$$$___magic___$$$"
 Assimp uses this prefix when loading files from memory. More...
 
IntPtr Scene
 Pointer to Assimp loaded scene. More...
 
- Properties inherited from TriLib.AssetLoaderBase
bool HasOnMeshCreated [get]
 Gets a value indicating whether this instance has on mesh created event. More...
 
bool HasOnMaterialCreated [get]
 Gets a value indicating whether this instance has on material created event. More...
 
bool HasOnTextureLoaded [get]
 Gets a value indicating whether this instance has on texture loaded event. More...
 
bool HasOnAvatarCreated [get]
 
bool HasOnAnimationClipCreated [get]
 Gets a value indicating whether this instance has on animation clip created event. More...
 
bool HasOnObjectLoaded [get]
 Gets a value indicating whether this instance has on object loaded event. More...
 
bool HasOnMetadataProcessed [get]
 Gets a value indicating whether this instance has on metadata processed event. More...
 
bool HasOnBlendShapeKeyCreated [get]
 Gets a value indicating whether this instance has on blend-shape key created event. More...
 
- Events inherited from TriLib.AssetLoaderBase
EmbeddedTextureLoadCallback EmbeddedTextureLoad
 Use this field to assign the callback that will be triggered when a texture looks up for embedded data. More...
 
MeshCreatedHandle OnMeshCreated
 Use this field to assign the event that occurs when a mesh is loaded. More...
 
MaterialCreatedHandle OnMaterialCreated
 Use this field to assign the event that occurs when a material is created. More...
 
TextureLoadHandle OnTextureLoaded
 Use this field to assign the event that occurs when a texture is loaded. More...
 
AvatarCreatedHandle OnAvatarCreated
 
AnimationClipCreatedHandle OnAnimationClipCreated
 Use this field to assign the event that occurs when an animation is created. More...
 
ObjectLoadedHandle OnObjectLoaded
 Use this field to assign the event that occurs when the asset is loaded. More...
 
MetadataProcessedHandle OnMetadataProcessed
 Use this field to assign the event that will occurs when each file metadata is processed. More...
 
BlendShapeKeyCreatedHandle OnBlendShapeKeyCreated
 Use this field to assign the event that occurs when a blend-shape key is created. More...
 

Detailed Description

Represents an Asset Loader which handles ZIP files (extracting them locally) and has synchronous and asynchronous methods. If you wish to simply load files from ZIP files without extracting them, use AssetLoader or AssetLoaderAsync instead.

Member Function Documentation

◆ LoadFromFile()

GameObject TriLib.AssetLoaderZip.LoadFromFile ( string  filename,
AssetLoaderOptions  options = null,
GameObject  wrapperGameObject = null,
AssimpInterop.ProgressCallback  progressCallback = null 
)

Loads a UnityEngine.GameObject from input filename with defined options.

Warning
To ensure your materials will be loaded, don´t remove the material files included in the package.
Parameters
filenameFilename used to load the UnityEngine.GameObject.
optionsAssetLoaderOptions used to load the object.
wrapperGameObjectUse this field to load the new UnityEngine.GameObject into referenced UnityEngine.GameObject.
progressCallbackCallback used to retrieve file loading percentage.
Returns
A new UnityEngine.GameObject.
protected void Awake() {
GameObject myGameObject;
try {
using (var assetLoader = new AssetLoader()) {
gameObject = assetLoader.LoadFromFile("mymodel.fbx");
}
} catch (Exception e) {
Debug.LogFormat("Unable to load mymodel.fbx. The loader returned: {0}", e);
}
}

◆ LoadFromFileAsync()

Thread TriLib.AssetLoaderZip.LoadFromFileAsync ( string  filename,
AssetLoaderOptions  options = null,
GameObject  wrapperGameObject = null,
ObjectLoadedHandle  onAssetLoaded = null,
AssimpInterop.ProgressCallback  progressCallback = null 
)

Asynchronously loads a UnityEngine.GameObject from input filename with defined options.

Warning
To ensure your materials will be loaded, don´t remove the material files included in the package.
Parameters
filenameFilename used to load the UnityEngine.GameObject.
optionsAssetLoaderOptions used to load the object.
wrapperGameObjectUse this field to load the new UnityEngine.GameObject into referenced UnityEngine.GameObject.
onAssetLoadedThe action that will be executed when the UnityEngine.GameObject be loaded.
progressCallbackCallback used to retrieve file loading percentage.
Returns
The created Thread on NET 2.0, otherwise returns the created Task.
protected void Awake() {
GameObject myGameObject;
try {
using (var assetLoader = new AssetLoader()) {
assetLoader.LoadFromFile("mymodel.fbx", null, null, delegate(GameObject loadedGameObject) {
Debug.Log("My object '" + loadedGameObject.name + "' has been loaded!");
});
}
} catch (Exception e) {
Debug.LogFormat("Unable to load mymodel.fbx. The loader returned: {0}", e);
}
}

The documentation for this class was generated from the following file: