< Summary

Class:AvatarEditorHUDView
Assembly:AvatarEditorHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/AvatarEditorHUDView.cs
Covered lines:204
Uncovered lines:105
Coverable lines:309
Total lines:728
Line coverage:66% (204 of 309)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarEditorHUDView()0%110100%
Initialize()0%110100%
AvatarEditorHUDView()0%110100%
Awake()0%220100%
Initialize(...)0%330100%
Update()0%110100%
SetIsWeb3(...)0%110100%
InitializeNavigationEvents(...)0%330100%
InitializeNavigationInfo(...)0%550100%
InitializeNavigationInfo(...)0%110100%
InitializeWearableChangeEvents()0%220100%
Create(...)0%110100%
UpdateSelectedBody(...)0%330100%
EquipWearable(...)0%110100%
UnequipWearable(...)0%110100%
SetWearableLoadingSpinner(...)0%220100%
ClearWearablesLoadingSpinner()0%6200%
SelectHairColor(...)0%110100%
GetRandomColor()0%110100%
SelectSkinColor(...)0%110100%
SelectEyeColor(...)0%110100%
SetColors(...)0%110100%
UnselectAllWearables()0%330100%
UpdateAvatarPreview(...)0%4.034087.5%
AddWearable(...)0%5.685070%
RefreshSelectorsSize()0%220100%
GetWearableCollectionName(...)0%4.123050%
RemoveWearable(...)0%30500%
RemoveAllWearables()0%220100%
OnRandomizeButton()0%12300%
OnDoneButton()0%2100%
TakeSnapshotsAfterStopPreviewAnimation()0%12300%
OnSnapshotsReady(...)0%2100%
OnSnapshotsFailed()0%2100%
SetVisibility(...)0%7.037091.67%
CleanUp()0%12120100%
SetAsFullScreenMenuMode(...)0%4.312016.67%
OnPointerDown(...)0%30500%
LoadCollectionsDropdown(...)0%6200%
BlockCollectionsDropdown(...)0%110100%
ShowSkinPopulatedList(...)0%2100%
SetThirdPartyCollectionsVisibility(...)0%110100%
ConfigureSectionSelector()0%110100%
SetSectionActive(...)0%220100%
PlayPreviewEmote(...)0%110100%
ResetPreviewEmote()0%110100%
ToggleThirdPartyCollection(...)0%12300%
ShowNoItemOfWearableCollectionWarning()0%2100%
ClickBlockerClicked()0%2100%
UpdateAvatarModelWhenNeeded()0%2.52050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/AvatarEditorHUDView.cs

#LineLine coverage
 1using DCL;
 2using System;
 3using System.Collections;
 4using System.Collections.Generic;
 5using System.Linq;
 6using System.Runtime.CompilerServices;
 7using TMPro;
 8using UnityEngine;
 9using UnityEngine.EventSystems;
 10using UnityEngine.UI;
 11using static WearableCollectionsAPIData;
 12
 13[assembly: InternalsVisibleTo("AvatarEditorHUDTests")]
 14
 15public class AvatarEditorHUDView : MonoBehaviour, IPointerDownHandler
 16{
 117    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
 027    public bool isOpen { get; private set; }
 028    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
 188041        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;
 50137    internal readonly Dictionary<string, ItemSelector> selectorsByCategory = new Dictionary<string, ItemSelector>();
 50138    private readonly HashSet<WearableItem> wearablesWithLoadingSpinner = new HashSet<WearableItem>();
 50139    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    {
 48150        loadingSpinnerGameObject.SetActive(false);
 48151        doneButton.interactable = false; //the default state of the button should be disable until a profile has been lo
 48152        if (characterPreviewController == null)
 153        {
 48154            characterPreviewController = Instantiate(characterPreviewPrefab).GetComponent<CharacterPreviewController>();
 48155            characterPreviewController.name = "_CharacterPreviewController";
 156        }
 157
 48158        isOpen = false;
 48159        arePanelsInitialized = false;
 48160    }
 161
 162    private void Initialize(AvatarEditorHUDController controller)
 163    {
 48164        this.controller = controller;
 48165        gameObject.name = VIEW_OBJECT_NAME;
 166
 48167        randomizeButton.onClick.AddListener(OnRandomizeButton);
 48168        doneButton.onClick.AddListener(OnDoneButton);
 48169        InitializeWearableChangeEvents();
 170
 576171        foreach (var button in goToMarketplaceButtons)
 240172            button.onClick.RemoveAllListeners();
 576173        foreach (var button in goToMarketplaceButtons)
 240174            button.onClick.AddListener(controller.GoToMarketplaceOrConnectWallet);
 175
 48176        characterPreviewController.camera.enabled = false;
 177
 48178        collectionsDropdown.OnOptionSelectionChanged -= controller.ToggleThirdPartyCollection;
 48179        collectionsDropdown.OnOptionSelectionChanged += controller.ToggleThirdPartyCollection;
 180
 48181        clickBlocker.OnClicked += ClickBlockerClicked;
 182
 48183        ConfigureSectionSelector();
 48184    }
 185
 186    private void Update()
 187    {
 1188        UpdateAvatarModelWhenNeeded();
 1189    }
 190
 191    public void SetIsWeb3(bool isWeb3User)
 192    {
 103193        web3Container.SetActive(isWeb3User);
 103194        noWeb3Container.SetActive(!isWeb3User);
 103195        skinsWeb3Container.SetActive(isWeb3User);
 103196        skinsMissingWeb3Container.SetActive(!isWeb3User);
 103197    }
 198
 199    internal void InitializeNavigationEvents(bool isGuest)
 200    {
 103201        if (arePanelsInitialized)
 56202            return;
 203
 1880204        for (int i = 0; i < navigationInfos.Length; i++)
 205        {
 893206            InitializeNavigationInfo(navigationInfos[i]);
 207        }
 47208        InitializeNavigationInfo(collectiblesNavigationInfo, !isGuest);
 209
 47210        characterPreviewRotation.OnHorizontalRotation += characterPreviewController.Rotate;
 47211        arePanelsInitialized = true;
 47212    }
 213
 214    private void InitializeNavigationInfo(AvatarEditorNavigationInfo current, bool isActive)
 215    {
 940216        current.Initialize();
 217
 940218        current.toggle.isOn = isActive ? current.enabledByDefault : false;
 940219        current.canvas.gameObject.SetActive(isActive ? current.enabledByDefault : false);
 220
 940221        current.toggle.onValueChanged.AddListener((on) =>
 222        {
 47223            current.canvas.gameObject.SetActive(@on);
 47224            characterPreviewController.SetFocus(current.focus);
 47225        });
 940226    }
 227
 228    private void InitializeNavigationInfo(AvatarEditorNavigationInfo current)
 229    {
 893230        InitializeNavigationInfo(current, true);
 893231    }
 232
 233    private void InitializeWearableChangeEvents()
 234    {
 48235        int nPairs = wearableGridPairs.Length;
 1728236        for (int i = 0; i < nPairs; i++)
 237        {
 816238            wearableGridPairs[i].selector.OnItemClicked += controller.WearableClicked;
 816239            wearableGridPairs[i].selector.OnSellClicked += controller.SellCollectible;
 816240            selectorsByCategory.Add(wearableGridPairs[i].categoryFilter, wearableGridPairs[i].selector);
 241        }
 242
 48243        collectiblesItemSelector.OnItemClicked += controller.WearableClicked;
 48244        collectiblesItemSelector.OnSellClicked += controller.SellCollectible;
 245
 48246        skinColorSelector.OnColorSelectorChange += controller.SkinColorClicked;
 48247        eyeColorPickerComponent.OnColorChanged += controller.EyesColorClicked;
 48248        hairColorPickerComponent.OnColorChanged += controller.HairColorClicked;
 48249        facialHairColorPickerComponent.OnColorChanged += controller.HairColorClicked;
 48250        eyeBrowsColorPickerComponent.OnColorChanged += controller.HairColorClicked;
 48251    }
 252
 253    internal static AvatarEditorHUDView Create(AvatarEditorHUDController controller)
 254    {
 48255        var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<AvatarEditorHUDView>();
 48256        view.Initialize(controller);
 48257        return view;
 258    }
 259
 260    public void UpdateSelectedBody(WearableItem bodyShape)
 261    {
 2232262        for (int i = 0; i < wearableGridPairs.Length; i++)
 263        {
 1054264            if (wearableGridPairs[i].categoryFilter == WearableLiterals.Categories.BODY_SHAPE)
 265            {
 62266                wearableGridPairs[i].selector.UnselectAll();
 62267                wearableGridPairs[i].selector.Select(bodyShape.id);
 62268            }
 269            else
 270            {
 992271                wearableGridPairs[i].selector.SetBodyShape(bodyShape.id);
 272            }
 273        }
 274
 62275        collectiblesItemSelector.SetBodyShape(bodyShape.id);
 62276    }
 277
 278    public void EquipWearable(WearableItem wearable)
 279    {
 1099280        selectorsByCategory[wearable.data.category].Select(wearable.id);
 1099281        SetWearableLoadingSpinner(wearable, true);
 1099282        collectiblesItemSelector.Select(wearable.id);
 1099283    }
 284
 285    public void UnequipWearable(WearableItem wearable)
 286    {
 464287        selectorsByCategory[wearable.data.category].Unselect(wearable.id);
 464288        SetWearableLoadingSpinner(wearable, false);
 464289        collectiblesItemSelector.Unselect(wearable.id);
 464290    }
 291
 292    internal void SetWearableLoadingSpinner(WearableItem wearable, bool isActive)
 293    {
 1563294        selectorsByCategory[wearable.data.category].SetWearableLoadingSpinner(wearable.id, isActive);
 1563295        collectiblesItemSelector.SetWearableLoadingSpinner(wearable.id, isActive);
 1563296        if (isActive)
 1099297            wearablesWithLoadingSpinner.Add(wearable);
 298        else
 464299            wearablesWithLoadingSpinner.Remove(wearable);
 464300    }
 301
 302    internal void ClearWearablesLoadingSpinner()
 303    {
 0304        foreach (WearableItem wearable in wearablesWithLoadingSpinner)
 305        {
 0306            selectorsByCategory[wearable.data.category].SetWearableLoadingSpinner(wearable.id, false);
 0307            collectiblesItemSelector.SetWearableLoadingSpinner(wearable.id, false);
 308        }
 309
 0310        wearablesWithLoadingSpinner.Clear();
 0311    }
 312
 313    public void SelectHairColor(Color hairColor)
 314    {
 108315        hairColorPickerComponent.SetColorSelector(hairColor);
 108316        hairColorPickerComponent.UpdateSliderValues(hairColor);
 108317        eyeBrowsColorPickerComponent.SetColorSelector(hairColor);
 108318        eyeBrowsColorPickerComponent.UpdateSliderValues(hairColor);
 108319        facialHairColorPickerComponent.SetColorSelector(hairColor);
 108320        facialHairColorPickerComponent.UpdateSliderValues(hairColor);
 108321    }
 322
 323    public Color GetRandomColor()
 324    {
 2325        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    {
 107330        skinColorSelector.Select(skinColor);
 107331    }
 332
 333    public void SelectEyeColor(Color eyesColor)
 334    {
 108335        eyeColorPickerComponent.SetColorSelector(eyesColor);
 108336        eyeColorPickerComponent.UpdateSliderValues(eyesColor);
 108337    }
 338
 339    public void SetColors(List<Color> skinColors, List<Color> hairColors, List<Color> eyeColors)
 340    {
 48341        skinColorSelector.Populate(skinColors);
 48342        eyeColorPickerComponent.SetColorList(eyeColors);
 48343        hairColorPickerComponent.SetColorList(hairColors);
 48344        eyeBrowsColorPickerComponent.SetColorList(hairColors);
 48345        facialHairColorPickerComponent.SetColorList(hairColors);
 48346    }
 347
 348    public void UnselectAllWearables()
 349    {
 3744350        for (int i = 0; i < wearableGridPairs.Length; i++)
 351        {
 1768352            if (wearableGridPairs[i].categoryFilter != WearableLiterals.Categories.BODY_SHAPE)
 353            {
 1664354                wearableGridPairs[i].selector.UnselectAll();
 355            }
 356        }
 357
 104358        collectiblesItemSelector.UnselectAll();
 104359    }
 360
 361    public void UpdateAvatarPreview(AvatarModel avatarModel, bool skipAudio)
 362    {
 125363        if (avatarModel?.wearables == null)
 0364            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
 125370        isAvatarDirty = true;
 125371        avatarModelToUpdate = avatarModel;
 125372        updateAvatarShouldSkipAudio = skipAudio;
 373
 125374        doneButton.interactable = false;
 125375        loadingSpinnerGameObject.SetActive(true);
 125376    }
 377
 378    public void AddWearable(WearableItem wearableItem, int amount,
 379        Func<WearableItem, bool> hideOtherWearablesToastStrategy,
 380        Func<WearableItem, bool> replaceOtherWearablesToastStrategy)
 381    {
 4221382        if (wearableItem == null)
 0383            return;
 384
 4221385        if (!selectorsByCategory.ContainsKey(wearableItem.data.category))
 386        {
 0387            Debug.LogError($"Category couldn't find selector for category: {wearableItem.data.category} ");
 0388            return;
 389        }
 390
 4221391        string collectionName = GetWearableCollectionName(wearableItem);
 392
 4221393        selectorsByCategory[wearableItem.data.category].AddWearable(
 394            wearableItem,
 395            collectionName,
 396            amount,
 397            hideOtherWearablesToastStrategy,
 398            replaceOtherWearablesToastStrategy);
 399
 4221400        if (wearableItem.IsCollectible() || wearableItem.IsFromThirdPartyCollection)
 401        {
 21402            collectiblesItemSelector.AddWearable(
 403                wearableItem,
 404                collectionName,
 405                amount,
 406                hideOtherWearablesToastStrategy,
 407                replaceOtherWearablesToastStrategy);
 408        }
 4221409    }
 410
 411    public void RefreshSelectorsSize()
 412    {
 162413        using (var iterator = selectorsByCategory.GetEnumerator())
 414        {
 2916415            while (iterator.MoveNext())
 416            {
 2754417                iterator.Current.Value.UpdateSelectorLayout();
 418            }
 162419        }
 420
 162421        collectiblesItemSelector.UpdateSelectorLayout();
 162422    }
 423
 424    private string GetWearableCollectionName(WearableItem wearableItem)
 425    {
 4221426        string collectionName = string.Empty;
 427
 4221428        if (wearableItem.IsFromThirdPartyCollection)
 429        {
 0430            loadedCollectionModels.TryGetValue(wearableItem.ThirdPartyCollectionId, out ToggleComponentModel collectionM
 431
 0432            if (collectionModel != null)
 0433                collectionName = collectionModel.text;
 434        }
 435
 4221436        return collectionName;
 437    }
 438
 439    public void RemoveWearable(WearableItem wearableItem)
 440    {
 0441        if (wearableItem == null)
 0442            return;
 443
 0444        if (!selectorsByCategory.ContainsKey(wearableItem.data.category))
 445        {
 0446            Debug.LogError($"Category couldn't find selector for category: {wearableItem.data.category} ");
 0447            return;
 448        }
 449
 0450        selectorsByCategory[wearableItem.data.category].RemoveWearable(wearableItem.id);
 0451        if (wearableItem.IsCollectible() || wearableItem.IsFromThirdPartyCollection)
 0452            collectiblesItemSelector.RemoveWearable(wearableItem.id);
 0453    }
 454
 455    public void RemoveAllWearables()
 456    {
 151457        using (var enumerator = selectorsByCategory.GetEnumerator())
 458        {
 2718459            while (enumerator.MoveNext())
 460            {
 2567461                enumerator.Current.Value.RemoveAllWearables();
 462            }
 151463        }
 464
 151465        collectiblesItemSelector.RemoveAllWearables();
 151466    }
 467
 468    private void OnRandomizeButton()
 469    {
 0470        OnRandomize?.Invoke();
 0471        controller.RandomizeWearables();
 0472        randomizeAnimator?.SetBool(RANDOMIZE_ANIMATOR_LOADING_BOOL, true);
 0473    }
 474
 475    private void OnDoneButton()
 476    {
 0477        doneButton.interactable = false;
 0478        CoroutineStarter.Start(TakeSnapshotsAfterStopPreviewAnimation());
 0479        eyeColorPickerComponent.SetActive(false);
 0480        hairColorPickerComponent.SetActive(false);
 0481        facialHairColorPickerComponent.SetActive(false);
 0482        eyeBrowsColorPickerComponent.SetActive(false);
 0483    }
 484
 485    private IEnumerator TakeSnapshotsAfterStopPreviewAnimation()
 486    {
 487        // We need to stop the current preview animation in order to take a correct snapshot
 0488        ResetPreviewEmote();
 0489        yield return new WaitForSeconds(TIME_TO_RESET_PREVIEW_ANIMATION);
 0490        characterPreviewController.TakeSnapshots(OnSnapshotsReady, OnSnapshotsFailed);
 0491    }
 492
 493    private void OnSnapshotsReady(Texture2D face256, Texture2D body)
 494    {
 0495        doneButton.interactable = true;
 0496        controller.SaveAvatar(face256, body);
 0497    }
 498
 0499    private void OnSnapshotsFailed() { doneButton.interactable = true; }
 500
 501    public void SetVisibility(bool visible)
 502    {
 92503        characterPreviewController.camera.enabled = visible;
 92504        avatarEditorCanvas.enabled = visible;
 92505        avatarEditorCanvasGroup.blocksRaycasts = visible;
 506
 92507        if (visible && !isOpen)
 508        {
 43509            OnSetVisibility?.Invoke(visible);
 0510        }
 49511        else if (!visible && isOpen)
 512        {
 1513            collectionsDropdown.Close();
 1514            noItemInCollectionWarning.Dismiss(true);
 1515            OnSetVisibility?.Invoke(visible);
 516        }
 517
 92518        isOpen = visible;
 92519    }
 520
 521    public void CleanUp()
 522    {
 48523        loadingSpinnerGameObject = null;
 48524        randomizeAnimator = null;
 48525        if (wearableGridPairs != null)
 526        {
 48527            int nPairs = wearableGridPairs.Length;
 1728528            for (int i = 0; i < nPairs; i++)
 529            {
 816530                var itemSelector = wearableGridPairs[i].selector;
 816531                if (itemSelector != null)
 532                {
 816533                    itemSelector.OnItemClicked -= controller.WearableClicked;
 816534                    itemSelector.OnSellClicked -= controller.SellCollectible;
 535                }
 536            }
 537        }
 538
 48539        if (collectiblesItemSelector != null)
 540        {
 48541            collectiblesItemSelector.OnItemClicked -= controller.WearableClicked;
 48542            collectiblesItemSelector.OnSellClicked -= controller.SellCollectible;
 543        }
 544
 48545        if (skinColorSelector != null)
 48546            skinColorSelector.OnColorSelectorChange -= controller.SkinColorClicked;
 48547        if (eyeColorPickerComponent != null)
 48548            eyeColorPickerComponent.OnColorChanged -= controller.EyesColorClicked;
 48549        if (hairColorPickerComponent != null)
 48550            hairColorPickerComponent.OnColorChanged -= controller.HairColorClicked;
 48551        if (facialHairColorPickerComponent != null)
 48552            facialHairColorPickerComponent.OnColorChanged -= controller.HairColorClicked;
 48553        if (eyeBrowsColorPickerComponent != null)
 48554            eyeBrowsColorPickerComponent.OnColorChanged -= controller.HairColorClicked;
 555
 48556        if (this != null)
 48557            Destroy(gameObject);
 558
 48559        if (characterPreviewController != null)
 560        {
 48561            Destroy(characterPreviewController.gameObject);
 48562            characterPreviewController = null;
 563        }
 564
 48565        collectionsDropdown.OnOptionSelectionChanged -= controller.ToggleThirdPartyCollection;
 48566        collectionsDropdown.Dispose();
 567
 48568        sectionSelector.GetSection(AVATAR_SECTION_INDEX).onSelect.RemoveAllListeners();
 48569        sectionSelector.GetSection(EMOTES_SECTION_INDEX).onSelect.RemoveAllListeners();
 570
 48571        clickBlocker.OnClicked -= ClickBlockerClicked;
 48572    }
 573
 574    public void SetAsFullScreenMenuMode(Transform parentTransform)
 575    {
 48576        if (parentTransform == null)
 48577            return;
 578
 0579        transform.SetParent(parentTransform);
 0580        transform.localScale = Vector3.one;
 581
 0582        RectTransform rectTransform = transform as RectTransform;
 0583        rectTransform.anchorMin = Vector2.zero;
 0584        rectTransform.anchorMax = Vector2.one;
 0585        rectTransform.pivot = new Vector2(0.5f, 0.5f);
 0586        rectTransform.localPosition = Vector2.zero;
 0587        rectTransform.offsetMax = Vector2.zero;
 0588        rectTransform.offsetMin = Vector2.zero;
 0589    }
 590
 591    public void OnPointerDown(PointerEventData eventData)
 592    {
 0593        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        {
 0598            eyeColorPickerComponent.SetActive(false);
 0599            hairColorPickerComponent.SetActive(false);
 0600            eyeBrowsColorPickerComponent.SetActive(false);
 0601            facialHairColorPickerComponent.SetActive(false);
 602        }
 0603    }
 604
 605    public void LoadCollectionsDropdown(Collection[] collections)
 606    {
 0607        List<ToggleComponentModel> collectionsToAdd = new List<ToggleComponentModel>();
 0608        foreach (var collection in collections)
 609        {
 0610            ToggleComponentModel newCollectionModel = new ToggleComponentModel
 611            {
 612                id = collection.urn,
 613                text = collection.name,
 614                isOn = false,
 615                isTextActive = true
 616            };
 617
 0618            collectionsToAdd.Add(newCollectionModel);
 0619            loadedCollectionModels.Add(collection.urn, newCollectionModel);
 620        }
 621
 0622        collectionsDropdown.SetOptions(collectionsToAdd);
 0623    }
 624
 625    public void BlockCollectionsDropdown(bool isBlocked)
 626    {
 1627        collectionsDropdown.SetLoadingActive(isBlocked);
 1628    }
 629
 630    public void ShowSkinPopulatedList(bool show)
 631    {
 0632        skinsPopulatedListContainer.SetActive(show);
 0633        skinsEmptyListContainer.SetActive(!show);
 0634        skinsConnectWalletButtonContainer.SetActive(show);
 0635    }
 636
 637    public void SetThirdPartyCollectionsVisibility(bool visible) =>
 48638        collectionsDropdown.gameObject.SetActive(visible);
 639
 640    internal void ConfigureSectionSelector()
 641    {
 48642        sectionTitle.text = AVATAR_SECTION_TITLE;
 643
 48644        sectionSelector.GetSection(AVATAR_SECTION_INDEX).onSelect.AddListener((isSelected) =>
 645        {
 0646            avatarSection.SetActive(isSelected);
 0647            randomizeButton.gameObject.SetActive(true);
 648
 0649            if (isSelected)
 650            {
 0651                sectionTitle.text = AVATAR_SECTION_TITLE;
 0652                ResetPreviewEmote();
 653            }
 654
 0655            emotesCustomizationDataStore.isEmotesCustomizationSelected.Set(false, notifyEvent: false);
 0656        });
 48657        sectionSelector.GetSection(EMOTES_SECTION_INDEX).onSelect.AddListener((isSelected) =>
 658        {
 0659            emotesSection.SetActive(isSelected);
 0660            randomizeButton.gameObject.SetActive(false);
 661
 0662            if (isSelected)
 663            {
 0664                sectionTitle.text = EMOTES_SECTION_TITLE;
 0665                ResetPreviewEmote();
 666            }
 667
 0668            characterPreviewController.SetFocus(CharacterPreviewController.CameraFocus.DefaultEditing);
 0669            emotesCustomizationDataStore.isEmotesCustomizationSelected.Set(true, notifyEvent: false);
 0670        });
 48671    }
 672
 673    internal void SetSectionActive(int sectionIndex, bool isActive)
 674    {
 96675        sectionSelector.GetSection(sectionIndex).SetActive(isActive);
 288676        sectionSelector.gameObject.SetActive(sectionSelector.GetAllSections().Count(x => x.IsActive()) > 1);
 96677    }
 678
 2679    public void PlayPreviewEmote(string emoteId) { characterPreviewController.PlayEmote(emoteId, (long)Time.realtimeSinc
 680
 2681    public void ResetPreviewEmote() { PlayPreviewEmote(RESET_PREVIEW_ANIMATION); }
 682
 683    public void ToggleThirdPartyCollection(string collectionId, bool isOn)
 684    {
 0685        List<IToggleComponentView> allCollectionOptions = collectionsDropdown.GetAllOptions();
 0686        foreach (IToggleComponentView collectionOption in allCollectionOptions)
 687        {
 0688            if (collectionOption.id == collectionId)
 0689                collectionOption.isOn = isOn;
 690        }
 0691    }
 692    public void ShowNoItemOfWearableCollectionWarning()
 693    {
 0694        noItemInCollectionWarning.Dismiss(true);
 0695        noItemInCollectionWarning.Show(new DCL.NotificationModel.Model
 696        {
 697            timer = 5f,
 698        });
 0699    }
 700
 701    private void ClickBlockerClicked()
 702    {
 0703        noItemInCollectionWarning.Dismiss(false);
 0704    }
 705
 706    private void UpdateAvatarModelWhenNeeded()
 707    {
 1708        if (isAvatarDirty)
 709        {
 0710            characterPreviewController.UpdateModel(avatarModelToUpdate,
 711                () =>
 712                {
 0713                    if (doneButton != null)
 0714                        doneButton.interactable = true;
 715
 0716                    loadingSpinnerGameObject?.SetActive(false);
 717
 0718                    if (!updateAvatarShouldSkipAudio)
 0719                        OnAvatarAppear?.Invoke(avatarModelToUpdate);
 720
 0721                    ClearWearablesLoadingSpinner();
 0722                    randomizeAnimator?.SetBool(RANDOMIZE_ANIMATOR_LOADING_BOOL, false);
 0723                });
 724
 0725            isAvatarDirty = false;
 726        }
 1727    }
 728}

Methods/Properties

AvatarEditorHUDView()
isOpen()
isOpen(System.Boolean)
emotesCustomizationDataStore()
Initialize()
AvatarEditorHUDView()
Awake()
Initialize(AvatarEditorHUDController)
Update()
SetIsWeb3(System.Boolean)
InitializeNavigationEvents(System.Boolean)
InitializeNavigationInfo(AvatarEditorHUDView/AvatarEditorNavigationInfo, System.Boolean)
InitializeNavigationInfo(AvatarEditorHUDView/AvatarEditorNavigationInfo)
InitializeWearableChangeEvents()
Create(AvatarEditorHUDController)
UpdateSelectedBody(WearableItem)
EquipWearable(WearableItem)
UnequipWearable(WearableItem)
SetWearableLoadingSpinner(WearableItem, System.Boolean)
ClearWearablesLoadingSpinner()
SelectHairColor(UnityEngine.Color)
GetRandomColor()
SelectSkinColor(UnityEngine.Color)
SelectEyeColor(UnityEngine.Color)
SetColors(System.Collections.Generic.List[Color], System.Collections.Generic.List[Color], System.Collections.Generic.List[Color])
UnselectAllWearables()
UpdateAvatarPreview(AvatarModel, System.Boolean)
AddWearable(WearableItem, System.Int32, System.Func[WearableItem,Boolean], System.Func[WearableItem,Boolean])
RefreshSelectorsSize()
GetWearableCollectionName(WearableItem)
RemoveWearable(WearableItem)
RemoveAllWearables()
OnRandomizeButton()
OnDoneButton()
TakeSnapshotsAfterStopPreviewAnimation()
OnSnapshotsReady(UnityEngine.Texture2D, UnityEngine.Texture2D)
OnSnapshotsFailed()
SetVisibility(System.Boolean)
CleanUp()
SetAsFullScreenMenuMode(UnityEngine.Transform)
OnPointerDown(UnityEngine.EventSystems.PointerEventData)
LoadCollectionsDropdown(WearableCollectionsAPIData/Collection[])
BlockCollectionsDropdown(System.Boolean)
ShowSkinPopulatedList(System.Boolean)
SetThirdPartyCollectionsVisibility(System.Boolean)
ConfigureSectionSelector()
SetSectionActive(System.Int32, System.Boolean)
PlayPreviewEmote(System.String)
ResetPreviewEmote()
ToggleThirdPartyCollection(System.String, System.Boolean)
ShowNoItemOfWearableCollectionWarning()
ClickBlockerClicked()
UpdateAvatarModelWhenNeeded()