< Summary

Class:AvatarEditorHUDController
Assembly:AvatarEditorHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/AvatarEditorHUDController.cs
Covered lines:271
Uncovered lines:80
Coverable lines:351
Total lines:704
Line coverage:77.2% (271 of 351)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarEditorHUDController()0%110100%
AvatarEditorHUDController()0%110100%
Initialize(...)0%110100%
SetCatalog(...)0%2.062075%
LoadUserProfile(...)0%110100%
LoadOwnedWereables(...)0%550100%
QueryNftCollections(...)0%7.464040%
RetryLoadOwnedWearables()0%2100%
PlayerRendererLoaded(...)0%6.136084.62%
LoadUserProfile(...)0%11.4211084.85%
EnsureWearablesCategoriesNotEmpty()0%7.027092.86%
WearableClicked(...)0%7.197084.21%
HairColorClicked(...)0%110100%
SkinColorClicked(...)0%110100%
EyesColorClicked(...)0%110100%
UpdateAvatarPreview()0%220100%
EquipHairColor(...)0%220100%
EquipEyesColor(...)0%220100%
EquipSkinColor(...)0%220100%
EquipBodyShape(...)0%6.046089.47%
EquipWearable(...)0%5.035088.89%
UnequipWearable(...)0%220100%
UnequipAllWearables()0%220100%
ProcessCatalog(...)0%330100%
AddWearable(...)0%440100%
RemoveWearable(...)0%20400%
RandomizeWearables()0%44093.75%
GetWearablesReplacedBy(...)0%7.017093.33%
SetVisibility(...)0%110100%
OnAvatarEditorVisibleChanged(...)0%110100%
SetVisibility_Internal(...)0%16.0415083.33%
Dispose()0%110100%
CleanUp()0%220100%
SetConfiguration(...)0%2100%
SaveAvatar(...)0%2.012087.5%
DiscardAndClose()0%12300%
GoToMarketplace()0%6200%
SellCollectible(...)0%12300%
ToggleVisibility()0%2100%
ConfigureBackpackInFullscreenMenuChanged(...)0%110100%
ExploreV2IsOpenChanged(...)0%12300%

File(s)

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

#LineLine coverage
 1using DCL;
 2using DCL.Helpers;
 3using DCL.Interface;
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using UnityEngine;
 8using UnityEngine.Rendering;
 9using UnityEngine.Rendering.Universal;
 10using Categories = WearableLiterals.Categories;
 11
 12public class AvatarEditorHUDController : IHUD
 13{
 14    private const int LOADING_OWNED_WEARABLES_RETRIES = 3;
 15    private const string LOADING_OWNED_WEARABLES_ERROR_MESSAGE = "There was a problem loading your wearables";
 16    private const string URL_MARKET_PLACE = "https://market.decentraland.org/browse?section=wearables";
 17    private const string URL_GET_A_WALLET = "https://docs.decentraland.org/get-a-wallet";
 18    private const string URL_SELL_COLLECTIBLE_GENERIC = "https://market.decentraland.org/account";
 19    private const string URL_SELL_SPECIFIC_COLLECTIBLE = "https://market.decentraland.org/contracts/{collectionId}/token
 20
 121    protected static readonly string[] categoriesThatMustHaveSelection = { Categories.BODY_SHAPE, Categories.UPPER_BODY,
 122    protected static readonly string[] categoriesToRandomize = { Categories.HAIR, Categories.EYES, Categories.EYEBROWS, 
 23
 24    [NonSerialized]
 25    public bool bypassUpdateAvatarPreview = false;
 26
 27    private UserProfile userProfile;
 28    private BaseDictionary<string, WearableItem> catalog;
 10229    bool renderingEnabled => CommonScriptableObjects.rendererState.Get();
 9930    bool isPlayerRendererLoaded => DataStore.i.common.isPlayerRendererLoaded.Get();
 17531    BaseVariable<bool> avatarEditorVisible => DataStore.i.HUDs.avatarEditorVisible;
 13332    BaseVariable<Transform> configureBackpackInFullscreenMenu => DataStore.i.exploreV2.configureBackpackInFullscreenMenu
 8733    BaseVariable<bool> exploreV2IsOpen => DataStore.i.exploreV2.isOpen;
 4634    private readonly Dictionary<string, List<WearableItem>> wearablesByCategory = new Dictionary<string, List<WearableIt
 4635    protected readonly AvatarEditorHUDModel model = new AvatarEditorHUDModel();
 36
 37    private ColorList skinColorList;
 38    private ColorList eyeColorList;
 39    private ColorList hairColorList;
 40    private bool prevMouseLockState = false;
 4641    private int ownedWearablesRemainingRequests = LOADING_OWNED_WEARABLES_RETRIES;
 42    private bool ownedWearablesAlreadyLoaded = false;
 4643    private List<Nft> ownedNftCollectionsL1 = new List<Nft>();
 4644    private List<Nft> ownedNftCollectionsL2 = new List<Nft>();
 45    private bool avatarIsDirty = false;
 46    private float lastTimeOwnedWearablesChecked = 0;
 47
 48    public AvatarEditorHUDView view;
 49
 50    public event Action OnOpen;
 51    public event Action OnClose;
 52
 9253    public AvatarEditorHUDController() { }
 54
 55    public void Initialize(UserProfile userProfile, BaseDictionary<string, WearableItem> catalog, bool bypassUpdateAvata
 56    {
 4657        this.userProfile = userProfile;
 4658        this.bypassUpdateAvatarPreview = bypassUpdateAvatarPreview;
 59
 4660        view = AvatarEditorHUDView.Create(this);
 61
 4662        avatarEditorVisible.OnChange += OnAvatarEditorVisibleChanged;
 4663        OnAvatarEditorVisibleChanged(avatarEditorVisible.Get(), false);
 4664        view.OnCloseActionTriggered += DiscardAndClose;
 65
 4666        configureBackpackInFullscreenMenu.OnChange += ConfigureBackpackInFullscreenMenuChanged;
 4667        ConfigureBackpackInFullscreenMenuChanged(configureBackpackInFullscreenMenu.Get(), null);
 68
 4669        exploreV2IsOpen.OnChange += ExploreV2IsOpenChanged;
 70
 4671        skinColorList = Resources.Load<ColorList>("SkinTone");
 4672        hairColorList = Resources.Load<ColorList>("HairColor");
 4673        eyeColorList = Resources.Load<ColorList>("EyeColor");
 4674        view.SetColors(skinColorList.colors, hairColorList.colors, eyeColorList.colors);
 75
 4676        SetCatalog(catalog);
 77
 4678        LoadUserProfile(userProfile, true);
 4679        this.userProfile.OnUpdate += LoadUserProfile;
 80
 4681        DataStore.i.HUDs.isAvatarEditorInitialized.Set(true);
 4682    }
 83
 84    public void SetCatalog(BaseDictionary<string, WearableItem> catalog)
 85    {
 4686        if (this.catalog != null)
 87        {
 088            this.catalog.OnAdded -= AddWearable;
 089            this.catalog.OnRemoved -= RemoveWearable;
 90        }
 91
 4692        this.catalog = catalog;
 93
 4694        ProcessCatalog(this.catalog);
 4695        this.catalog.OnAdded += AddWearable;
 4696        this.catalog.OnRemoved += RemoveWearable;
 4697    }
 98
 99    private void LoadUserProfile(UserProfile userProfile)
 100    {
 42101        LoadUserProfile(userProfile, false);
 42102        QueryNftCollections(userProfile.userId);
 42103    }
 104
 105    private void LoadOwnedWereables(UserProfile userProfile)
 106    {
 107        // If there is more than 1 minute that we have checked the owned wearables, we try it again
 108        // This is done in order to retrieved the wearables after you has claimed them
 41109        if ((Time.realtimeSinceStartup < lastTimeOwnedWearablesChecked + 60 &&
 110             (ownedWearablesAlreadyLoaded ||
 111              ownedWearablesRemainingRequests <= 0)) ||
 112            string.IsNullOrEmpty(userProfile.userId))
 40113            return;
 114
 1115        view.ShowCollectiblesLoadingSpinner(true);
 1116        view.ShowCollectiblesLoadingRetry(false);
 1117        lastTimeOwnedWearablesChecked = Time.realtimeSinceStartup;
 118
 1119        CatalogController.RequestOwnedWearables(userProfile.userId)
 120                         .Then((ownedWearables) =>
 121                         {
 0122                             ownedWearablesAlreadyLoaded = true;
 0123                             this.userProfile.SetInventory(ownedWearables.Select(x => x.id).ToArray());
 0124                             LoadUserProfile(userProfile, true);
 0125                             view.ShowCollectiblesLoadingSpinner(false);
 0126                         })
 127                         .Catch((error) =>
 128                         {
 0129                             ownedWearablesRemainingRequests--;
 0130                             if (ownedWearablesRemainingRequests > 0)
 131                             {
 0132                                 Debug.LogWarning("Retrying owned wereables loading...");
 0133                                 LoadOwnedWereables(userProfile);
 0134                             }
 135                             else
 136                             {
 0137                                 NotificationsController.i.ShowNotification(new DCL.NotificationModel.Model
 138                                 {
 139                                     message = LOADING_OWNED_WEARABLES_ERROR_MESSAGE,
 140                                     type = DCL.NotificationModel.Type.GENERIC,
 141                                     timer = 10f,
 142                                     destroyOnFinish = true
 143                                 });
 144
 0145                                 view.ShowCollectiblesLoadingSpinner(false);
 0146                                 view.ShowCollectiblesLoadingRetry(true);
 0147                                 Debug.LogError(error);
 148                             }
 0149                         });
 1150    }
 151
 152    private void QueryNftCollections(string userId)
 153    {
 42154        if (string.IsNullOrEmpty(userId))
 42155            return;
 156
 0157        DCL.Environment.i.platform.serviceProviders.theGraph.QueryNftCollections(userProfile.userId, NftCollectionsLayer
 0158           .Then((nfts) => ownedNftCollectionsL1 = nfts)
 0159           .Catch((error) => Debug.LogError(error));
 160
 0161        DCL.Environment.i.platform.serviceProviders.theGraph.QueryNftCollections(userProfile.userId, NftCollectionsLayer
 0162           .Then((nfts) => ownedNftCollectionsL2 = nfts)
 0163           .Catch((error) => Debug.LogError(error));
 0164    }
 165
 166    public void RetryLoadOwnedWearables()
 167    {
 0168        ownedWearablesRemainingRequests = LOADING_OWNED_WEARABLES_RETRIES;
 0169        LoadOwnedWereables(userProfile);
 0170    }
 171
 172    private void PlayerRendererLoaded(bool current, bool previous)
 173    {
 14174        if (!current)
 0175            return;
 176
 14177        if (!ownedWearablesAlreadyLoaded)
 178        {
 14179            List<string> equippedOwnedWearables = new List<string>();
 58180            for (int i = 0; i < userProfile.avatar.wearables.Count; i++)
 181            {
 15182                if (catalog.TryGetValue(userProfile.avatar.wearables[i], out WearableItem wearable) &&
 183                    !wearable.data.tags.Contains("base-wearable"))
 184                {
 0185                    equippedOwnedWearables.Add(userProfile.avatar.wearables[i]);
 186                }
 187            }
 188
 14189            userProfile.SetInventory(equippedOwnedWearables.ToArray());
 190        }
 191
 14192        LoadUserProfile(userProfile, true);
 14193        DataStore.i.common.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded;
 14194    }
 195
 196    public void LoadUserProfile(UserProfile userProfile, bool forceLoading)
 197    {
 102198        bool avatarEditorNotVisible = renderingEnabled && !view.isOpen;
 102199        bool isPlaying = !Application.isBatchMode;
 200
 102201        if (!forceLoading)
 202        {
 42203            if (isPlaying && avatarEditorNotVisible)
 0204                return;
 205        }
 206
 102207        if (userProfile == null)
 0208            return;
 209
 102210        if (userProfile.avatar == null || string.IsNullOrEmpty(userProfile.avatar.bodyShape))
 3211            return;
 212
 99213        CatalogController.wearableCatalog.TryGetValue(userProfile.avatar.bodyShape, out var bodyShape);
 214
 99215        if (bodyShape == null)
 216        {
 0217            return;
 218        }
 219
 99220        view.SetIsWeb3(userProfile.hasConnectedWeb3);
 221
 99222        ProcessCatalog(this.catalog);
 99223        EquipBodyShape(bodyShape);
 99224        EquipSkinColor(userProfile.avatar.skinColor);
 99225        EquipHairColor(userProfile.avatar.hairColor);
 99226        EquipEyesColor(userProfile.avatar.eyeColor);
 227
 99228        model.wearables.Clear();
 99229        view.UnselectAllWearables();
 230
 99231        int wearablesCount = userProfile.avatar.wearables.Count;
 232
 99233        if (isPlayerRendererLoaded)
 234        {
 158235            for (var i = 0; i < wearablesCount; i++)
 236            {
 46237                CatalogController.wearableCatalog.TryGetValue(userProfile.avatar.wearables[i], out var wearable);
 46238                if (wearable == null)
 239                {
 0240                    Debug.LogError($"Couldn't find wearable with ID {userProfile.avatar.wearables[i]}");
 0241                    continue;
 242                }
 243
 46244                EquipWearable(wearable);
 245            }
 246        }
 247
 99248        EnsureWearablesCategoriesNotEmpty();
 249
 99250        UpdateAvatarPreview();
 99251    }
 252
 253    private void EnsureWearablesCategoriesNotEmpty()
 254    {
 145255        var categoriesInUse = model.wearables.Select(x => x.data.category).ToArray();
 1584256        for (var i = 0; i < categoriesThatMustHaveSelection.Length; i++)
 257        {
 693258            var category = categoriesThatMustHaveSelection[i];
 693259            if (category != Categories.BODY_SHAPE && !(categoriesInUse.Contains(category)))
 260            {
 261                WearableItem wearable;
 558262                var defaultItemId = WearableLiterals.DefaultWearables.GetDefaultWearable(model.bodyShape.id, category);
 558263                if (defaultItemId != null)
 264                {
 558265                    CatalogController.wearableCatalog.TryGetValue(defaultItemId, out wearable);
 558266                }
 267                else
 268                {
 0269                    wearable = wearablesByCategory[category].FirstOrDefault(x => x.SupportsBodyShape(model.bodyShape.id)
 270                }
 271
 558272                if (wearable != null)
 273                {
 558274                    EquipWearable(wearable);
 275                }
 276            }
 277        }
 99278    }
 279
 280    public void WearableClicked(string wearableId)
 281    {
 20282        CatalogController.wearableCatalog.TryGetValue(wearableId, out var wearable);
 20283        if (wearable == null)
 3284            return;
 285
 17286        if (wearable.data.category == Categories.BODY_SHAPE)
 287        {
 3288            if (wearable.id == model.bodyShape.id)
 0289                return;
 3290            EquipBodyShape(wearable);
 3291        }
 292        else
 293        {
 14294            if (model.wearables.Contains(wearable))
 295            {
 2296                if (!categoriesThatMustHaveSelection.Contains(wearable.data.category))
 297                {
 0298                    UnequipWearable(wearable);
 0299                }
 300                else
 301                {
 2302                    return;
 303                }
 304            }
 305            else
 306            {
 91307                var sameCategoryEquipped = model.wearables.FirstOrDefault(x => x.data.category == wearable.data.category
 12308                if (sameCategoryEquipped != null)
 309                {
 2310                    UnequipWearable(sameCategoryEquipped);
 311                }
 312
 12313                EquipWearable(wearable);
 314            }
 315        }
 316
 15317        UpdateAvatarPreview();
 15318    }
 319
 320    public void HairColorClicked(Color color)
 321    {
 2322        EquipHairColor(color);
 2323        view.SelectHairColor(model.hairColor);
 2324        UpdateAvatarPreview();
 2325    }
 326
 327    public void SkinColorClicked(Color color)
 328    {
 2329        EquipSkinColor(color);
 2330        view.SelectSkinColor(model.skinColor);
 2331        UpdateAvatarPreview();
 2332    }
 333
 334    public void EyesColorClicked(Color color)
 335    {
 2336        EquipEyesColor(color);
 2337        view.SelectEyeColor(model.eyesColor);
 2338        UpdateAvatarPreview();
 2339    }
 340
 341    protected virtual void UpdateAvatarPreview()
 342    {
 121343        if (!bypassUpdateAvatarPreview)
 121344            view.UpdateAvatarPreview(model.ToAvatarModel());
 121345    }
 346
 347    private void EquipHairColor(Color color)
 348    {
 102349        var colorToSet = color;
 1042350        if (!hairColorList.colors.Any(x => x.AproxComparison(colorToSet)))
 351        {
 92352            colorToSet = hairColorList.colors[hairColorList.defaultColor];
 353        }
 354
 102355        model.hairColor = colorToSet;
 102356        view.SelectHairColor(model.hairColor);
 102357    }
 358
 359    private void EquipEyesColor(Color color)
 360    {
 102361        var colorToSet = color;
 1041362        if (!eyeColorList.colors.Any(x => x.AproxComparison(color)))
 363        {
 92364            colorToSet = eyeColorList.colors[eyeColorList.defaultColor];
 365        }
 366
 102367        model.eyesColor = colorToSet;
 102368        view.SelectEyeColor(model.eyesColor);
 102369    }
 370
 371    private void EquipSkinColor(Color color)
 372    {
 101373        var colorToSet = color;
 1033374        if (!skinColorList.colors.Any(x => x.AproxComparison(colorToSet)))
 375        {
 92376            colorToSet = skinColorList.colors[skinColorList.defaultColor];
 377        }
 378
 101379        model.skinColor = colorToSet;
 101380        view.SelectSkinColor(model.skinColor);
 101381    }
 382
 383    private void EquipBodyShape(WearableItem bodyShape)
 384    {
 102385        if (bodyShape.data.category != Categories.BODY_SHAPE)
 386        {
 0387            Debug.LogError($"Item ({bodyShape.id} is not a body shape");
 0388            return;
 389        }
 390
 102391        if (model.bodyShape == bodyShape)
 52392            return;
 393
 50394        model.bodyShape = bodyShape;
 50395        view.UpdateSelectedBody(bodyShape);
 396
 50397        int wearablesCount = model.wearables.Count;
 140398        for (var i = wearablesCount - 1; i >= 0; i--)
 399        {
 20400            UnequipWearable(model.wearables[i]);
 401        }
 402
 50403        var defaultWearables = WearableLiterals.DefaultWearables.GetDefaultWearables(bodyShape.id);
 810404        for (var i = 0; i < defaultWearables.Length; i++)
 405        {
 355406            if (catalog.TryGetValue(defaultWearables[i], out var wearable))
 355407                EquipWearable(wearable);
 408        }
 50409    }
 410
 411    private void EquipWearable(WearableItem wearable)
 412    {
 978413        if (!wearablesByCategory.ContainsKey(wearable.data.category))
 0414            return;
 415
 978416        if (wearablesByCategory[wearable.data.category].Contains(wearable) && wearable.SupportsBodyShape(model.bodyShape
 417        {
 978418            var toReplace = GetWearablesReplacedBy(wearable);
 978419            toReplace.ForEach(UnequipWearable);
 978420            model.wearables.Add(wearable);
 978421            view.EquipWearable(wearable);
 978422            avatarIsDirty = true;
 423        }
 978424    }
 425
 426    private void UnequipWearable(WearableItem wearable)
 427    {
 24428        if (model.wearables.Contains(wearable))
 429        {
 24430            model.wearables.Remove(wearable);
 24431            view.UnequipWearable(wearable);
 24432            avatarIsDirty = true;
 433        }
 24434    }
 435
 436    public void UnequipAllWearables()
 437    {
 982438        foreach (var wearable in model.wearables)
 439        {
 419440            view.UnequipWearable(wearable);
 441        }
 442
 72443        model.wearables.Clear();
 72444    }
 445
 446    private void ProcessCatalog(BaseDictionary<string, WearableItem> catalog)
 447    {
 145448        wearablesByCategory.Clear();
 145449        view.RemoveAllWearables();
 145450        using (var iterator = catalog.Get().GetEnumerator())
 451        {
 5329452            while (iterator.MoveNext())
 453            {
 5184454                AddWearable(iterator.Current.Key, iterator.Current.Value);
 455            }
 145456        }
 145457    }
 458
 459    private void AddWearable(string id, WearableItem wearable)
 460    {
 5192461        if (!wearable.data.tags.Contains("base-wearable") && userProfile.GetItemAmount(id) == 0)
 462        {
 1142463            return;
 464        }
 465
 4050466        if (!wearablesByCategory.ContainsKey(wearable.data.category))
 467        {
 1584468            wearablesByCategory.Add(wearable.data.category, new List<WearableItem>());
 469        }
 470
 4050471        wearablesByCategory[wearable.data.category].Add(wearable);
 4050472        view.AddWearable(wearable, userProfile.GetItemAmount(id));
 4050473    }
 474
 475    private void RemoveWearable(string id, WearableItem wearable)
 476    {
 0477        if (wearablesByCategory.ContainsKey(wearable.data.category))
 478        {
 0479            if (wearablesByCategory[wearable.data.category].Remove(wearable))
 480            {
 0481                if (wearablesByCategory[wearable.data.category].Count == 0)
 482                {
 0483                    wearablesByCategory.Remove(wearable.data.category);
 484                }
 485            }
 486        }
 487
 0488        view.RemoveWearable(wearable);
 0489    }
 490
 491    public void RandomizeWearables()
 492    {
 1493        EquipHairColor(hairColorList.colors[UnityEngine.Random.Range(0, hairColorList.colors.Count)]);
 1494        EquipEyesColor(eyeColorList.colors[UnityEngine.Random.Range(0, eyeColorList.colors.Count)]);
 495
 1496        model.wearables.Clear();
 1497        view.UnselectAllWearables();
 1498        using (var iterator = wearablesByCategory.GetEnumerator())
 499        {
 12500            while (iterator.MoveNext())
 501            {
 11502                string category = iterator.Current.Key;
 11503                if (!categoriesToRandomize.Contains(category))
 504                {
 505                    continue;
 506                }
 507
 29508                var supportedWearables = iterator.Current.Value.Where(x => x.SupportsBodyShape(model.bodyShape.id)).ToAr
 7509                if (supportedWearables.Length == 0)
 510                {
 0511                    Debug.LogError($"Couldn't get any wearable for category {category} and bodyshape {model.bodyShape.id
 512                }
 513
 7514                var wearable = supportedWearables[UnityEngine.Random.Range(0, supportedWearables.Length - 1)];
 7515                EquipWearable(wearable);
 516            }
 1517        }
 518
 1519        UpdateAvatarPreview();
 1520    }
 521
 522    public List<WearableItem> GetWearablesReplacedBy(WearableItem wearableItem)
 523    {
 978524        List<WearableItem> wearablesToReplace = new List<WearableItem>();
 525
 978526        HashSet<string> categoriesToReplace = new HashSet<string>(wearableItem.GetReplacesList(model.bodyShape.id) ?? ne
 527
 978528        int wearableCount = model.wearables.Count;
 7420529        for (int i = 0; i < wearableCount; i++)
 530        {
 2732531            var wearable = model.wearables[i];
 2732532            if (wearable == null)
 533                continue;
 534
 2732535            if (categoriesToReplace.Contains(wearable.data.category))
 536            {
 2537                wearablesToReplace.Add(wearable);
 2538            }
 539            else
 540            {
 541                //For retrocompatibility's sake we check current wearables against new one (compatibility matrix is symm
 2730542                HashSet<string> replacesList = new HashSet<string>(wearable.GetReplacesList(model.bodyShape.id) ?? new s
 2730543                if (replacesList.Contains(wearableItem.data.category))
 544                {
 0545                    wearablesToReplace.Add(wearable);
 546                }
 547            }
 548        }
 549
 978550        return wearablesToReplace;
 551    }
 552
 46553    private float prevRenderScale = 1.0f;
 554    private Camera mainCamera;
 555
 84556    public void SetVisibility(bool visible) { avatarEditorVisible.Set(visible); }
 557
 176558    private void OnAvatarEditorVisibleChanged(bool current, bool previous) { SetVisibility_Internal(current); }
 559
 560    public void SetVisibility_Internal(bool visible)
 561    {
 88562        var currentRenderProfile = DCL.RenderProfileManifest.i.currentProfile;
 563
 88564        if (!visible && view.isOpen)
 565        {
 1566            if (DataStore.i.common.isSignUpFlow.Get())
 0567                DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(1f);
 568
 1569            DCL.Environment.i.messaging.manager.paused = false;
 1570            DataStore.i.skyboxConfig.avatarMatProfile.Set(AvatarMaterialProfile.InWorld);
 1571            currentRenderProfile.avatarProfile.Apply();
 1572            if (prevMouseLockState && DataStore.i.common.isSignUpFlow.Get())
 573            {
 0574                Utils.LockCursor();
 575            }
 576
 577            // NOTE(Brian): SSAO doesn't work correctly with the offseted avatar preview if the renderScale != 1.0
 1578            var asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
 1579            asset.renderScale = prevRenderScale;
 580
 1581            if (DataStore.i.common.isSignUpFlow.Get())
 0582                CommonScriptableObjects.isFullscreenHUDOpen.Set(false);
 583
 1584            DataStore.i.common.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded;
 585
 1586            OnClose?.Invoke();
 0587        }
 87588        else if (visible && !view.isOpen)
 589        {
 41590            if (DataStore.i.common.isSignUpFlow.Get())
 0591                DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(0f);
 592
 41593            LoadOwnedWereables(userProfile);
 41594            DCL.Environment.i.messaging.manager.paused = DataStore.i.common.isSignUpFlow.Get();
 41595            DataStore.i.skyboxConfig.avatarMatProfile.Set(AvatarMaterialProfile.InEditor);
 41596            currentRenderProfile.avatarProfile.Apply();
 597
 41598            prevMouseLockState = Utils.isCursorLocked;
 599
 41600            if (DataStore.i.common.isSignUpFlow.Get() || !DataStore.i.exploreV2.isInitialized.Get())
 41601                Utils.UnlockCursor();
 602
 603            // NOTE(Brian): SSAO doesn't work correctly with the offseted avatar preview if the renderScale != 1.0
 41604            var asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
 41605            prevRenderScale = asset.renderScale;
 41606            asset.renderScale = 1.0f;
 607
 41608            if (DataStore.i.common.isSignUpFlow.Get())
 0609                CommonScriptableObjects.isFullscreenHUDOpen.Set(true);
 610
 41611            DataStore.i.common.isPlayerRendererLoaded.OnChange += PlayerRendererLoaded;
 612
 41613            OnOpen?.Invoke();
 614        }
 615
 88616        currentRenderProfile.avatarProfile.Apply();
 88617        view.SetVisibility(visible);
 88618    }
 619
 620    public void Dispose()
 621    {
 41622        avatarEditorVisible.OnChange -= OnAvatarEditorVisibleChanged;
 41623        configureBackpackInFullscreenMenu.OnChange -= ConfigureBackpackInFullscreenMenuChanged;
 41624        view.OnCloseActionTriggered -= DiscardAndClose;
 41625        DataStore.i.common.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded;
 41626        exploreV2IsOpen.OnChange -= ExploreV2IsOpenChanged;
 627
 41628        CleanUp();
 41629    }
 630
 631    public void CleanUp()
 632    {
 46633        UnequipAllWearables();
 634
 46635        if (view != null)
 46636            view.CleanUp();
 637
 46638        this.userProfile.OnUpdate -= LoadUserProfile;
 46639        this.catalog.OnAdded -= AddWearable;
 46640        this.catalog.OnRemoved -= RemoveWearable;
 46641        DataStore.i.common.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded;
 46642    }
 643
 0644    public void SetConfiguration(HUDConfiguration configuration) { SetVisibility(configuration.active); }
 645
 646    public void SaveAvatar(Texture2D faceSnapshot, Texture2D face128Snapshot, Texture2D face256Snapshot, Texture2D bodyS
 647    {
 1648        var avatarModel = model.ToAvatarModel();
 649
 1650        WebInterface.SendSaveAvatar(avatarModel, faceSnapshot, face128Snapshot, face256Snapshot, bodySnapshot, DataStore
 1651        userProfile.OverrideAvatar(avatarModel, face256Snapshot);
 1652        if (DataStore.i.common.isSignUpFlow.Get())
 0653            DataStore.i.HUDs.signupVisible.Set(true);
 654
 1655        avatarIsDirty = false;
 1656        SetVisibility(false);
 1657    }
 658
 659    public void DiscardAndClose()
 660    {
 0661        if (!view.isOpen)
 0662            return;
 663
 0664        if (!DataStore.i.common.isSignUpFlow.Get())
 0665            LoadUserProfile(userProfile);
 666        else
 0667            WebInterface.SendCloseUserAvatar(true);
 668
 0669        SetVisibility(false);
 0670    }
 671
 672    public void GoToMarketplace()
 673    {
 0674        if (userProfile.hasConnectedWeb3)
 0675            WebInterface.OpenURL(URL_MARKET_PLACE);
 676        else
 0677            WebInterface.OpenURL(URL_GET_A_WALLET);
 0678    }
 679
 680    public void SellCollectible(string collectibleId)
 681    {
 0682        var ownedCollectible = ownedNftCollectionsL1.FirstOrDefault(nft => nft.urn == collectibleId);
 0683        if (ownedCollectible == null)
 0684            ownedCollectible = ownedNftCollectionsL2.FirstOrDefault(nft => nft.urn == collectibleId);
 685
 0686        if (ownedCollectible != null)
 0687            WebInterface.OpenURL(URL_SELL_SPECIFIC_COLLECTIBLE.Replace("{collectionId}", ownedCollectible.collectionId).
 688        else
 0689            WebInterface.OpenURL(URL_SELL_COLLECTIBLE_GENERIC);
 0690    }
 691
 0692    public void ToggleVisibility() { SetVisibility(!view.isOpen); }
 693
 92694    private void ConfigureBackpackInFullscreenMenuChanged(Transform currentParentTransform, Transform previousParentTran
 695
 696    private void ExploreV2IsOpenChanged(bool current, bool previous)
 697    {
 0698        if (!current && avatarIsDirty)
 699        {
 0700            LoadUserProfile(userProfile, true);
 0701            avatarIsDirty = false;
 702        }
 0703    }
 704}

Methods/Properties

AvatarEditorHUDController()
renderingEnabled()
isPlayerRendererLoaded()
avatarEditorVisible()
configureBackpackInFullscreenMenu()
exploreV2IsOpen()
AvatarEditorHUDController()
Initialize(UserProfile, .BaseDictionary[String,WearableItem], System.Boolean)
SetCatalog(.BaseDictionary[String,WearableItem])
LoadUserProfile(UserProfile)
LoadOwnedWereables(UserProfile)
QueryNftCollections(System.String)
RetryLoadOwnedWearables()
PlayerRendererLoaded(System.Boolean, System.Boolean)
LoadUserProfile(UserProfile, System.Boolean)
EnsureWearablesCategoriesNotEmpty()
WearableClicked(System.String)
HairColorClicked(UnityEngine.Color)
SkinColorClicked(UnityEngine.Color)
EyesColorClicked(UnityEngine.Color)
UpdateAvatarPreview()
EquipHairColor(UnityEngine.Color)
EquipEyesColor(UnityEngine.Color)
EquipSkinColor(UnityEngine.Color)
EquipBodyShape(WearableItem)
EquipWearable(WearableItem)
UnequipWearable(WearableItem)
UnequipAllWearables()
ProcessCatalog(.BaseDictionary[String,WearableItem])
AddWearable(System.String, WearableItem)
RemoveWearable(System.String, WearableItem)
RandomizeWearables()
GetWearablesReplacedBy(WearableItem)
SetVisibility(System.Boolean)
OnAvatarEditorVisibleChanged(System.Boolean, System.Boolean)
SetVisibility_Internal(System.Boolean)
Dispose()
CleanUp()
SetConfiguration(HUDConfiguration)
SaveAvatar(UnityEngine.Texture2D, UnityEngine.Texture2D, UnityEngine.Texture2D, UnityEngine.Texture2D)
DiscardAndClose()
GoToMarketplace()
SellCollectible(System.String)
ToggleVisibility()
ConfigureBackpackInFullscreenMenuChanged(UnityEngine.Transform, UnityEngine.Transform)
ExploreV2IsOpenChanged(System.Boolean, System.Boolean)