| | 1 | | using System.Collections.Generic; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL.Emotes |
| | 5 | | { |
| | 6 | | public class EmoteAnimationsPlugin : IPlugin |
| | 7 | | { |
| | 8 | | private readonly DataStore_Emotes dataStore; |
| | 9 | |
|
| 0 | 10 | | public EmoteAnimationsPlugin(DataStore_Emotes dataStore) |
| | 11 | | { |
| 0 | 12 | | this.dataStore = dataStore; |
| 0 | 13 | | this.dataStore.animations.Clear(); |
| 0 | 14 | | this.dataStore.emotesOnUse.OnRefCountUpdated += OnRefCountUpdated; |
| | 15 | |
|
| 0 | 16 | | InitializeEmbeddedEmotes(); |
| 0 | 17 | | InitializeEmotes(this.dataStore.emotesOnUse.GetAllRefCounts()); |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | private void InitializeEmbeddedEmotes() |
| | 21 | | { |
| | 22 | | //To avoid circular references in assemblies we hardcode this here instead of using WearableLiterals |
| | 23 | | //Embedded Emotes are only temporary until they can be retrieved from the content server |
| | 24 | | const string FEMALE = "urn:decentraland:off-chain:base-avatars:BaseFemale"; |
| | 25 | | const string MALE = "urn:decentraland:off-chain:base-avatars:BaseMale"; |
| | 26 | |
|
| 0 | 27 | | var embeddedEmotes = Resources.Load<EmbeddedEmotesSO>("EmbeddedEmotes"); |
| | 28 | |
|
| 0 | 29 | | foreach (EmbeddedEmote embeddedEmote in embeddedEmotes.emotes) |
| | 30 | | { |
| 0 | 31 | | if (embeddedEmote.maleAnimation != null) |
| | 32 | | { |
| | 33 | | //We match the animation id with its name due to performance reasons |
| | 34 | | //Unity's Animation uses the name to play the clips. |
| 0 | 35 | | embeddedEmote.maleAnimation.name = embeddedEmote.id; |
| 0 | 36 | | dataStore.animations.Add((MALE, embeddedEmote.id), embeddedEmote.maleAnimation); |
| | 37 | | } |
| | 38 | |
|
| 0 | 39 | | if (embeddedEmote.femaleAnimation != null) |
| | 40 | | { |
| | 41 | | //We match the animation id with its name due to performance reasons |
| | 42 | | //Unity's Animation uses the name to play the clips. |
| 0 | 43 | | embeddedEmote.femaleAnimation.name = embeddedEmote.id; |
| 0 | 44 | | dataStore.animations.Add((FEMALE, embeddedEmote.id), embeddedEmote.femaleAnimation); |
| | 45 | | } |
| | 46 | | } |
| 0 | 47 | | CatalogController.i.EmbedWearables(embeddedEmotes.emotes); |
| 0 | 48 | | } |
| | 49 | |
|
| | 50 | | private void OnRefCountUpdated(string emoteId, int refCount) |
| | 51 | | { |
| 0 | 52 | | if (refCount > 0) |
| 0 | 53 | | LoadEmote(emoteId); |
| | 54 | | else |
| 0 | 55 | | UnloadEmote(emoteId); |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | private void InitializeEmotes(IEnumerable<KeyValuePair<string, int>> refCounts) |
| | 59 | | { |
| 0 | 60 | | foreach (KeyValuePair<string, int> keyValuePair in refCounts) |
| | 61 | | { |
| 0 | 62 | | LoadEmote(keyValuePair.Key); |
| | 63 | | } |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | private void LoadEmote(string id) |
| | 67 | | { |
| | 68 | | //TODO when working with emotes in the content server |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | private void UnloadEmote(string id) |
| | 72 | | { |
| | 73 | | //TODO when working with emotes in the content server |
| 0 | 74 | | } |
| | 75 | |
|
| 0 | 76 | | public void Dispose() { this.dataStore.emotesOnUse.OnRefCountUpdated -= OnRefCountUpdated; } |
| | 77 | | } |
| | 78 | |
|
| | 79 | | } |