| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using System.Collections; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Runtime.CompilerServices; |
| | 7 | | using TMPro; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.EventSystems; |
| | 10 | | using UnityEngine.UI; |
| | 11 | | using static WearableCollectionsAPIData; |
| | 12 | |
|
| | 13 | | [assembly: InternalsVisibleTo("AvatarEditorHUDTests")] |
| | 14 | |
|
| | 15 | | public class AvatarEditorHUDView : MonoBehaviour, IPointerDownHandler |
| | 16 | | { |
| 1 | 17 | | private static readonly int RANDOMIZE_ANIMATOR_LOADING_BOOL = Animator.StringToHash("Loading"); |
| | 18 | | private const string VIEW_PATH = "AvatarEditorHUD"; |
| | 19 | | private const string VIEW_OBJECT_NAME = "_AvatarEditorHUD"; |
| | 20 | | internal const int AVATAR_SECTION_INDEX = 0; |
| | 21 | | internal const string AVATAR_SECTION_TITLE = "Avatar"; |
| | 22 | | internal const int EMOTES_SECTION_INDEX = 1; |
| | 23 | | internal const string EMOTES_SECTION_TITLE = "Emotes"; |
| | 24 | | private const string RESET_PREVIEW_ANIMATION = "Idle"; |
| | 25 | | private const float TIME_TO_RESET_PREVIEW_ANIMATION = 0.2f; |
| | 26 | |
|
| 0 | 27 | | public bool isOpen { get; private set; } |
| 0 | 28 | | internal DataStore_EmotesCustomization emotesCustomizationDataStore => DataStore.i.emotesCustomization; |
| | 29 | |
|
| | 30 | | internal bool arePanelsInitialized = false; |
| | 31 | |
|
| | 32 | | [Serializable] |
| | 33 | | public class AvatarEditorNavigationInfo |
| | 34 | | { |
| | 35 | | public Toggle toggle; |
| | 36 | | public Canvas canvas; |
| | 37 | | public bool enabledByDefault; |
| | 38 | | public CharacterPreviewController.CameraFocus focus = CharacterPreviewController.CameraFocus.DefaultEditing; |
| | 39 | |
|
| | 40 | | //To remove when we refactor this to avoid ToggleGroup issues when quitting application |
| 1880 | 41 | | public void Initialize() { Application.quitting += () => toggle.onValueChanged.RemoveAllListeners(); } |
| | 42 | | } |
| | 43 | |
|
| | 44 | | [Serializable] |
| | 45 | | public class AvatarEditorWearableFilter |
| | 46 | | { |
| | 47 | | public string categoryFilter; |
| | 48 | | public ItemSelector selector; |
| | 49 | | } |
| | 50 | |
|
| | 51 | | [SerializeField] |
| | 52 | | internal Canvas avatarEditorCanvas; |
| | 53 | |
|
| | 54 | | [SerializeField] |
| | 55 | | internal CanvasGroup avatarEditorCanvasGroup; |
| | 56 | |
|
| | 57 | | [SerializeField] |
| | 58 | | internal AvatarEditorNavigationInfo[] navigationInfos; |
| | 59 | |
|
| | 60 | | [SerializeField] |
| | 61 | | internal AvatarEditorWearableFilter[] wearableGridPairs; |
| | 62 | |
|
| | 63 | | [SerializeField] |
| | 64 | | internal AvatarEditorNavigationInfo collectiblesNavigationInfo; |
| | 65 | |
|
| | 66 | | [SerializeField] |
| | 67 | | internal ItemSelector collectiblesItemSelector; |
| | 68 | |
|
| | 69 | | [SerializeField] |
| | 70 | | internal ColorSelector skinColorSelector; |
| | 71 | |
|
| | 72 | | [SerializeField] |
| | 73 | | internal ColorPickerComponentView eyeColorPickerComponent; |
| | 74 | |
|
| | 75 | | [SerializeField] |
| | 76 | | internal ColorPickerComponentView hairColorPickerComponent; |
| | 77 | |
|
| | 78 | | [SerializeField] |
| | 79 | | internal ColorPickerComponentView facialHairColorPickerComponent; |
| | 80 | |
|
| | 81 | | [SerializeField] |
| | 82 | | internal ColorPickerComponentView eyeBrowsColorPickerComponent; |
| | 83 | |
|
| | 84 | | [SerializeField] |
| | 85 | | internal GameObject characterPreviewPrefab; |
| | 86 | |
|
| | 87 | | [SerializeField] |
| | 88 | | internal PreviewCameraRotation characterPreviewRotation; |
| | 89 | |
|
| | 90 | | [SerializeField] |
| | 91 | | internal Button randomizeButton; |
| | 92 | |
|
| | 93 | | [SerializeField] |
| | 94 | | internal Animator randomizeAnimator; |
| | 95 | |
|
| | 96 | | [SerializeField] |
| | 97 | | internal Button doneButton; |
| | 98 | |
|
| | 99 | | [SerializeField] internal Button[] goToMarketplaceButtons; |
| | 100 | |
|
| | 101 | | [SerializeField] internal GameObject loadingSpinnerGameObject; |
| | 102 | |
|
| | 103 | | [Header("Collectibles")] |
| | 104 | | [SerializeField] |
| | 105 | | internal GameObject web3Container; |
| | 106 | |
|
| | 107 | | [SerializeField] |
| | 108 | | internal GameObject noWeb3Container; |
| | 109 | |
|
| | 110 | | [Header("Skins")] |
| | 111 | |
|
| | 112 | | [SerializeField] internal GameObject skinsFeatureContainer; |
| | 113 | |
|
| | 114 | | [SerializeField] internal GameObject skinsWeb3Container; |
| | 115 | |
|
| | 116 | | [SerializeField] internal GameObject skinsMissingWeb3Container; |
| | 117 | |
|
| | 118 | | [SerializeField] internal GameObject skinsConnectWalletButtonContainer; |
| | 119 | |
|
| | 120 | | [SerializeField] private GameObject skinsPopulatedListContainer; |
| | 121 | | [SerializeField] private GameObject skinsEmptyListContainer; |
| | 122 | |
|
| | 123 | | [SerializeField] |
| | 124 | | internal DropdownComponentView collectionsDropdown; |
| | 125 | |
|
| | 126 | | [Header("Section Selector")] |
| | 127 | | [SerializeField] internal SectionSelectorComponentView sectionSelector; |
| | 128 | | [SerializeField] internal TMP_Text sectionTitle; |
| | 129 | | [SerializeField] internal GameObject avatarSection; |
| | 130 | | [SerializeField] internal GameObject emotesSection; |
| | 131 | |
|
| | 132 | | [SerializeField] internal UIHelper_ClickBlocker clickBlocker; |
| | 133 | | [SerializeField] internal Notification noItemInCollectionWarning; |
| | 134 | |
|
| | 135 | | private static CharacterPreviewController characterPreviewController; |
| | 136 | | private AvatarEditorHUDController controller; |
| 50 | 137 | | internal readonly Dictionary<string, ItemSelector> selectorsByCategory = new Dictionary<string, ItemSelector>(); |
| 50 | 138 | | private readonly HashSet<WearableItem> wearablesWithLoadingSpinner = new HashSet<WearableItem>(); |
| 50 | 139 | | private readonly Dictionary<string, ToggleComponentModel> loadedCollectionModels = new Dictionary<string, ToggleComp |
| | 140 | | private bool isAvatarDirty; |
| | 141 | | private AvatarModel avatarModelToUpdate; |
| | 142 | | private bool updateAvatarShouldSkipAudio; |
| | 143 | |
|
| | 144 | | public event Action<AvatarModel> OnAvatarAppear; |
| | 145 | | public event Action<bool> OnSetVisibility; |
| | 146 | | public event Action OnRandomize; |
| | 147 | |
|
| | 148 | | private void Awake() |
| | 149 | | { |
| 48 | 150 | | loadingSpinnerGameObject.SetActive(false); |
| 48 | 151 | | doneButton.interactable = false; //the default state of the button should be disable until a profile has been lo |
| 48 | 152 | | if (characterPreviewController == null) |
| | 153 | | { |
| 48 | 154 | | characterPreviewController = Instantiate(characterPreviewPrefab).GetComponent<CharacterPreviewController>(); |
| 48 | 155 | | characterPreviewController.name = "_CharacterPreviewController"; |
| | 156 | | } |
| | 157 | |
|
| 48 | 158 | | isOpen = false; |
| 48 | 159 | | arePanelsInitialized = false; |
| 48 | 160 | | } |
| | 161 | |
|
| | 162 | | private void Initialize(AvatarEditorHUDController controller) |
| | 163 | | { |
| 48 | 164 | | this.controller = controller; |
| 48 | 165 | | gameObject.name = VIEW_OBJECT_NAME; |
| | 166 | |
|
| 48 | 167 | | randomizeButton.onClick.AddListener(OnRandomizeButton); |
| 48 | 168 | | doneButton.onClick.AddListener(OnDoneButton); |
| 48 | 169 | | InitializeWearableChangeEvents(); |
| | 170 | |
|
| 576 | 171 | | foreach (var button in goToMarketplaceButtons) |
| 240 | 172 | | button.onClick.RemoveAllListeners(); |
| 576 | 173 | | foreach (var button in goToMarketplaceButtons) |
| 240 | 174 | | button.onClick.AddListener(controller.GoToMarketplaceOrConnectWallet); |
| | 175 | |
|
| 48 | 176 | | characterPreviewController.camera.enabled = false; |
| | 177 | |
|
| 48 | 178 | | collectionsDropdown.OnOptionSelectionChanged -= controller.ToggleThirdPartyCollection; |
| 48 | 179 | | collectionsDropdown.OnOptionSelectionChanged += controller.ToggleThirdPartyCollection; |
| | 180 | |
|
| 48 | 181 | | clickBlocker.OnClicked += ClickBlockerClicked; |
| | 182 | |
|
| 48 | 183 | | ConfigureSectionSelector(); |
| 48 | 184 | | } |
| | 185 | |
|
| | 186 | | private void Update() |
| | 187 | | { |
| 1 | 188 | | UpdateAvatarModelWhenNeeded(); |
| 1 | 189 | | } |
| | 190 | |
|
| | 191 | | public void SetIsWeb3(bool isWeb3User) |
| | 192 | | { |
| 103 | 193 | | web3Container.SetActive(isWeb3User); |
| 103 | 194 | | noWeb3Container.SetActive(!isWeb3User); |
| 103 | 195 | | skinsWeb3Container.SetActive(isWeb3User); |
| 103 | 196 | | skinsMissingWeb3Container.SetActive(!isWeb3User); |
| 103 | 197 | | } |
| | 198 | |
|
| | 199 | | internal void InitializeNavigationEvents(bool isGuest) |
| | 200 | | { |
| 103 | 201 | | if (arePanelsInitialized) |
| 56 | 202 | | return; |
| | 203 | |
|
| 1880 | 204 | | for (int i = 0; i < navigationInfos.Length; i++) |
| | 205 | | { |
| 893 | 206 | | InitializeNavigationInfo(navigationInfos[i]); |
| | 207 | | } |
| 47 | 208 | | InitializeNavigationInfo(collectiblesNavigationInfo, !isGuest); |
| | 209 | |
|
| 47 | 210 | | characterPreviewRotation.OnHorizontalRotation += characterPreviewController.Rotate; |
| 47 | 211 | | arePanelsInitialized = true; |
| 47 | 212 | | } |
| | 213 | |
|
| | 214 | | private void InitializeNavigationInfo(AvatarEditorNavigationInfo current, bool isActive) |
| | 215 | | { |
| 940 | 216 | | current.Initialize(); |
| | 217 | |
|
| 940 | 218 | | current.toggle.isOn = isActive ? current.enabledByDefault : false; |
| 940 | 219 | | current.canvas.gameObject.SetActive(isActive ? current.enabledByDefault : false); |
| | 220 | |
|
| 940 | 221 | | current.toggle.onValueChanged.AddListener((on) => |
| | 222 | | { |
| 47 | 223 | | current.canvas.gameObject.SetActive(@on); |
| 47 | 224 | | characterPreviewController.SetFocus(current.focus); |
| 47 | 225 | | }); |
| 940 | 226 | | } |
| | 227 | |
|
| | 228 | | private void InitializeNavigationInfo(AvatarEditorNavigationInfo current) |
| | 229 | | { |
| 893 | 230 | | InitializeNavigationInfo(current, true); |
| 893 | 231 | | } |
| | 232 | |
|
| | 233 | | private void InitializeWearableChangeEvents() |
| | 234 | | { |
| 48 | 235 | | int nPairs = wearableGridPairs.Length; |
| 1728 | 236 | | for (int i = 0; i < nPairs; i++) |
| | 237 | | { |
| 816 | 238 | | wearableGridPairs[i].selector.OnItemClicked += controller.WearableClicked; |
| 816 | 239 | | wearableGridPairs[i].selector.OnSellClicked += controller.SellCollectible; |
| 816 | 240 | | selectorsByCategory.Add(wearableGridPairs[i].categoryFilter, wearableGridPairs[i].selector); |
| | 241 | | } |
| | 242 | |
|
| 48 | 243 | | collectiblesItemSelector.OnItemClicked += controller.WearableClicked; |
| 48 | 244 | | collectiblesItemSelector.OnSellClicked += controller.SellCollectible; |
| | 245 | |
|
| 48 | 246 | | skinColorSelector.OnColorSelectorChange += controller.SkinColorClicked; |
| 48 | 247 | | eyeColorPickerComponent.OnColorChanged += controller.EyesColorClicked; |
| 48 | 248 | | hairColorPickerComponent.OnColorChanged += controller.HairColorClicked; |
| 48 | 249 | | facialHairColorPickerComponent.OnColorChanged += controller.HairColorClicked; |
| 48 | 250 | | eyeBrowsColorPickerComponent.OnColorChanged += controller.HairColorClicked; |
| 48 | 251 | | } |
| | 252 | |
|
| | 253 | | internal static AvatarEditorHUDView Create(AvatarEditorHUDController controller) |
| | 254 | | { |
| 48 | 255 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<AvatarEditorHUDView>(); |
| 48 | 256 | | view.Initialize(controller); |
| 48 | 257 | | return view; |
| | 258 | | } |
| | 259 | |
|
| | 260 | | public void UpdateSelectedBody(WearableItem bodyShape) |
| | 261 | | { |
| 2232 | 262 | | for (int i = 0; i < wearableGridPairs.Length; i++) |
| | 263 | | { |
| 1054 | 264 | | if (wearableGridPairs[i].categoryFilter == WearableLiterals.Categories.BODY_SHAPE) |
| | 265 | | { |
| 62 | 266 | | wearableGridPairs[i].selector.UnselectAll(); |
| 62 | 267 | | wearableGridPairs[i].selector.Select(bodyShape.id); |
| 62 | 268 | | } |
| | 269 | | else |
| | 270 | | { |
| 992 | 271 | | wearableGridPairs[i].selector.SetBodyShape(bodyShape.id); |
| | 272 | | } |
| | 273 | | } |
| | 274 | |
|
| 62 | 275 | | collectiblesItemSelector.SetBodyShape(bodyShape.id); |
| 62 | 276 | | } |
| | 277 | |
|
| | 278 | | public void EquipWearable(WearableItem wearable) |
| | 279 | | { |
| 1099 | 280 | | selectorsByCategory[wearable.data.category].Select(wearable.id); |
| 1099 | 281 | | SetWearableLoadingSpinner(wearable, true); |
| 1099 | 282 | | collectiblesItemSelector.Select(wearable.id); |
| 1099 | 283 | | } |
| | 284 | |
|
| | 285 | | public void UnequipWearable(WearableItem wearable) |
| | 286 | | { |
| 464 | 287 | | selectorsByCategory[wearable.data.category].Unselect(wearable.id); |
| 464 | 288 | | SetWearableLoadingSpinner(wearable, false); |
| 464 | 289 | | collectiblesItemSelector.Unselect(wearable.id); |
| 464 | 290 | | } |
| | 291 | |
|
| | 292 | | internal void SetWearableLoadingSpinner(WearableItem wearable, bool isActive) |
| | 293 | | { |
| 1563 | 294 | | selectorsByCategory[wearable.data.category].SetWearableLoadingSpinner(wearable.id, isActive); |
| 1563 | 295 | | collectiblesItemSelector.SetWearableLoadingSpinner(wearable.id, isActive); |
| 1563 | 296 | | if (isActive) |
| 1099 | 297 | | wearablesWithLoadingSpinner.Add(wearable); |
| | 298 | | else |
| 464 | 299 | | wearablesWithLoadingSpinner.Remove(wearable); |
| 464 | 300 | | } |
| | 301 | |
|
| | 302 | | internal void ClearWearablesLoadingSpinner() |
| | 303 | | { |
| 0 | 304 | | foreach (WearableItem wearable in wearablesWithLoadingSpinner) |
| | 305 | | { |
| 0 | 306 | | selectorsByCategory[wearable.data.category].SetWearableLoadingSpinner(wearable.id, false); |
| 0 | 307 | | collectiblesItemSelector.SetWearableLoadingSpinner(wearable.id, false); |
| | 308 | | } |
| | 309 | |
|
| 0 | 310 | | wearablesWithLoadingSpinner.Clear(); |
| 0 | 311 | | } |
| | 312 | |
|
| | 313 | | public void SelectHairColor(Color hairColor) |
| | 314 | | { |
| 108 | 315 | | hairColorPickerComponent.SetColorSelector(hairColor); |
| 108 | 316 | | hairColorPickerComponent.UpdateSliderValues(hairColor); |
| 108 | 317 | | eyeBrowsColorPickerComponent.SetColorSelector(hairColor); |
| 108 | 318 | | eyeBrowsColorPickerComponent.UpdateSliderValues(hairColor); |
| 108 | 319 | | facialHairColorPickerComponent.SetColorSelector(hairColor); |
| 108 | 320 | | facialHairColorPickerComponent.UpdateSliderValues(hairColor); |
| 108 | 321 | | } |
| | 322 | |
|
| | 323 | | public Color GetRandomColor() |
| | 324 | | { |
| 2 | 325 | | return Color.HSVToRGB(UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range |
| | 326 | | } |
| | 327 | |
|
| | 328 | | public void SelectSkinColor(Color skinColor) |
| | 329 | | { |
| 107 | 330 | | skinColorSelector.Select(skinColor); |
| 107 | 331 | | } |
| | 332 | |
|
| | 333 | | public void SelectEyeColor(Color eyesColor) |
| | 334 | | { |
| 108 | 335 | | eyeColorPickerComponent.SetColorSelector(eyesColor); |
| 108 | 336 | | eyeColorPickerComponent.UpdateSliderValues(eyesColor); |
| 108 | 337 | | } |
| | 338 | |
|
| | 339 | | public void SetColors(List<Color> skinColors, List<Color> hairColors, List<Color> eyeColors) |
| | 340 | | { |
| 48 | 341 | | skinColorSelector.Populate(skinColors); |
| 48 | 342 | | eyeColorPickerComponent.SetColorList(eyeColors); |
| 48 | 343 | | hairColorPickerComponent.SetColorList(hairColors); |
| 48 | 344 | | eyeBrowsColorPickerComponent.SetColorList(hairColors); |
| 48 | 345 | | facialHairColorPickerComponent.SetColorList(hairColors); |
| 48 | 346 | | } |
| | 347 | |
|
| | 348 | | public void UnselectAllWearables() |
| | 349 | | { |
| 3744 | 350 | | for (int i = 0; i < wearableGridPairs.Length; i++) |
| | 351 | | { |
| 1768 | 352 | | if (wearableGridPairs[i].categoryFilter != WearableLiterals.Categories.BODY_SHAPE) |
| | 353 | | { |
| 1664 | 354 | | wearableGridPairs[i].selector.UnselectAll(); |
| | 355 | | } |
| | 356 | | } |
| | 357 | |
|
| 104 | 358 | | collectiblesItemSelector.UnselectAll(); |
| 104 | 359 | | } |
| | 360 | |
|
| | 361 | | public void UpdateAvatarPreview(AvatarModel avatarModel, bool skipAudio) |
| | 362 | | { |
| 125 | 363 | | if (avatarModel?.wearables == null) |
| 0 | 364 | | return; |
| | 365 | |
|
| | 366 | | // We delay the updating of the avatar 1 frame to disengage from the kernel message flow |
| | 367 | | // otherwise the cancellation of the updating task throws an exception that is catch by |
| | 368 | | // kernel setthrew method, which floods the analytics. |
| | 369 | | // Also it updates just once if its called many times in a row |
| 125 | 370 | | isAvatarDirty = true; |
| 125 | 371 | | avatarModelToUpdate = avatarModel; |
| 125 | 372 | | updateAvatarShouldSkipAudio = skipAudio; |
| | 373 | |
|
| 125 | 374 | | doneButton.interactable = false; |
| 125 | 375 | | loadingSpinnerGameObject.SetActive(true); |
| 125 | 376 | | } |
| | 377 | |
|
| | 378 | | public void AddWearable(WearableItem wearableItem, int amount, |
| | 379 | | Func<WearableItem, bool> hideOtherWearablesToastStrategy, |
| | 380 | | Func<WearableItem, bool> replaceOtherWearablesToastStrategy) |
| | 381 | | { |
| 4221 | 382 | | if (wearableItem == null) |
| 0 | 383 | | return; |
| | 384 | |
|
| 4221 | 385 | | if (!selectorsByCategory.ContainsKey(wearableItem.data.category)) |
| | 386 | | { |
| 0 | 387 | | Debug.LogError($"Category couldn't find selector for category: {wearableItem.data.category} "); |
| 0 | 388 | | return; |
| | 389 | | } |
| | 390 | |
|
| 4221 | 391 | | string collectionName = GetWearableCollectionName(wearableItem); |
| | 392 | |
|
| 4221 | 393 | | selectorsByCategory[wearableItem.data.category].AddWearable( |
| | 394 | | wearableItem, |
| | 395 | | collectionName, |
| | 396 | | amount, |
| | 397 | | hideOtherWearablesToastStrategy, |
| | 398 | | replaceOtherWearablesToastStrategy); |
| | 399 | |
|
| 4221 | 400 | | if (wearableItem.IsCollectible() || wearableItem.IsFromThirdPartyCollection) |
| | 401 | | { |
| 21 | 402 | | collectiblesItemSelector.AddWearable( |
| | 403 | | wearableItem, |
| | 404 | | collectionName, |
| | 405 | | amount, |
| | 406 | | hideOtherWearablesToastStrategy, |
| | 407 | | replaceOtherWearablesToastStrategy); |
| | 408 | | } |
| 4221 | 409 | | } |
| | 410 | |
|
| | 411 | | public void RefreshSelectorsSize() |
| | 412 | | { |
| 162 | 413 | | using (var iterator = selectorsByCategory.GetEnumerator()) |
| | 414 | | { |
| 2916 | 415 | | while (iterator.MoveNext()) |
| | 416 | | { |
| 2754 | 417 | | iterator.Current.Value.UpdateSelectorLayout(); |
| | 418 | | } |
| 162 | 419 | | } |
| | 420 | |
|
| 162 | 421 | | collectiblesItemSelector.UpdateSelectorLayout(); |
| 162 | 422 | | } |
| | 423 | |
|
| | 424 | | private string GetWearableCollectionName(WearableItem wearableItem) |
| | 425 | | { |
| 4221 | 426 | | string collectionName = string.Empty; |
| | 427 | |
|
| 4221 | 428 | | if (wearableItem.IsFromThirdPartyCollection) |
| | 429 | | { |
| 0 | 430 | | loadedCollectionModels.TryGetValue(wearableItem.ThirdPartyCollectionId, out ToggleComponentModel collectionM |
| | 431 | |
|
| 0 | 432 | | if (collectionModel != null) |
| 0 | 433 | | collectionName = collectionModel.text; |
| | 434 | | } |
| | 435 | |
|
| 4221 | 436 | | return collectionName; |
| | 437 | | } |
| | 438 | |
|
| | 439 | | public void RemoveWearable(WearableItem wearableItem) |
| | 440 | | { |
| 0 | 441 | | if (wearableItem == null) |
| 0 | 442 | | return; |
| | 443 | |
|
| 0 | 444 | | if (!selectorsByCategory.ContainsKey(wearableItem.data.category)) |
| | 445 | | { |
| 0 | 446 | | Debug.LogError($"Category couldn't find selector for category: {wearableItem.data.category} "); |
| 0 | 447 | | return; |
| | 448 | | } |
| | 449 | |
|
| 0 | 450 | | selectorsByCategory[wearableItem.data.category].RemoveWearable(wearableItem.id); |
| 0 | 451 | | if (wearableItem.IsCollectible() || wearableItem.IsFromThirdPartyCollection) |
| 0 | 452 | | collectiblesItemSelector.RemoveWearable(wearableItem.id); |
| 0 | 453 | | } |
| | 454 | |
|
| | 455 | | public void RemoveAllWearables() |
| | 456 | | { |
| 151 | 457 | | using (var enumerator = selectorsByCategory.GetEnumerator()) |
| | 458 | | { |
| 2718 | 459 | | while (enumerator.MoveNext()) |
| | 460 | | { |
| 2567 | 461 | | enumerator.Current.Value.RemoveAllWearables(); |
| | 462 | | } |
| 151 | 463 | | } |
| | 464 | |
|
| 151 | 465 | | collectiblesItemSelector.RemoveAllWearables(); |
| 151 | 466 | | } |
| | 467 | |
|
| | 468 | | private void OnRandomizeButton() |
| | 469 | | { |
| 0 | 470 | | OnRandomize?.Invoke(); |
| 0 | 471 | | controller.RandomizeWearables(); |
| 0 | 472 | | randomizeAnimator?.SetBool(RANDOMIZE_ANIMATOR_LOADING_BOOL, true); |
| 0 | 473 | | } |
| | 474 | |
|
| | 475 | | private void OnDoneButton() |
| | 476 | | { |
| 0 | 477 | | doneButton.interactable = false; |
| 0 | 478 | | CoroutineStarter.Start(TakeSnapshotsAfterStopPreviewAnimation()); |
| 0 | 479 | | eyeColorPickerComponent.SetActive(false); |
| 0 | 480 | | hairColorPickerComponent.SetActive(false); |
| 0 | 481 | | facialHairColorPickerComponent.SetActive(false); |
| 0 | 482 | | eyeBrowsColorPickerComponent.SetActive(false); |
| 0 | 483 | | } |
| | 484 | |
|
| | 485 | | private IEnumerator TakeSnapshotsAfterStopPreviewAnimation() |
| | 486 | | { |
| | 487 | | // We need to stop the current preview animation in order to take a correct snapshot |
| 0 | 488 | | ResetPreviewEmote(); |
| 0 | 489 | | yield return new WaitForSeconds(TIME_TO_RESET_PREVIEW_ANIMATION); |
| 0 | 490 | | characterPreviewController.TakeSnapshots(OnSnapshotsReady, OnSnapshotsFailed); |
| 0 | 491 | | } |
| | 492 | |
|
| | 493 | | private void OnSnapshotsReady(Texture2D face256, Texture2D body) |
| | 494 | | { |
| 0 | 495 | | doneButton.interactable = true; |
| 0 | 496 | | controller.SaveAvatar(face256, body); |
| 0 | 497 | | } |
| | 498 | |
|
| 0 | 499 | | private void OnSnapshotsFailed() { doneButton.interactable = true; } |
| | 500 | |
|
| | 501 | | public void SetVisibility(bool visible) |
| | 502 | | { |
| 92 | 503 | | characterPreviewController.camera.enabled = visible; |
| 92 | 504 | | avatarEditorCanvas.enabled = visible; |
| 92 | 505 | | avatarEditorCanvasGroup.blocksRaycasts = visible; |
| | 506 | |
|
| 92 | 507 | | if (visible && !isOpen) |
| | 508 | | { |
| 43 | 509 | | OnSetVisibility?.Invoke(visible); |
| 0 | 510 | | } |
| 49 | 511 | | else if (!visible && isOpen) |
| | 512 | | { |
| 1 | 513 | | collectionsDropdown.Close(); |
| 1 | 514 | | noItemInCollectionWarning.Dismiss(true); |
| 1 | 515 | | OnSetVisibility?.Invoke(visible); |
| | 516 | | } |
| | 517 | |
|
| 92 | 518 | | isOpen = visible; |
| 92 | 519 | | } |
| | 520 | |
|
| | 521 | | public void CleanUp() |
| | 522 | | { |
| 48 | 523 | | loadingSpinnerGameObject = null; |
| 48 | 524 | | randomizeAnimator = null; |
| 48 | 525 | | if (wearableGridPairs != null) |
| | 526 | | { |
| 48 | 527 | | int nPairs = wearableGridPairs.Length; |
| 1728 | 528 | | for (int i = 0; i < nPairs; i++) |
| | 529 | | { |
| 816 | 530 | | var itemSelector = wearableGridPairs[i].selector; |
| 816 | 531 | | if (itemSelector != null) |
| | 532 | | { |
| 816 | 533 | | itemSelector.OnItemClicked -= controller.WearableClicked; |
| 816 | 534 | | itemSelector.OnSellClicked -= controller.SellCollectible; |
| | 535 | | } |
| | 536 | | } |
| | 537 | | } |
| | 538 | |
|
| 48 | 539 | | if (collectiblesItemSelector != null) |
| | 540 | | { |
| 48 | 541 | | collectiblesItemSelector.OnItemClicked -= controller.WearableClicked; |
| 48 | 542 | | collectiblesItemSelector.OnSellClicked -= controller.SellCollectible; |
| | 543 | | } |
| | 544 | |
|
| 48 | 545 | | if (skinColorSelector != null) |
| 48 | 546 | | skinColorSelector.OnColorSelectorChange -= controller.SkinColorClicked; |
| 48 | 547 | | if (eyeColorPickerComponent != null) |
| 48 | 548 | | eyeColorPickerComponent.OnColorChanged -= controller.EyesColorClicked; |
| 48 | 549 | | if (hairColorPickerComponent != null) |
| 48 | 550 | | hairColorPickerComponent.OnColorChanged -= controller.HairColorClicked; |
| 48 | 551 | | if (facialHairColorPickerComponent != null) |
| 48 | 552 | | facialHairColorPickerComponent.OnColorChanged -= controller.HairColorClicked; |
| 48 | 553 | | if (eyeBrowsColorPickerComponent != null) |
| 48 | 554 | | eyeBrowsColorPickerComponent.OnColorChanged -= controller.HairColorClicked; |
| | 555 | |
|
| 48 | 556 | | if (this != null) |
| 48 | 557 | | Destroy(gameObject); |
| | 558 | |
|
| 48 | 559 | | if (characterPreviewController != null) |
| | 560 | | { |
| 48 | 561 | | Destroy(characterPreviewController.gameObject); |
| 48 | 562 | | characterPreviewController = null; |
| | 563 | | } |
| | 564 | |
|
| 48 | 565 | | collectionsDropdown.OnOptionSelectionChanged -= controller.ToggleThirdPartyCollection; |
| 48 | 566 | | collectionsDropdown.Dispose(); |
| | 567 | |
|
| 48 | 568 | | sectionSelector.GetSection(AVATAR_SECTION_INDEX).onSelect.RemoveAllListeners(); |
| 48 | 569 | | sectionSelector.GetSection(EMOTES_SECTION_INDEX).onSelect.RemoveAllListeners(); |
| | 570 | |
|
| 48 | 571 | | clickBlocker.OnClicked -= ClickBlockerClicked; |
| 48 | 572 | | } |
| | 573 | |
|
| | 574 | | public void SetAsFullScreenMenuMode(Transform parentTransform) |
| | 575 | | { |
| 48 | 576 | | if (parentTransform == null) |
| 48 | 577 | | return; |
| | 578 | |
|
| 0 | 579 | | transform.SetParent(parentTransform); |
| 0 | 580 | | transform.localScale = Vector3.one; |
| | 581 | |
|
| 0 | 582 | | RectTransform rectTransform = transform as RectTransform; |
| 0 | 583 | | rectTransform.anchorMin = Vector2.zero; |
| 0 | 584 | | rectTransform.anchorMax = Vector2.one; |
| 0 | 585 | | rectTransform.pivot = new Vector2(0.5f, 0.5f); |
| 0 | 586 | | rectTransform.localPosition = Vector2.zero; |
| 0 | 587 | | rectTransform.offsetMax = Vector2.zero; |
| 0 | 588 | | rectTransform.offsetMin = Vector2.zero; |
| 0 | 589 | | } |
| | 590 | |
|
| | 591 | | public void OnPointerDown(PointerEventData eventData) |
| | 592 | | { |
| 0 | 593 | | if (eventData.pointerPressRaycast.gameObject != eyeColorPickerComponent.gameObject && |
| | 594 | | eventData.pointerPressRaycast.gameObject != hairColorPickerComponent.gameObject && |
| | 595 | | eventData.pointerPressRaycast.gameObject != eyeBrowsColorPickerComponent.gameObject && |
| | 596 | | eventData.pointerPressRaycast.gameObject != facialHairColorPickerComponent.gameObject) |
| | 597 | | { |
| 0 | 598 | | eyeColorPickerComponent.SetActive(false); |
| 0 | 599 | | hairColorPickerComponent.SetActive(false); |
| 0 | 600 | | eyeBrowsColorPickerComponent.SetActive(false); |
| 0 | 601 | | facialHairColorPickerComponent.SetActive(false); |
| | 602 | | } |
| 0 | 603 | | } |
| | 604 | |
|
| | 605 | | public void LoadCollectionsDropdown(Collection[] collections) |
| | 606 | | { |
| 0 | 607 | | List<ToggleComponentModel> collectionsToAdd = new List<ToggleComponentModel>(); |
| 0 | 608 | | foreach (var collection in collections) |
| | 609 | | { |
| 0 | 610 | | ToggleComponentModel newCollectionModel = new ToggleComponentModel |
| | 611 | | { |
| | 612 | | id = collection.urn, |
| | 613 | | text = collection.name, |
| | 614 | | isOn = false, |
| | 615 | | isTextActive = true |
| | 616 | | }; |
| | 617 | |
|
| 0 | 618 | | collectionsToAdd.Add(newCollectionModel); |
| 0 | 619 | | loadedCollectionModels.Add(collection.urn, newCollectionModel); |
| | 620 | | } |
| | 621 | |
|
| 0 | 622 | | collectionsDropdown.SetOptions(collectionsToAdd); |
| 0 | 623 | | } |
| | 624 | |
|
| | 625 | | public void BlockCollectionsDropdown(bool isBlocked) |
| | 626 | | { |
| 1 | 627 | | collectionsDropdown.SetLoadingActive(isBlocked); |
| 1 | 628 | | } |
| | 629 | |
|
| | 630 | | public void ShowSkinPopulatedList(bool show) |
| | 631 | | { |
| 0 | 632 | | skinsPopulatedListContainer.SetActive(show); |
| 0 | 633 | | skinsEmptyListContainer.SetActive(!show); |
| 0 | 634 | | skinsConnectWalletButtonContainer.SetActive(show); |
| 0 | 635 | | } |
| | 636 | |
|
| | 637 | | public void SetThirdPartyCollectionsVisibility(bool visible) => |
| 48 | 638 | | collectionsDropdown.gameObject.SetActive(visible); |
| | 639 | |
|
| | 640 | | internal void ConfigureSectionSelector() |
| | 641 | | { |
| 48 | 642 | | sectionTitle.text = AVATAR_SECTION_TITLE; |
| | 643 | |
|
| 48 | 644 | | sectionSelector.GetSection(AVATAR_SECTION_INDEX).onSelect.AddListener((isSelected) => |
| | 645 | | { |
| 0 | 646 | | avatarSection.SetActive(isSelected); |
| 0 | 647 | | randomizeButton.gameObject.SetActive(true); |
| | 648 | |
|
| 0 | 649 | | if (isSelected) |
| | 650 | | { |
| 0 | 651 | | sectionTitle.text = AVATAR_SECTION_TITLE; |
| 0 | 652 | | ResetPreviewEmote(); |
| | 653 | | } |
| | 654 | |
|
| 0 | 655 | | emotesCustomizationDataStore.isEmotesCustomizationSelected.Set(false, notifyEvent: false); |
| 0 | 656 | | }); |
| 48 | 657 | | sectionSelector.GetSection(EMOTES_SECTION_INDEX).onSelect.AddListener((isSelected) => |
| | 658 | | { |
| 0 | 659 | | emotesSection.SetActive(isSelected); |
| 0 | 660 | | randomizeButton.gameObject.SetActive(false); |
| | 661 | |
|
| 0 | 662 | | if (isSelected) |
| | 663 | | { |
| 0 | 664 | | sectionTitle.text = EMOTES_SECTION_TITLE; |
| 0 | 665 | | ResetPreviewEmote(); |
| | 666 | | } |
| | 667 | |
|
| 0 | 668 | | characterPreviewController.SetFocus(CharacterPreviewController.CameraFocus.DefaultEditing); |
| 0 | 669 | | emotesCustomizationDataStore.isEmotesCustomizationSelected.Set(true, notifyEvent: false); |
| 0 | 670 | | }); |
| 48 | 671 | | } |
| | 672 | |
|
| | 673 | | internal void SetSectionActive(int sectionIndex, bool isActive) |
| | 674 | | { |
| 96 | 675 | | sectionSelector.GetSection(sectionIndex).SetActive(isActive); |
| 288 | 676 | | sectionSelector.gameObject.SetActive(sectionSelector.GetAllSections().Count(x => x.IsActive()) > 1); |
| 96 | 677 | | } |
| | 678 | |
|
| 2 | 679 | | public void PlayPreviewEmote(string emoteId) { characterPreviewController.PlayEmote(emoteId, (long)Time.realtimeSinc |
| | 680 | |
|
| 2 | 681 | | public void ResetPreviewEmote() { PlayPreviewEmote(RESET_PREVIEW_ANIMATION); } |
| | 682 | |
|
| | 683 | | public void ToggleThirdPartyCollection(string collectionId, bool isOn) |
| | 684 | | { |
| 0 | 685 | | List<IToggleComponentView> allCollectionOptions = collectionsDropdown.GetAllOptions(); |
| 0 | 686 | | foreach (IToggleComponentView collectionOption in allCollectionOptions) |
| | 687 | | { |
| 0 | 688 | | if (collectionOption.id == collectionId) |
| 0 | 689 | | collectionOption.isOn = isOn; |
| | 690 | | } |
| 0 | 691 | | } |
| | 692 | | public void ShowNoItemOfWearableCollectionWarning() |
| | 693 | | { |
| 0 | 694 | | noItemInCollectionWarning.Dismiss(true); |
| 0 | 695 | | noItemInCollectionWarning.Show(new DCL.NotificationModel.Model |
| | 696 | | { |
| | 697 | | timer = 5f, |
| | 698 | | }); |
| 0 | 699 | | } |
| | 700 | |
|
| | 701 | | private void ClickBlockerClicked() |
| | 702 | | { |
| 0 | 703 | | noItemInCollectionWarning.Dismiss(false); |
| 0 | 704 | | } |
| | 705 | |
|
| | 706 | | private void UpdateAvatarModelWhenNeeded() |
| | 707 | | { |
| 1 | 708 | | if (isAvatarDirty) |
| | 709 | | { |
| 0 | 710 | | characterPreviewController.UpdateModel(avatarModelToUpdate, |
| | 711 | | () => |
| | 712 | | { |
| 0 | 713 | | if (doneButton != null) |
| 0 | 714 | | doneButton.interactable = true; |
| | 715 | |
|
| 0 | 716 | | loadingSpinnerGameObject?.SetActive(false); |
| | 717 | |
|
| 0 | 718 | | if (!updateAvatarShouldSkipAudio) |
| 0 | 719 | | OnAvatarAppear?.Invoke(avatarModelToUpdate); |
| | 720 | |
|
| 0 | 721 | | ClearWearablesLoadingSpinner(); |
| 0 | 722 | | randomizeAnimator?.SetBool(RANDOMIZE_ANIMATOR_LOADING_BOOL, false); |
| 0 | 723 | | }); |
| | 724 | |
|
| 0 | 725 | | isAvatarDirty = false; |
| | 726 | | } |
| 1 | 727 | | } |
| | 728 | | } |