| | 1 | | using DCL; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | | using Categories = WearableLiterals.Categories; |
| | 7 | | using Rarity = WearableLiterals.ItemRarity; |
| | 8 | |
|
| | 9 | | public class AvatarEditorHUDAudioHandler : MonoBehaviour |
| | 10 | | { |
| | 11 | | [SerializeField] |
| | 12 | | AvatarEditorHUDView view; |
| | 13 | |
|
| | 14 | | [SerializeField] |
| | 15 | | ItemSelector nftItemSelector; |
| | 16 | |
|
| | 17 | | [SerializeField] |
| | 18 | | Button randomizeButton; |
| | 19 | |
|
| | 20 | | [SerializeField] |
| | 21 | | AudioEvent eventMusic, eventRarity, eventAvatarAppear, eventReactionMale, eventReactionFemale, eventWearableClothing |
| | 22 | | eventWearableFootwear, eventWearableHair, eventWearableHatMask, eventWearableRarity; |
| | 23 | |
|
| | 24 | | WearableItem lastSelectedWearable = null; |
| | 25 | | bool hasClickedRandomize = false, wearableIsSameAsPrevious = false; |
| | 26 | |
|
| | 27 | | IEnumerator musicFadeOut; |
| | 28 | |
|
| | 29 | | private void Start() |
| | 30 | | { |
| 1 | 31 | | int nPairs = view.wearableGridPairs.Length; |
| 36 | 32 | | for (int i = 0; i < nPairs; i++) |
| | 33 | | { |
| 17 | 34 | | view.wearableGridPairs[i].selector.OnItemClicked += OnSelectWearable; |
| | 35 | | } |
| | 36 | |
|
| 1 | 37 | | nftItemSelector.OnItemClicked += OnSelectWearable; |
| | 38 | |
|
| 1 | 39 | | view.OnSetVisibility += OnSetAvatarEditorVisibility; |
| 1 | 40 | | view.OnRandomize += OnClickRandomize; |
| 1 | 41 | | } |
| | 42 | |
|
| | 43 | | void OnSelectWearable(string wearableId) |
| | 44 | | { |
| 0 | 45 | | CatalogController.wearableCatalog.TryGetValue(wearableId, out var wearable); |
| 0 | 46 | | wearableIsSameAsPrevious = (wearable == lastSelectedWearable); |
| 0 | 47 | | if (wearableIsSameAsPrevious) |
| 0 | 48 | | return; |
| | 49 | |
|
| 0 | 50 | | lastSelectedWearable = wearable; |
| 0 | 51 | | if (wearable == null) |
| 0 | 52 | | return; |
| | 53 | |
|
| 0 | 54 | | switch (wearable.data.category) |
| | 55 | | { |
| | 56 | | case Categories.EYEBROWS: |
| 0 | 57 | | eventWearableHair.Play(true); |
| 0 | 58 | | break; |
| | 59 | | case "facial_hair": |
| 0 | 60 | | eventWearableHair.Play(true); |
| 0 | 61 | | break; |
| | 62 | | case Categories.FEET: |
| 0 | 63 | | eventWearableFootwear.Play(true); |
| 0 | 64 | | break; |
| | 65 | | case Categories.HAIR: |
| 0 | 66 | | eventWearableHair.Play(true); |
| 0 | 67 | | break; |
| | 68 | | case Categories.LOWER_BODY: |
| 0 | 69 | | eventWearableClothing.Play(true); |
| 0 | 70 | | break; |
| | 71 | | case Categories.UPPER_BODY: |
| 0 | 72 | | eventWearableClothing.Play(true); |
| 0 | 73 | | break; |
| | 74 | | case "eyewear": |
| 0 | 75 | | eventWearableEyewear.Play(true); |
| 0 | 76 | | break; |
| | 77 | | case "tiara": |
| 0 | 78 | | eventWearableJewelry.Play(true); |
| 0 | 79 | | break; |
| | 80 | | case "earring": |
| 0 | 81 | | eventWearableJewelry.Play(true); |
| 0 | 82 | | break; |
| | 83 | | case "hat": |
| 0 | 84 | | eventWearableHatMask.Play(true); |
| 0 | 85 | | break; |
| | 86 | | case "top_head": |
| 0 | 87 | | eventWearableFootwear.Play(true); |
| 0 | 88 | | break; |
| | 89 | | case "helmet": |
| 0 | 90 | | eventWearableFootwear.Play(true); |
| 0 | 91 | | break; |
| | 92 | | case "mask": |
| 0 | 93 | | eventWearableHatMask.Play(true); |
| | 94 | | break; |
| | 95 | | default: |
| | 96 | | break; |
| | 97 | | } |
| 0 | 98 | | } |
| | 99 | |
|
| 0 | 100 | | void OnEyeColorChanged(Color color) { ResetLastClickedWearable(); } |
| | 101 | |
|
| 0 | 102 | | void OnSkinColorChanged(Color color) { ResetLastClickedWearable(); } |
| | 103 | |
|
| 0 | 104 | | void OnHairColorChanged(Color color) { ResetLastClickedWearable(); } |
| | 105 | |
|
| | 106 | | void OnClickRandomize() |
| | 107 | | { |
| 0 | 108 | | hasClickedRandomize = true; |
| 0 | 109 | | ResetLastClickedWearable(); |
| 0 | 110 | | } |
| | 111 | |
|
| 0 | 112 | | void ResetLastClickedWearable() { lastSelectedWearable = null; } |
| | 113 | |
|
| | 114 | | void OnAvatarAppear(AvatarModel model) |
| | 115 | | { |
| 0 | 116 | | if (!view.isOpen) |
| 0 | 117 | | return; |
| | 118 | |
|
| 0 | 119 | | eventAvatarAppear.Play(true); |
| | 120 | |
|
| 0 | 121 | | if (!wearableIsSameAsPrevious) |
| | 122 | | { |
| 0 | 123 | | if (lastSelectedWearable != null) |
| 0 | 124 | | PlayRarity(); |
| | 125 | |
|
| 0 | 126 | | if (lastSelectedWearable != null || hasClickedRandomize) |
| 0 | 127 | | PlayVoiceReaction(model.bodyShape); |
| | 128 | | } |
| | 129 | |
|
| 0 | 130 | | hasClickedRandomize = false; |
| 0 | 131 | | } |
| | 132 | |
|
| | 133 | | void PlayRarity() |
| | 134 | | { |
| 0 | 135 | | if (lastSelectedWearable.rarity == null) |
| 0 | 136 | | return; |
| | 137 | |
|
| | 138 | | /*switch (lastClickedWearable.rarity) |
| | 139 | | { |
| | 140 | | case Rarity.RARE: |
| | 141 | | eventRarity.SetIndex(0); |
| | 142 | | break; |
| | 143 | | case Rarity.EPIC: |
| | 144 | | eventRarity.SetIndex(1); |
| | 145 | | break; |
| | 146 | | case Rarity.LEGENDARY: |
| | 147 | | eventRarity.SetIndex(2); |
| | 148 | | break; |
| | 149 | | case Rarity.MYTHIC: |
| | 150 | | eventRarity.SetIndex(3); |
| | 151 | | break; |
| | 152 | | case Rarity.UNIQUE: |
| | 153 | | eventRarity.SetIndex(4); |
| | 154 | | break; |
| | 155 | | default: |
| | 156 | | eventRarity.SetIndex(0); |
| | 157 | | break; |
| | 158 | | }*/ |
| | 159 | |
|
| 0 | 160 | | if (lastSelectedWearable.rarity == Rarity.UNIQUE) |
| 0 | 161 | | eventRarity.SetIndex(1); |
| | 162 | | else |
| 0 | 163 | | eventRarity.SetIndex(0); |
| | 164 | |
|
| 0 | 165 | | eventRarity.Play(true); |
| 0 | 166 | | } |
| | 167 | |
|
| | 168 | | void PlayVoiceReaction(string bodyShape) |
| | 169 | | { |
| 0 | 170 | | float chanceToPlay = 0.75f; |
| 0 | 171 | | AudioEvent eventReaction = null; |
| | 172 | |
|
| 0 | 173 | | if (bodyShape.Contains("Female")) |
| 0 | 174 | | eventReaction = eventReactionFemale; |
| | 175 | | else |
| 0 | 176 | | eventReaction = eventReactionMale; |
| | 177 | |
|
| 0 | 178 | | if (lastSelectedWearable != null) |
| | 179 | | { |
| 0 | 180 | | if (lastSelectedWearable.rarity == Rarity.EPIC |
| | 181 | | || lastSelectedWearable.rarity == Rarity.LEGENDARY |
| | 182 | | || lastSelectedWearable.rarity == Rarity.MYTHIC |
| | 183 | | || lastSelectedWearable.rarity == Rarity.UNIQUE) |
| | 184 | | { |
| 0 | 185 | | eventReaction.RandomizeIndex(14, 28); |
| 0 | 186 | | chanceToPlay = 1f; |
| 0 | 187 | | } |
| | 188 | | else |
| | 189 | | { |
| 0 | 190 | | eventReaction.RandomizeIndex(0, 14); |
| | 191 | | } |
| | 192 | | } |
| | 193 | |
|
| 0 | 194 | | if (eventReaction != null && Random.Range(0f, 1f) <= chanceToPlay) |
| | 195 | | { |
| 0 | 196 | | if (!eventReaction.source.isPlaying) |
| | 197 | | { |
| 0 | 198 | | eventReaction.PlayScheduled(0.6f); |
| | 199 | | } |
| | 200 | | } |
| 0 | 201 | | } |
| | 202 | |
|
| | 203 | | void OnSetAvatarEditorVisibility(bool visible) |
| | 204 | | { |
| 0 | 205 | | AudioScriptableObjects.listItemAppear.ResetPitch(); |
| | 206 | |
|
| 0 | 207 | | if (visible) |
| | 208 | | { |
| 0 | 209 | | if (DataStore.i.common.isSignUpFlow.Get()) |
| | 210 | | { |
| 0 | 211 | | if (musicFadeOut != null) |
| | 212 | | { |
| 0 | 213 | | StopCoroutine(musicFadeOut); |
| 0 | 214 | | StartCoroutine(eventMusic.FadeIn(1f)); |
| | 215 | | } |
| | 216 | |
|
| 0 | 217 | | if (!eventMusic.source.isPlaying) |
| 0 | 218 | | eventMusic.Play(); |
| | 219 | | } |
| | 220 | |
|
| 0 | 221 | | view.eyeColorSelector.OnColorChanged += OnEyeColorChanged; |
| 0 | 222 | | view.skinColorSelector.OnColorChanged += OnSkinColorChanged; |
| 0 | 223 | | view.hairColorSelector.OnColorChanged += OnHairColorChanged; |
| 0 | 224 | | view.OnAvatarAppear += OnAvatarAppear; |
| 0 | 225 | | } |
| | 226 | | else |
| | 227 | | { |
| 0 | 228 | | if (DataStore.i.common.isSignUpFlow.Get()) |
| | 229 | | { |
| 0 | 230 | | musicFadeOut = eventMusic.FadeOut(2f); |
| 0 | 231 | | StartCoroutine(musicFadeOut); |
| | 232 | | } |
| | 233 | |
|
| 0 | 234 | | view.eyeColorSelector.OnColorChanged -= OnEyeColorChanged; |
| 0 | 235 | | view.skinColorSelector.OnColorChanged -= OnSkinColorChanged; |
| 0 | 236 | | view.hairColorSelector.OnColorChanged -= OnHairColorChanged; |
| 0 | 237 | | view.OnAvatarAppear -= OnAvatarAppear; |
| | 238 | | } |
| 0 | 239 | | } |
| | 240 | | } |