123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using TriLibCore.General;
- using UnityEngine;
- using TriLibCore.Extensions;
- using UnityEngine.UI;
- namespace TriLibCore.Samples
- {
-
-
-
- public class LoadModelFromFilePickerSample : MonoBehaviour
- {
-
-
-
- private GameObject _loadedGameObject;
-
-
-
- [SerializeField]
- private Button _loadModelButton;
-
-
-
-
-
-
- public void LoadModel()
- {
- var assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
- var assetLoaderFilePicker = AssetLoaderFilePicker.Create();
- assetLoaderFilePicker.LoadModelFromFilePickerAsync("Select a Model file", OnLoad, OnMaterialsLoad, OnProgress, OnBeginLoad, OnError, null, assetLoaderOptions);
- }
-
-
-
-
- private void OnBeginLoad(bool filesSelected)
- {
- _loadModelButton.interactable = false;
- }
-
-
-
-
- private void OnError(IContextualizedError obj)
- {
- Debug.LogError($"An error ocurred while loading your Model: {obj.GetInnerException()}");
- }
-
-
-
-
-
- private void OnProgress(AssetLoaderContext assetLoaderContext, float progress)
- {
- Debug.Log($"Loading Model. Progress: {progress:P}");
- }
-
-
-
-
-
- private void OnMaterialsLoad(AssetLoaderContext assetLoaderContext)
- {
- if (assetLoaderContext.RootGameObject != null)
- {
- Debug.Log("Materials loaded. Model fully loaded.");
- }
- else
- {
- Debug.Log("Model could not be loaded.");
- }
- }
-
-
-
-
-
- private void OnLoad(AssetLoaderContext assetLoaderContext)
- {
- if (_loadedGameObject != null)
- {
- Destroy(_loadedGameObject);
- }
- _loadedGameObject = assetLoaderContext.RootGameObject;
- if (_loadedGameObject != null)
- {
- Camera.main.FitToBounds(assetLoaderContext.RootGameObject, 2f);
- Debug.Log("Model loaded. Loading materials.");
- }
- else
- {
- Debug.Log("Model materials could not be loaded.");
- }
- _loadModelButton.interactable = true;
- }
- }
- }
|