1#pragma warning disable 649
2using System.Collections.Generic;
33 [SerializeField]
private Button _loadAnimationButton;
38 [SerializeField]
private Button _animationPlayTemplate;
43 private GameObject _loadedGameObject;
48 private readonly List<AnimationClip> _loadedAnimationClips =
new List<AnimationClip>();
67 var assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
68 assetLoaderOptions.AddAssetUnloader =
false;
69 assetLoaderOptions.ImportMaterials =
false;
70 assetLoaderOptions.ImportTextures =
false;
71 assetLoaderOptions.ImportMeshes =
false;
72 assetLoaderOptions.SampleBindPose =
true;
73 assetLoaderOptions.AnimationType = AnimationType.Humanoid;
74 assetLoaderOptions.HumanoidAvatarMapper =
75 Resources.Load<HumanoidAvatarMapper>(
"Mappers/Avatar/MixamoAndBipedByNameHumanoidAvatarMapper");
77 var legacyToHumanoidAnimationClipMapper =
80 legacyToHumanoidAnimationClipMapper.name =
"LegacyToHumanoidAnimationClipMapper";
81 assetLoaderOptions.FixedAllocations.Add(legacyToHumanoidAnimationClipMapper);
83 var simpleAnimationPlayerAnimationClipMapper =
85 simpleAnimationPlayerAnimationClipMapper.name =
"SimpleAnimationPlayerAnimationClipMapper";
86 assetLoaderOptions.FixedAllocations.Add(simpleAnimationPlayerAnimationClipMapper);
88 assetLoaderOptions.AnimationClipMappers =
new AnimationClipMapper[]
90 legacyToHumanoidAnimationClipMapper,
91 simpleAnimationPlayerAnimationClipMapper
96 OnProgress, OnBeginLoad, OnError,
null, assetLoaderOptions);
103 private void OnBeginLoad(
bool filesSelected)
105 _loadAnimationButton.interactable = !filesSelected;
115 private void OnError(IContextualizedError obj)
117 Debug.LogError($
"An error ocurred while loading your Model: {obj.GetInnerException()}");
125 private void OnProgress(AssetLoaderContext assetLoaderContext,
float progress)
127 Debug.Log($
"Loading Model. Progress: {progress:P}");
139 private void OnMaterialsLoad(AssetLoaderContext assetLoaderContext)
141 if (assetLoaderContext.RootGameObject !=
null)
143 Debug.Log(
"Materials loaded. Model fully loaded.");
145 if (simpleAnimationPlayer !=
null)
146 foreach (var animationClip
in simpleAnimationPlayer.AnimationClips)
149 if (animationClip ==
null)
continue;
150 var animationIndex = _loadedAnimationClips.Count;
151 var button = Instantiate(_animationPlayTemplate, _animationPlayTemplate.transform.parent);
152 button.GetComponentInChildren<Text>().text = animationClip.name;
153 button.onClick.AddListener(delegate
157 button.gameObject.SetActive(
true);
158 _loadedAnimationClips.Add(animationClip);
161 Destroy(assetLoaderContext
166 Debug.Log(
"Model could not be loaded.");
175 private void OnLoad(AssetLoaderContext assetLoaderContext)
177 _loadAnimationButton.interactable =
true;
UnityEngine.UI.Button Button
Represents an Asset Loader which loads files using a platform-specific file picker.
static AssetLoaderFilePicker Create()
Creates the Asset Loader File Picker Singleton instance.
void LoadModelFromFilePickerAsync(string title, Action< AssetLoaderContext > onLoad, Action< AssetLoaderContext > onMaterialsLoad, Action< AssetLoaderContext, float > onProgress, Action< bool > onBeginLoad, Action< IContextualizedError > onError, GameObject wrapperGameObject, AssetLoaderOptions assetLoaderOptions)
Loads a Model from the OS file picker asynchronously, or synchronously when the OS doesn't support Th...
Represents a Mapper that converts legacy Animation Clips into humanoid Animation Clips.
AnimationClip MecanimAnimationClipTemplate
Template mecanim animation clip. Unity runtime API can't access mecanim animation clip settings as ro...
Represents a Mapper that creates a Simple Animation Player used to play Animation Clips by their inde...
Represents a Playable used to play Animations from its Animation Clip List using names or indices as ...
IList< AnimationClip > AnimationClips
Source animation clips.
void PlayAnimation(int index)
Plays the Animation Clip with the given index.
Represents a sample that allows user loading Humanoid Animations with a File Picker.
AnimationClip MecanimAnimationClipTemplate
Template mecanim animation clip. Unity runtime API can't access mecanim animation clip settings as ro...
void LoadAnimation()
Creates the AssetLoaderOptions instance and displays the Model file-picker. First we will point the S...
SimpleAnimationPlayer OriginalModelSimpleAnimationPlayer
Simple Animation Player component located on the existing Model in the Scene. The Simple Animation Pl...