| | 1 | | using DCL; |
| | 2 | | using DCLServices.WearablesCatalogService; |
| | 3 | | using System; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | public class AvatarEditorHUDAnimationController : IDisposable |
| | 7 | | { |
| | 8 | | private readonly IAvatarEditorHUDView hudView; |
| | 9 | | private readonly IWearablesCatalogService wearablesCatalogService; |
| | 10 | | internal string activeCategory; |
| | 11 | | private int currentAnimationIndexShown; |
| | 12 | |
|
| 0 | 13 | | public AvatarEditorHUDAnimationController( |
| | 14 | | IAvatarEditorHUDView avatarEditorHUDView, |
| | 15 | | IWearablesCatalogService wearablesCatalogService) |
| | 16 | | { |
| 0 | 17 | | this.hudView = avatarEditorHUDView; |
| 0 | 18 | | this.wearablesCatalogService = wearablesCatalogService; |
| | 19 | |
|
| 0 | 20 | | hudView.OnRandomize += OnClickRandomize; |
| 0 | 21 | | hudView.WearableSelectorClicked += OnSelectWearable; |
| 0 | 22 | | hudView.OnAvatarAppearFeedback += AvatarAppearFeedback; |
| 0 | 23 | | } |
| | 24 | |
|
| | 25 | | public void AvatarAppearFeedback(AvatarModel avatarModelToUpdate) |
| | 26 | | { |
| 0 | 27 | | if (!string.IsNullOrEmpty(activeCategory)) |
| | 28 | | { |
| 0 | 29 | | PlayAnimation(avatarModelToUpdate); |
| | 30 | | } |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | private void OnClickRandomize() |
| | 34 | | { |
| 0 | 35 | | activeCategory = ""; |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | private void PlayAnimation(AvatarModel avatarModelToUpdate) |
| | 39 | | { |
| 0 | 40 | | avatarModelToUpdate.expressionTriggerTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); |
| 0 | 41 | | hudView.CharacterPreview.PlayEmote(activeCategory, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public void OnSelectWearable(string wearableId) |
| | 45 | | { |
| 0 | 46 | | wearablesCatalogService.WearablesCatalog.TryGetValue(wearableId, out var wearable); |
| 0 | 47 | | switch (wearable.data.category) |
| | 48 | | { |
| | 49 | | case WearableLiterals.Categories.FEET: |
| 0 | 50 | | activeCategory = GetRandomizedName("Outfit_Shoes_v0",2); |
| 0 | 51 | | break; |
| | 52 | | case WearableLiterals.Categories.LOWER_BODY: |
| 0 | 53 | | activeCategory = GetRandomizedName("Outfit_Lower_v0",3); |
| 0 | 54 | | break; |
| | 55 | | case WearableLiterals.Categories.UPPER_BODY: |
| 0 | 56 | | activeCategory = GetRandomizedName("Outfit_Upper_v0",3); |
| 0 | 57 | | break; |
| | 58 | | case "eyewear": |
| 0 | 59 | | activeCategory = GetRandomizedName("Outfit_Accessories_v0",3); |
| 0 | 60 | | break; |
| | 61 | | case "tiara": |
| 0 | 62 | | activeCategory = GetRandomizedName("Outfit_Accessories_v0",3); |
| 0 | 63 | | break; |
| | 64 | | case "earring": |
| 0 | 65 | | activeCategory = GetRandomizedName("Outfit_Accessories_v0",3); |
| 0 | 66 | | break; |
| | 67 | | case "hat": |
| 0 | 68 | | activeCategory = GetRandomizedName("Outfit_Accessories_v0",3); |
| 0 | 69 | | break; |
| | 70 | | case "top_head": |
| 0 | 71 | | activeCategory = GetRandomizedName("Outfit_Accessories_v0",3); |
| 0 | 72 | | break; |
| | 73 | | case "helmet": |
| 0 | 74 | | activeCategory = GetRandomizedName("Outfit_Accessories_v0",3); |
| 0 | 75 | | break; |
| | 76 | | case "mask": |
| 0 | 77 | | activeCategory = GetRandomizedName("Outfit_Accessories_v0",3); |
| 0 | 78 | | break; |
| | 79 | | case "skin": |
| 0 | 80 | | activeCategory = GetRandomizedName("Outfit_Upper_v0",3); |
| 0 | 81 | | break; |
| | 82 | | default: |
| 0 | 83 | | activeCategory = ""; |
| | 84 | | break; |
| | 85 | | } |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | private string GetRandomizedName(string baseString, int limit) |
| | 89 | | { |
| 0 | 90 | | currentAnimationIndexShown = (currentAnimationIndexShown + 1) % limit; |
| 0 | 91 | | return baseString + (currentAnimationIndexShown + 1); |
| | 92 | | } |
| | 93 | |
|
| | 94 | | public void Dispose() |
| | 95 | | { |
| 0 | 96 | | hudView.OnAvatarAppearFeedback -= AvatarAppearFeedback; |
| 0 | 97 | | hudView.OnRandomize -= OnClickRandomize; |
| 0 | 98 | | hudView.WearableSelectorClicked -= OnSelectWearable; |
| 0 | 99 | | } |
| | 100 | | } |