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