| | 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 animation { 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 | | animation = rendereable.container.GetComponentInChildren<Animation>()?.clip; |
| | 38 | |
|
| | 39 | | //Setting animation name equal to emote id to avoid unity animation clip duplication on Animation.AddClip() |
| 1 | 40 | | animation.name = emote.id; |
| 1 | 41 | | } |
| | 42 | |
|
| 0 | 43 | | public void Dispose() { retriever?.Dispose(); } |
| | 44 | | } |
| | 45 | | } |