| | 1 | | using System; |
| | 2 | | using System.Threading; |
| | 3 | | using AvatarSystem; |
| | 4 | | using Cysharp.Threading.Tasks; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Emotes |
| | 8 | | { |
| | 9 | | public class EmoteAnimationLoader : IEmoteAnimationLoader |
| | 10 | | { |
| | 11 | | private readonly IWearableRetriever retriever; |
| 0 | 12 | | public AnimationClip loadedAnimationClip { get; internal set; } |
| | 13 | |
|
| 0 | 14 | | public EmoteAnimationLoader(IWearableRetriever retriever) { this.retriever = retriever; } |
| | 15 | |
|
| | 16 | | public async UniTask LoadEmote(GameObject container, WearableItem emote, string bodyShapeId, CancellationToken c |
| | 17 | | { |
| 7 | 18 | | if (container == null) |
| 1 | 19 | | throw new NullReferenceException("Container cannot be null"); |
| | 20 | |
|
| 6 | 21 | | if (emote == null) |
| 1 | 22 | | throw new NullReferenceException("Emote cannot be null"); |
| | 23 | |
|
| 5 | 24 | | if (string.IsNullOrEmpty(bodyShapeId)) |
| 2 | 25 | | throw new NullReferenceException("bodyShapeId cannot be null or empty"); |
| | 26 | |
|
| 3 | 27 | | ct.ThrowIfCancellationRequested(); |
| | 28 | |
|
| 2 | 29 | | WearableItem.Representation representation = emote.GetRepresentation(bodyShapeId); |
| 2 | 30 | | if (representation == null) |
| | 31 | | { |
| 1 | 32 | | throw new Exception($"No representation for {bodyShapeId} of emote: {emote.id}"); |
| | 33 | | } |
| | 34 | |
|
| 1 | 35 | | Rendereable rendereable = await retriever.Retrieve(container, emote.GetContentProvider(bodyShapeId), emote.b |
| | 36 | |
|
| 1 | 37 | | var animation = rendereable.container.GetComponentInChildren<Animation>(); |
| 1 | 38 | | if (animation == null) |
| | 39 | | { |
| 0 | 40 | | Debug.LogError("Animation component not found in the container for emote " + emote.id); |
| 0 | 41 | | return; |
| | 42 | | } |
| | 43 | |
|
| 1 | 44 | | var animationClip = animation.clip; |
| 1 | 45 | | if(animationClip == null) |
| | 46 | | { |
| 0 | 47 | | Debug.LogError("AnimationClip not found in the container for emote " + emote.id); |
| 0 | 48 | | return; |
| | 49 | | } |
| | 50 | |
|
| | 51 | | //Setting animation name equal to emote id to avoid unity animation clip duplication on Animation.AddClip() |
| 1 | 52 | | this.loadedAnimationClip = animationClip; |
| 1 | 53 | | animationClip.name = emote.id; |
| 1 | 54 | | } |
| | 55 | |
|
| 0 | 56 | | public void Dispose() { retriever?.Dispose(); } |
| | 57 | | } |
| | 58 | | } |