1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using TriLibCore.General;
- using UnityEngine;
- namespace TriLibCore.Samples
- {
- /// <summary>
- /// Represents a sample that loads a compressed (Zipped) Model.
- /// </summary>
- public class LoadModelFromURLSample : MonoBehaviour
- {
- /// <summary>
- /// Creates the AssetLoaderOptions instance, configures the Web Request, and downloads the Model.
- /// </summary>
- /// <remarks>
- /// You can create the AssetLoaderOptions by right clicking on the Assets Explorer and selecting "TriLib->Create->AssetLoaderOptions->Pre-Built AssetLoaderOptions".
- /// </remarks>
- private void Start()
- {
- var assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
- var webRequest = AssetDownloader.CreateWebRequest("https://ricardoreis.net/trilib/demos/sample/TriLibSampleModel.zip");
- AssetDownloader.LoadModelFromUri(webRequest, OnLoad, OnMaterialsLoad, OnProgress, OnError, null, assetLoaderOptions);
- }
- /// <summary>
- /// Called when any error occurs.
- /// </summary>
- /// <param name="obj">The contextualized error, containing the original exception and the context passed to the method where the error was thrown.</param>
- private void OnError(IContextualizedError obj)
- {
- Debug.LogError($"An error ocurred while loading your Model: {obj.GetInnerException()}");
- }
- /// <summary>
- /// Called when the Model loading progress changes.
- /// </summary>
- /// <param name="assetLoaderContext">The context used to load the Model.</param>
- /// <param name="progress">The loading progress.</param>
- private void OnProgress(AssetLoaderContext assetLoaderContext, float progress)
- {
- Debug.Log($"Loading Model. Progress: {progress:P}");
- }
- /// <summary>
- /// Called when the Model (including Textures and Materials) has been fully loaded, or after any error occurs.
- /// </summary>
- /// <remarks>The loaded GameObject is available on the assetLoaderContext.RootGameObject field.</remarks>
- /// <param name="assetLoaderContext">The context used to load the Model.</param>
- private void OnMaterialsLoad(AssetLoaderContext assetLoaderContext)
- {
- Debug.Log("Materials loaded. Model fully loaded.");
- }
- /// <summary>
- /// Called when the Model Meshes and hierarchy are loaded.
- /// </summary>
- /// <remarks>The loaded GameObject is available on the assetLoaderContext.RootGameObject field.</remarks>
- /// <param name="assetLoaderContext">The context used to load the Model.</param>
- private void OnLoad(AssetLoaderContext assetLoaderContext)
- {
- Debug.Log("Model loaded. Loading materials.");
- }
- }
- }
|