| | 1 | | using DCL; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Interface; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Linq; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.Rendering; |
| | 9 | | using UnityEngine.Rendering.Universal; |
| | 10 | | using Categories = WearableLiterals.Categories; |
| | 11 | |
|
| | 12 | | public 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 = "https://market.decentraland.org/account"; |
| | 19 | |
|
| 1 | 20 | | protected static readonly string[] categoriesThatMustHaveSelection = { Categories.BODY_SHAPE, Categories.UPPER_BODY, |
| 1 | 21 | | protected static readonly string[] categoriesToRandomize = { Categories.HAIR, Categories.EYES, Categories.EYEBROWS, |
| | 22 | |
|
| | 23 | | [NonSerialized] |
| | 24 | | public bool bypassUpdateAvatarPreview = false; |
| | 25 | |
|
| | 26 | | private UserProfile userProfile; |
| | 27 | | private BaseDictionary<string, WearableItem> catalog; |
| 87 | 28 | | bool renderingEnabled => CommonScriptableObjects.rendererState.Get(); |
| 0 | 29 | | bool isPlayerRendererLoaded => DataStore.i.isPlayerRendererLoaded.Get(); |
| 46 | 30 | | private readonly Dictionary<string, List<WearableItem>> wearablesByCategory = new Dictionary<string, List<WearableIt |
| 46 | 31 | | protected readonly AvatarEditorHUDModel model = new AvatarEditorHUDModel(); |
| | 32 | |
|
| | 33 | | private ColorList skinColorList; |
| | 34 | | private ColorList eyeColorList; |
| | 35 | | private ColorList hairColorList; |
| | 36 | | private bool prevMouseLockState = false; |
| 46 | 37 | | private int ownedWearablesRemainingRequests = LOADING_OWNED_WEARABLES_RETRIES; |
| | 38 | | private bool ownedWearablesAlreadyLoaded = false; |
| | 39 | |
|
| | 40 | | public AvatarEditorHUDView view; |
| | 41 | |
|
| | 42 | | public event Action OnOpen; |
| | 43 | | public event Action OnClose; |
| | 44 | |
|
| 92 | 45 | | public AvatarEditorHUDController() { } |
| | 46 | |
|
| | 47 | | public void Initialize(UserProfile userProfile, BaseDictionary<string, WearableItem> catalog, bool bypassUpdateAvata |
| | 48 | | { |
| 44 | 49 | | this.userProfile = userProfile; |
| 44 | 50 | | this.bypassUpdateAvatarPreview = bypassUpdateAvatarPreview; |
| | 51 | |
|
| 44 | 52 | | view = AvatarEditorHUDView.Create(this); |
| | 53 | |
|
| 44 | 54 | | view.OnToggleActionTriggered += ToggleVisibility; |
| 44 | 55 | | view.OnCloseActionTriggered += DiscardAndClose; |
| | 56 | |
|
| 44 | 57 | | skinColorList = Resources.Load<ColorList>("SkinTone"); |
| 44 | 58 | | hairColorList = Resources.Load<ColorList>("HairColor"); |
| 44 | 59 | | eyeColorList = Resources.Load<ColorList>("EyeColor"); |
| 44 | 60 | | view.SetColors(skinColorList.colors, hairColorList.colors, eyeColorList.colors); |
| | 61 | |
|
| 44 | 62 | | SetCatalog(catalog); |
| | 63 | |
|
| 44 | 64 | | LoadUserProfile(userProfile, true); |
| 44 | 65 | | this.userProfile.OnUpdate += LoadUserProfile; |
| 44 | 66 | | DataStore.i.isPlayerRendererLoaded.OnChange += PlayerRendererLoaded; |
| 44 | 67 | | } |
| | 68 | |
|
| | 69 | | public void SetCatalog(BaseDictionary<string, WearableItem> catalog) |
| | 70 | | { |
| 44 | 71 | | if (this.catalog != null) |
| | 72 | | { |
| 0 | 73 | | this.catalog.OnAdded -= AddWearable; |
| 0 | 74 | | this.catalog.OnRemoved -= RemoveWearable; |
| | 75 | | } |
| | 76 | |
|
| 44 | 77 | | this.catalog = catalog; |
| | 78 | |
|
| 44 | 79 | | ProcessCatalog(this.catalog); |
| 44 | 80 | | this.catalog.OnAdded += AddWearable; |
| 44 | 81 | | this.catalog.OnRemoved += RemoveWearable; |
| 44 | 82 | | } |
| | 83 | |
|
| | 84 | | private void LoadUserProfile(UserProfile userProfile) |
| | 85 | | { |
| 41 | 86 | | LoadOwnedWereables(userProfile); |
| 41 | 87 | | LoadUserProfile(userProfile, false); |
| 41 | 88 | | } |
| | 89 | |
|
| | 90 | | private void LoadOwnedWereables(UserProfile userProfile) |
| | 91 | | { |
| 41 | 92 | | if (ownedWearablesAlreadyLoaded || ownedWearablesRemainingRequests <= 0 || string.IsNullOrEmpty(userProfile.user |
| 41 | 93 | | return; |
| | 94 | |
|
| 0 | 95 | | view.ShowCollectiblesLoadingSpinner(true); |
| 0 | 96 | | view.ShowCollectiblesLoadingRetry(false); |
| 0 | 97 | | CatalogController.RequestOwnedWearables(userProfile.userId) |
| | 98 | | .Then((ownedWearables) => |
| | 99 | | { |
| 0 | 100 | | ownedWearablesAlreadyLoaded = true; |
| 0 | 101 | | this.userProfile.SetInventory(ownedWearables.Select(x => x.id).ToArray()); |
| 0 | 102 | | LoadUserProfile(userProfile, true); |
| 0 | 103 | | view.ShowCollectiblesLoadingSpinner(false); |
| 0 | 104 | | }) |
| | 105 | | .Catch((error) => |
| | 106 | | { |
| 0 | 107 | | ownedWearablesRemainingRequests--; |
| 0 | 108 | | if (ownedWearablesRemainingRequests > 0) |
| | 109 | | { |
| 0 | 110 | | Debug.LogWarning("Retrying owned wereables loading..."); |
| 0 | 111 | | LoadOwnedWereables(userProfile); |
| 0 | 112 | | } |
| | 113 | | else |
| | 114 | | { |
| 0 | 115 | | NotificationsController.i.ShowNotification(new Notification.Model |
| | 116 | | { |
| | 117 | | message = LOADING_OWNED_WEARABLES_ERROR_MESSAGE, |
| | 118 | | type = NotificationFactory.Type.GENERIC, |
| | 119 | | timer = 10f, |
| | 120 | | destroyOnFinish = true |
| | 121 | | }); |
| | 122 | |
|
| 0 | 123 | | view.ShowCollectiblesLoadingSpinner(false); |
| 0 | 124 | | view.ShowCollectiblesLoadingRetry(true); |
| 0 | 125 | | Debug.LogError(error); |
| | 126 | | } |
| 0 | 127 | | }); |
| 0 | 128 | | } |
| | 129 | |
|
| | 130 | | public void RetryLoadOwnedWearables() |
| | 131 | | { |
| 0 | 132 | | ownedWearablesRemainingRequests = LOADING_OWNED_WEARABLES_RETRIES; |
| 0 | 133 | | LoadOwnedWereables(userProfile); |
| 0 | 134 | | } |
| | 135 | |
|
| | 136 | | private void PlayerRendererLoaded(bool current, bool previous) |
| | 137 | | { |
| 2 | 138 | | if (!current) |
| 0 | 139 | | return; |
| | 140 | |
|
| 2 | 141 | | if (!ownedWearablesAlreadyLoaded) |
| | 142 | | { |
| 2 | 143 | | List<string> equippedOwnedWearables = new List<string>(); |
| 4 | 144 | | for (int i = 0; i < userProfile.avatar.wearables.Count; i++) |
| | 145 | | { |
| 0 | 146 | | if (catalog.TryGetValue(userProfile.avatar.wearables[i], out WearableItem wearable) && |
| | 147 | | !wearable.data.tags.Contains("base-wearable")) |
| | 148 | | { |
| 0 | 149 | | equippedOwnedWearables.Add(userProfile.avatar.wearables[i]); |
| | 150 | | } |
| | 151 | | } |
| | 152 | |
|
| 2 | 153 | | userProfile.SetInventory(equippedOwnedWearables.ToArray()); |
| | 154 | | } |
| | 155 | |
|
| 2 | 156 | | LoadUserProfile(userProfile, true); |
| 2 | 157 | | DataStore.i.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded; |
| 2 | 158 | | } |
| | 159 | |
|
| | 160 | | public void LoadUserProfile(UserProfile userProfile, bool forceLoading) |
| | 161 | | { |
| 87 | 162 | | bool avatarEditorNotVisible = renderingEnabled && !view.isOpen; |
| 87 | 163 | | bool isPlaying = !Application.isBatchMode; |
| | 164 | |
|
| 87 | 165 | | if (!forceLoading) |
| | 166 | | { |
| 41 | 167 | | if (isPlaying && avatarEditorNotVisible) |
| 0 | 168 | | return; |
| | 169 | | } |
| | 170 | |
|
| 87 | 171 | | if (userProfile == null) |
| 0 | 172 | | return; |
| | 173 | |
|
| 87 | 174 | | if (userProfile.avatar == null || string.IsNullOrEmpty(userProfile.avatar.bodyShape)) |
| 3 | 175 | | return; |
| | 176 | |
|
| 84 | 177 | | CatalogController.wearableCatalog.TryGetValue(userProfile.avatar.bodyShape, out var bodyShape); |
| | 178 | |
|
| 84 | 179 | | if (bodyShape == null) |
| | 180 | | { |
| 0 | 181 | | return; |
| | 182 | | } |
| | 183 | |
|
| 84 | 184 | | view.SetIsWeb3(userProfile.hasConnectedWeb3); |
| | 185 | |
|
| 84 | 186 | | ProcessCatalog(this.catalog); |
| 84 | 187 | | EquipBodyShape(bodyShape); |
| 84 | 188 | | EquipSkinColor(userProfile.avatar.skinColor); |
| 84 | 189 | | EquipHairColor(userProfile.avatar.hairColor); |
| 84 | 190 | | EquipEyesColor(userProfile.avatar.eyeColor); |
| | 191 | |
|
| 84 | 192 | | model.wearables.Clear(); |
| 84 | 193 | | view.UnselectAllWearables(); |
| | 194 | |
|
| 84 | 195 | | int wearablesCount = userProfile.avatar.wearables.Count; |
| | 196 | |
|
| 84 | 197 | | if (isPlayerRendererLoaded) |
| | 198 | | { |
| 184 | 199 | | for (var i = 0; i < wearablesCount; i++) |
| | 200 | | { |
| 53 | 201 | | CatalogController.wearableCatalog.TryGetValue(userProfile.avatar.wearables[i], out var wearable); |
| 53 | 202 | | if (wearable == null) |
| | 203 | | { |
| 0 | 204 | | Debug.LogError($"Couldn't find wearable with ID {userProfile.avatar.wearables[i]}"); |
| 0 | 205 | | continue; |
| | 206 | | } |
| | 207 | |
|
| 53 | 208 | | EquipWearable(wearable); |
| | 209 | | } |
| | 210 | | } |
| | 211 | |
|
| 84 | 212 | | EnsureWearablesCategoriesNotEmpty(); |
| | 213 | |
|
| 84 | 214 | | UpdateAvatarPreview(); |
| 84 | 215 | | } |
| | 216 | |
|
| | 217 | | private void EnsureWearablesCategoriesNotEmpty() |
| | 218 | | { |
| 137 | 219 | | var categoriesInUse = model.wearables.Select(x => x.data.category).ToArray(); |
| 1344 | 220 | | for (var i = 0; i < categoriesThatMustHaveSelection.Length; i++) |
| | 221 | | { |
| 588 | 222 | | var category = categoriesThatMustHaveSelection[i]; |
| 588 | 223 | | if (category != Categories.BODY_SHAPE && !(categoriesInUse.Contains(category))) |
| | 224 | | { |
| | 225 | | WearableItem wearable; |
| 462 | 226 | | var defaultItemId = WearableLiterals.DefaultWearables.GetDefaultWearable(model.bodyShape.id, category); |
| 462 | 227 | | if (defaultItemId != null) |
| | 228 | | { |
| 462 | 229 | | CatalogController.wearableCatalog.TryGetValue(defaultItemId, out wearable); |
| 462 | 230 | | } |
| | 231 | | else |
| | 232 | | { |
| 0 | 233 | | wearable = wearablesByCategory[category].FirstOrDefault(x => x.SupportsBodyShape(model.bodyShape.id) |
| | 234 | | } |
| | 235 | |
|
| 462 | 236 | | if (wearable != null) |
| | 237 | | { |
| 462 | 238 | | EquipWearable(wearable); |
| | 239 | | } |
| | 240 | | } |
| | 241 | | } |
| 84 | 242 | | } |
| | 243 | |
|
| | 244 | | public void WearableClicked(string wearableId) |
| | 245 | | { |
| 20 | 246 | | CatalogController.wearableCatalog.TryGetValue(wearableId, out var wearable); |
| 20 | 247 | | if (wearable == null) |
| 3 | 248 | | return; |
| | 249 | |
|
| 17 | 250 | | if (wearable.data.category == Categories.BODY_SHAPE) |
| | 251 | | { |
| 3 | 252 | | if (wearable.id == model.bodyShape.id) |
| 0 | 253 | | return; |
| 3 | 254 | | EquipBodyShape(wearable); |
| 3 | 255 | | } |
| | 256 | | else |
| | 257 | | { |
| 14 | 258 | | if (model.wearables.Contains(wearable)) |
| | 259 | | { |
| 2 | 260 | | if (!categoriesThatMustHaveSelection.Contains(wearable.data.category)) |
| | 261 | | { |
| 0 | 262 | | UnequipWearable(wearable); |
| 0 | 263 | | } |
| | 264 | | else |
| | 265 | | { |
| 2 | 266 | | return; |
| | 267 | | } |
| | 268 | | } |
| | 269 | | else |
| | 270 | | { |
| 91 | 271 | | var sameCategoryEquipped = model.wearables.FirstOrDefault(x => x.data.category == wearable.data.category |
| 12 | 272 | | if (sameCategoryEquipped != null) |
| | 273 | | { |
| 2 | 274 | | UnequipWearable(sameCategoryEquipped); |
| | 275 | | } |
| | 276 | |
|
| 12 | 277 | | EquipWearable(wearable); |
| | 278 | | } |
| | 279 | | } |
| | 280 | |
|
| 15 | 281 | | UpdateAvatarPreview(); |
| 15 | 282 | | } |
| | 283 | |
|
| | 284 | | public void HairColorClicked(Color color) |
| | 285 | | { |
| 2 | 286 | | EquipHairColor(color); |
| 2 | 287 | | view.SelectHairColor(model.hairColor); |
| 2 | 288 | | UpdateAvatarPreview(); |
| 2 | 289 | | } |
| | 290 | |
|
| | 291 | | public void SkinColorClicked(Color color) |
| | 292 | | { |
| 2 | 293 | | EquipSkinColor(color); |
| 2 | 294 | | view.SelectSkinColor(model.skinColor); |
| 2 | 295 | | UpdateAvatarPreview(); |
| 2 | 296 | | } |
| | 297 | |
|
| | 298 | | public void EyesColorClicked(Color color) |
| | 299 | | { |
| 2 | 300 | | EquipEyesColor(color); |
| 2 | 301 | | view.SelectEyeColor(model.eyesColor); |
| 2 | 302 | | UpdateAvatarPreview(); |
| 2 | 303 | | } |
| | 304 | |
|
| | 305 | | protected virtual void UpdateAvatarPreview() |
| | 306 | | { |
| 106 | 307 | | if (!bypassUpdateAvatarPreview) |
| 106 | 308 | | view.UpdateAvatarPreview(model.ToAvatarModel()); |
| 106 | 309 | | } |
| | 310 | |
|
| | 311 | | private void EquipHairColor(Color color) |
| | 312 | | { |
| 87 | 313 | | var colorToSet = color; |
| 881 | 314 | | if (!hairColorList.colors.Any(x => x.AproxComparison(colorToSet))) |
| | 315 | | { |
| 78 | 316 | | colorToSet = hairColorList.colors[hairColorList.defaultColor]; |
| | 317 | | } |
| | 318 | |
|
| 87 | 319 | | model.hairColor = colorToSet; |
| 87 | 320 | | view.SelectHairColor(model.hairColor); |
| 87 | 321 | | } |
| | 322 | |
|
| | 323 | | private void EquipEyesColor(Color color) |
| | 324 | | { |
| 87 | 325 | | var colorToSet = color; |
| 883 | 326 | | if (!eyeColorList.colors.Any(x => x.AproxComparison(color))) |
| | 327 | | { |
| 78 | 328 | | colorToSet = eyeColorList.colors[eyeColorList.defaultColor]; |
| | 329 | | } |
| | 330 | |
|
| 87 | 331 | | model.eyesColor = colorToSet; |
| 87 | 332 | | view.SelectEyeColor(model.eyesColor); |
| 87 | 333 | | } |
| | 334 | |
|
| | 335 | | private void EquipSkinColor(Color color) |
| | 336 | | { |
| 86 | 337 | | var colorToSet = color; |
| 877 | 338 | | if (!skinColorList.colors.Any(x => x.AproxComparison(colorToSet))) |
| | 339 | | { |
| 78 | 340 | | colorToSet = skinColorList.colors[skinColorList.defaultColor]; |
| | 341 | | } |
| | 342 | |
|
| 86 | 343 | | model.skinColor = colorToSet; |
| 86 | 344 | | view.SelectSkinColor(model.skinColor); |
| 86 | 345 | | } |
| | 346 | |
|
| | 347 | | private void EquipBodyShape(WearableItem bodyShape) |
| | 348 | | { |
| 87 | 349 | | if (bodyShape.data.category != Categories.BODY_SHAPE) |
| | 350 | | { |
| 0 | 351 | | Debug.LogError($"Item ({bodyShape.id} is not a body shape"); |
| 0 | 352 | | return; |
| | 353 | | } |
| | 354 | |
|
| 87 | 355 | | if (model.bodyShape == bodyShape) |
| 37 | 356 | | return; |
| | 357 | |
|
| 50 | 358 | | model.bodyShape = bodyShape; |
| 50 | 359 | | view.UpdateSelectedBody(bodyShape); |
| | 360 | |
|
| 50 | 361 | | int wearablesCount = model.wearables.Count; |
| 172 | 362 | | for (var i = wearablesCount - 1; i >= 0; i--) |
| | 363 | | { |
| 36 | 364 | | UnequipWearable(model.wearables[i]); |
| | 365 | | } |
| | 366 | |
|
| 50 | 367 | | var defaultWearables = WearableLiterals.DefaultWearables.GetDefaultWearables(bodyShape.id); |
| 812 | 368 | | for (var i = 0; i < defaultWearables.Length; i++) |
| | 369 | | { |
| 356 | 370 | | if (catalog.TryGetValue(defaultWearables[i], out var wearable)) |
| 356 | 371 | | EquipWearable(wearable); |
| | 372 | | } |
| 50 | 373 | | } |
| | 374 | |
|
| | 375 | | private void EquipWearable(WearableItem wearable) |
| | 376 | | { |
| 890 | 377 | | if (!wearablesByCategory.ContainsKey(wearable.data.category)) |
| 0 | 378 | | return; |
| | 379 | |
|
| 890 | 380 | | if (wearablesByCategory[wearable.data.category].Contains(wearable) && wearable.SupportsBodyShape(model.bodyShape |
| | 381 | | { |
| 890 | 382 | | var toReplace = GetWearablesReplacedBy(wearable); |
| 890 | 383 | | toReplace.ForEach(UnequipWearable); |
| 890 | 384 | | model.wearables.Add(wearable); |
| 890 | 385 | | view.EquipWearable(wearable); |
| | 386 | | } |
| 890 | 387 | | } |
| | 388 | |
|
| | 389 | | private void UnequipWearable(WearableItem wearable) |
| | 390 | | { |
| 40 | 391 | | if (model.wearables.Contains(wearable)) |
| | 392 | | { |
| 40 | 393 | | model.wearables.Remove(wearable); |
| 40 | 394 | | view.UnequipWearable(wearable); |
| | 395 | | } |
| 40 | 396 | | } |
| | 397 | |
|
| | 398 | | public void UnequipAllWearables() |
| | 399 | | { |
| 926 | 400 | | foreach (var wearable in model.wearables) |
| | 401 | | { |
| 395 | 402 | | view.UnequipWearable(wearable); |
| | 403 | | } |
| | 404 | |
|
| 68 | 405 | | model.wearables.Clear(); |
| 68 | 406 | | } |
| | 407 | |
|
| | 408 | | private void ProcessCatalog(BaseDictionary<string, WearableItem> catalog) |
| | 409 | | { |
| 128 | 410 | | wearablesByCategory.Clear(); |
| 128 | 411 | | view.RemoveAllWearables(); |
| 128 | 412 | | using (var iterator = catalog.Get().GetEnumerator()) |
| | 413 | | { |
| 3840 | 414 | | while (iterator.MoveNext()) |
| | 415 | | { |
| 3712 | 416 | | AddWearable(iterator.Current.Key, iterator.Current.Value); |
| | 417 | | } |
| 128 | 418 | | } |
| 128 | 419 | | } |
| | 420 | |
|
| | 421 | | private void AddWearable(string id, WearableItem wearable) |
| | 422 | | { |
| 3718 | 423 | | if (!wearable.data.tags.Contains("base-wearable") && userProfile.GetItemAmount(id) == 0) |
| | 424 | | { |
| 118 | 425 | | return; |
| | 426 | | } |
| | 427 | |
|
| 3600 | 428 | | if (!wearablesByCategory.ContainsKey(wearable.data.category)) |
| | 429 | | { |
| 1408 | 430 | | wearablesByCategory.Add(wearable.data.category, new List<WearableItem>()); |
| | 431 | | } |
| | 432 | |
|
| 3600 | 433 | | wearablesByCategory[wearable.data.category].Add(wearable); |
| 3600 | 434 | | view.AddWearable(wearable, userProfile.GetItemAmount(id)); |
| 3600 | 435 | | } |
| | 436 | |
|
| | 437 | | private void RemoveWearable(string id, WearableItem wearable) |
| | 438 | | { |
| 0 | 439 | | if (wearablesByCategory.ContainsKey(wearable.data.category)) |
| | 440 | | { |
| 0 | 441 | | if (wearablesByCategory[wearable.data.category].Remove(wearable)) |
| | 442 | | { |
| 0 | 443 | | if (wearablesByCategory[wearable.data.category].Count == 0) |
| | 444 | | { |
| 0 | 445 | | wearablesByCategory.Remove(wearable.data.category); |
| | 446 | | } |
| | 447 | | } |
| | 448 | | } |
| | 449 | |
|
| 0 | 450 | | view.RemoveWearable(wearable); |
| 0 | 451 | | } |
| | 452 | |
|
| | 453 | | public void RandomizeWearables() |
| | 454 | | { |
| 1 | 455 | | EquipHairColor(hairColorList.colors[UnityEngine.Random.Range(0, hairColorList.colors.Count)]); |
| 1 | 456 | | EquipEyesColor(eyeColorList.colors[UnityEngine.Random.Range(0, eyeColorList.colors.Count)]); |
| | 457 | |
|
| 1 | 458 | | model.wearables.Clear(); |
| 1 | 459 | | view.UnselectAllWearables(); |
| 1 | 460 | | using (var iterator = wearablesByCategory.GetEnumerator()) |
| | 461 | | { |
| 12 | 462 | | while (iterator.MoveNext()) |
| | 463 | | { |
| 11 | 464 | | string category = iterator.Current.Key; |
| 11 | 465 | | if (!categoriesToRandomize.Contains(category)) |
| | 466 | | { |
| | 467 | | continue; |
| | 468 | | } |
| | 469 | |
|
| 29 | 470 | | var supportedWearables = iterator.Current.Value.Where(x => x.SupportsBodyShape(model.bodyShape.id)).ToAr |
| 7 | 471 | | if (supportedWearables.Length == 0) |
| | 472 | | { |
| 0 | 473 | | Debug.LogError($"Couldn't get any wearable for category {category} and bodyshape {model.bodyShape.id |
| | 474 | | } |
| | 475 | |
|
| 7 | 476 | | var wearable = supportedWearables[UnityEngine.Random.Range(0, supportedWearables.Length - 1)]; |
| 7 | 477 | | EquipWearable(wearable); |
| | 478 | | } |
| 1 | 479 | | } |
| | 480 | |
|
| 1 | 481 | | UpdateAvatarPreview(); |
| 1 | 482 | | } |
| | 483 | |
|
| | 484 | | public List<WearableItem> GetWearablesReplacedBy(WearableItem wearableItem) |
| | 485 | | { |
| 890 | 486 | | List<WearableItem> wearablesToReplace = new List<WearableItem>(); |
| | 487 | |
|
| 890 | 488 | | HashSet<string> categoriesToReplace = new HashSet<string>(wearableItem.GetReplacesList(model.bodyShape.id) ?? ne |
| | 489 | |
|
| 890 | 490 | | int wearableCount = model.wearables.Count; |
| 6820 | 491 | | for (int i = 0; i < wearableCount; i++) |
| | 492 | | { |
| 2520 | 493 | | var wearable = model.wearables[i]; |
| 2520 | 494 | | if (wearable == null) |
| | 495 | | continue; |
| | 496 | |
|
| 2520 | 497 | | if (categoriesToReplace.Contains(wearable.data.category)) |
| | 498 | | { |
| 2 | 499 | | wearablesToReplace.Add(wearable); |
| 2 | 500 | | } |
| | 501 | | else |
| | 502 | | { |
| | 503 | | //For retrocompatibility's sake we check current wearables against new one (compatibility matrix is symm |
| 2518 | 504 | | HashSet<string> replacesList = new HashSet<string>(wearable.GetReplacesList(model.bodyShape.id) ?? new s |
| 2518 | 505 | | if (replacesList.Contains(wearableItem.data.category)) |
| | 506 | | { |
| 0 | 507 | | wearablesToReplace.Add(wearable); |
| | 508 | | } |
| | 509 | | } |
| | 510 | | } |
| | 511 | |
|
| 890 | 512 | | return wearablesToReplace; |
| | 513 | | } |
| | 514 | |
|
| 46 | 515 | | private float prevRenderScale = 1.0f; |
| | 516 | | private Camera mainCamera; |
| | 517 | |
|
| | 518 | | public void SetVisibility(bool visible) |
| | 519 | | { |
| 40 | 520 | | var currentRenderProfile = DCL.RenderProfileManifest.i.currentProfile; |
| | 521 | |
|
| 40 | 522 | | if (!visible && view.isOpen) |
| | 523 | | { |
| 1 | 524 | | DCL.Environment.i.messaging.manager.paused = false; |
| 1 | 525 | | currentRenderProfile.avatarProfile.currentProfile = currentRenderProfile.avatarProfile.inWorld; |
| 1 | 526 | | currentRenderProfile.avatarProfile.Apply(); |
| 1 | 527 | | if (prevMouseLockState) |
| | 528 | | { |
| 0 | 529 | | Utils.LockCursor(); |
| | 530 | | } |
| | 531 | |
|
| | 532 | | // NOTE(Brian): SSAO doesn't work correctly with the offseted avatar preview if the renderScale != 1.0 |
| 1 | 533 | | var asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; |
| 1 | 534 | | asset.renderScale = prevRenderScale; |
| | 535 | |
|
| 1 | 536 | | CommonScriptableObjects.isFullscreenHUDOpen.Set(false); |
| 1 | 537 | | OnClose?.Invoke(); |
| 0 | 538 | | } |
| 39 | 539 | | else if (visible && !view.isOpen) |
| | 540 | | { |
| 39 | 541 | | DCL.Environment.i.messaging.manager.paused = DataStore.i.isSignUpFlow.Get(); |
| 39 | 542 | | currentRenderProfile.avatarProfile.currentProfile = currentRenderProfile.avatarProfile.avatarEditor; |
| 39 | 543 | | currentRenderProfile.avatarProfile.Apply(); |
| | 544 | |
|
| 39 | 545 | | prevMouseLockState = Utils.isCursorLocked; |
| 39 | 546 | | Utils.UnlockCursor(); |
| | 547 | |
|
| | 548 | | // NOTE(Brian): SSAO doesn't work correctly with the offseted avatar preview if the renderScale != 1.0 |
| 39 | 549 | | var asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; |
| 39 | 550 | | prevRenderScale = asset.renderScale; |
| 39 | 551 | | asset.renderScale = 1.0f; |
| | 552 | |
|
| 39 | 553 | | CommonScriptableObjects.isFullscreenHUDOpen.Set(true); |
| 39 | 554 | | OnOpen?.Invoke(); |
| | 555 | | } |
| | 556 | |
|
| 40 | 557 | | currentRenderProfile.avatarProfile.Apply(); |
| 40 | 558 | | view.SetVisibility(visible); |
| 40 | 559 | | } |
| | 560 | |
|
| | 561 | | public void Dispose() |
| | 562 | | { |
| 39 | 563 | | view.OnToggleActionTriggered -= ToggleVisibility; |
| 39 | 564 | | view.OnCloseActionTriggered -= DiscardAndClose; |
| | 565 | |
|
| 39 | 566 | | CleanUp(); |
| 39 | 567 | | } |
| | 568 | |
|
| | 569 | | public void CleanUp() |
| | 570 | | { |
| 44 | 571 | | UnequipAllWearables(); |
| | 572 | |
|
| 44 | 573 | | if (view != null) |
| 44 | 574 | | view.CleanUp(); |
| | 575 | |
|
| 44 | 576 | | this.userProfile.OnUpdate -= LoadUserProfile; |
| 44 | 577 | | this.catalog.OnAdded -= AddWearable; |
| 44 | 578 | | this.catalog.OnRemoved -= RemoveWearable; |
| 44 | 579 | | DataStore.i.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded; |
| 44 | 580 | | } |
| | 581 | |
|
| 0 | 582 | | public void SetConfiguration(HUDConfiguration configuration) { SetVisibility(configuration.active); } |
| | 583 | |
|
| | 584 | | public void SaveAvatar(Texture2D faceSnapshot, Texture2D face128Snapshot, Texture2D face256Snapshot, Texture2D bodyS |
| | 585 | | { |
| 1 | 586 | | var avatarModel = model.ToAvatarModel(); |
| | 587 | |
|
| 1 | 588 | | WebInterface.SendSaveAvatar(avatarModel, faceSnapshot, face128Snapshot, face256Snapshot, bodySnapshot, DataStore |
| 1 | 589 | | userProfile.OverrideAvatar(avatarModel, face256Snapshot); |
| 1 | 590 | | if (DataStore.i.isSignUpFlow.Get()) |
| 0 | 591 | | DataStore.i.HUDs.signupVisible.Set(true); |
| | 592 | |
|
| 1 | 593 | | SetVisibility(false); |
| 1 | 594 | | } |
| | 595 | |
|
| | 596 | | public void DiscardAndClose() |
| | 597 | | { |
| 0 | 598 | | if (!DataStore.i.isSignUpFlow.Get()) |
| 0 | 599 | | LoadUserProfile(userProfile); |
| | 600 | | else |
| 0 | 601 | | WebInterface.SendCloseUserAvatar(true); |
| | 602 | |
|
| 0 | 603 | | SetVisibility(false); |
| 0 | 604 | | } |
| | 605 | |
|
| | 606 | | public void GoToMarketplace() |
| | 607 | | { |
| 0 | 608 | | if (userProfile.hasConnectedWeb3) |
| 0 | 609 | | WebInterface.OpenURL(URL_MARKET_PLACE); |
| | 610 | | else |
| 0 | 611 | | WebInterface.OpenURL(URL_GET_A_WALLET); |
| 0 | 612 | | } |
| | 613 | |
|
| 0 | 614 | | public void SellCollectible(string collectibleId) { WebInterface.OpenURL(URL_SELL_COLLECTIBLE); } |
| | 615 | |
|
| 0 | 616 | | public void ToggleVisibility() { SetVisibility(!view.isOpen); } |
| | 617 | | } |