| | 1 | | using AvatarSystem; |
| | 2 | | using Cysharp.Threading.Tasks; |
| | 3 | | using DCL.Components; |
| | 4 | | using DCL.Configuration; |
| | 5 | | using DCL.Controllers; |
| | 6 | | using DCL.Emotes; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using DCL.Interface; |
| | 9 | | using DCL.Models; |
| | 10 | | using System; |
| | 11 | | using System.Collections; |
| | 12 | | using System.Collections.Generic; |
| | 13 | | using System.Linq; |
| | 14 | | using System.Threading; |
| | 15 | | using UnityEngine; |
| | 16 | | using LOD = AvatarSystem.LOD; |
| | 17 | |
|
| | 18 | | namespace DCL |
| | 19 | | { |
| | 20 | | public class AvatarShape : BaseComponent, IHideAvatarAreaHandler, IHidePassportAreaHandler, IOutOfSceneBoundariesHan |
| | 21 | | { |
| | 22 | | private const float MINIMUM_PLAYERNAME_HEIGHT = 2.7f; |
| | 23 | | private const string VISIBILITY_CONSTRAINT_HIDE_AREA = "IN_HIDE_AREA"; |
| | 24 | | private const string VISIBILITY_CONSTRAINT_OUTSIDE_SCENE_BOUNDS = "OUTSIDE_SCENE_BOUNDS"; |
| | 25 | | private const string OPEN_PASSPORT_SOURCE = "World"; |
| | 26 | |
|
| | 27 | | public static event Action<IDCLEntity, AvatarShape> OnAvatarShapeUpdated; |
| | 28 | |
|
| | 29 | | public GameObject avatarContainer; |
| | 30 | | public Collider avatarCollider; |
| | 31 | | public AvatarMovementController avatarMovementController; |
| | 32 | | public StickersController stickersControllers; |
| | 33 | |
|
| | 34 | | [SerializeField] internal AvatarOnPointerDown onPointerDown; |
| | 35 | | [SerializeField] internal AvatarOutlineOnHoverEvent outlineOnHover; |
| | 36 | | [SerializeField] internal GameObject playerNameContainer; |
| | 37 | | [SerializeField] private Transform baseAvatarContainer; |
| | 38 | | [SerializeField] internal BaseAvatarReferences baseAvatarReferencesPrefab; |
| | 39 | |
|
| | 40 | | internal IPlayerName playerName; |
| | 41 | | internal IAvatarReporterController avatarReporterController; |
| | 42 | |
|
| | 43 | | private BaseVariable<(string playerId, string source)> currentPlayerInfoCardId; |
| | 44 | |
|
| | 45 | | public bool everythingIsLoaded; |
| | 46 | |
|
| | 47 | | bool initializedPosition = false; |
| | 48 | |
|
| | 49 | | private Player player = null; |
| 0 | 50 | | private BaseDictionary<string, Player> otherPlayers => DataStore.i.player.otherPlayers; |
| | 51 | |
|
| 311 | 52 | | private IAvatarAnchorPoints anchorPoints = new AvatarAnchorPoints(); |
| | 53 | | internal IAvatar avatar; |
| 311 | 54 | | private readonly AvatarModel currentAvatar = new AvatarModel { wearables = new List<string>() }; |
| | 55 | | private CancellationTokenSource loadingCts; |
| | 56 | | private ILazyTextureObserver currentLazyObserver; |
| 311 | 57 | | private bool isGlobalSceneAvatar = true; |
| | 58 | | private BaseRefCounter<AvatarModifierAreaID> currentActiveModifiers; |
| | 59 | | private IUserProfileBridge userProfileBridge; |
| | 60 | | private Service<IEmotesCatalogService> emotesCatalogService; |
| 4 | 61 | | public override string componentName => "avatarShape"; |
| | 62 | | private AvatarSceneEmoteHandler sceneEmoteHandler; |
| | 63 | | private IAvatarEmotesController emotesController; |
| | 64 | | private IBaseAvatarReferences baseAvatarReferences; |
| 311 | 65 | | private readonly OnPointerEvent.Model pointerEventModel = new () |
| | 66 | | { |
| | 67 | | type = OnPointerDown.NAME, |
| | 68 | | button = WebInterface.ACTION_BUTTON.POINTER.ToString(), |
| | 69 | | hoverText = "View Profile", |
| | 70 | | }; |
| | 71 | |
|
| | 72 | | private void Awake() |
| | 73 | | { |
| 308 | 74 | | model = new AvatarModel(); |
| 308 | 75 | | currentPlayerInfoCardId = DataStore.i.HUDs.currentPlayerId; |
| | 76 | |
|
| | 77 | | // TODO: user profile bridge should be retrieved from the service locator |
| 308 | 78 | | userProfileBridge = new UserProfileWebInterfaceBridge(); |
| | 79 | |
|
| 308 | 80 | | if (DataStore.i.avatarConfig.useHologramAvatar.Get()) |
| 0 | 81 | | avatar = GetAvatarWithHologram(); |
| | 82 | | else |
| 308 | 83 | | avatar = GetStandardAvatar(); |
| | 84 | |
|
| 308 | 85 | | emotesController = avatar.GetEmotesController(); |
| | 86 | |
|
| 308 | 87 | | sceneEmoteHandler = new AvatarSceneEmoteHandler( |
| | 88 | | emotesController, |
| | 89 | | Environment.i.serviceLocator.Get<IEmotesService>()); |
| | 90 | |
|
| 616 | 91 | | if (avatarReporterController == null) { avatarReporterController = new AvatarReporterController(Environment. |
| 308 | 92 | | } |
| | 93 | |
|
| | 94 | | public override void Initialize(IParcelScene scene, IDCLEntity entity) |
| | 95 | | { |
| 1 | 96 | | base.Initialize(scene, entity); |
| 1 | 97 | | DataStore.i.sceneBoundariesChecker?.Add(entity, this); |
| 1 | 98 | | } |
| | 99 | |
|
| | 100 | | private IAvatar GetStandardAvatar() |
| | 101 | | { |
| 308 | 102 | | var visibility = new Visibility(); |
| | 103 | |
|
| 308 | 104 | | return Environment.i.serviceLocator.Get<IAvatarFactory>() |
| | 105 | | .CreateAvatar( |
| | 106 | | avatarContainer, |
| | 107 | | GetComponentInChildren<AvatarAnimatorLegacy>(), |
| | 108 | | new LOD(avatarContainer, visibility, avatarMovementController), |
| | 109 | | visibility |
| | 110 | | ); |
| | 111 | | } |
| | 112 | |
|
| | 113 | | private IAvatar GetAvatarWithHologram() |
| | 114 | | { |
| 0 | 115 | | Visibility visibility = new Visibility(); |
| | 116 | |
|
| | 117 | | // Due to how we set our pools (and how the objets are cloned in), we might find that the original item alre |
| 0 | 118 | | baseAvatarReferences = baseAvatarContainer.GetComponentInChildren<IBaseAvatarReferences>() ?? Instantiate(ba |
| | 119 | |
|
| 0 | 120 | | return Environment.i.serviceLocator.Get<IAvatarFactory>() |
| | 121 | | .CreateAvatarWithHologram( |
| | 122 | | avatarContainer, |
| | 123 | | new BaseAvatar(baseAvatarReferences), |
| | 124 | | GetComponentInChildren<AvatarAnimatorLegacy>(), |
| | 125 | | new LOD(avatarContainer, visibility, avatarMovementController), |
| | 126 | | visibility |
| | 127 | | ); |
| | 128 | | } |
| | 129 | |
|
| | 130 | | private void Start() |
| | 131 | | { |
| 1 | 132 | | playerName = GetComponentInChildren<IPlayerName>(); |
| 1 | 133 | | playerName?.Hide(true); |
| 1 | 134 | | currentActiveModifiers ??= new BaseRefCounter<AvatarModifierAreaID>(); |
| 1 | 135 | | } |
| | 136 | |
|
| | 137 | | private void PlayerClicked() |
| | 138 | | { |
| 0 | 139 | | if (model == null) |
| 0 | 140 | | return; |
| | 141 | |
|
| 0 | 142 | | currentPlayerInfoCardId.Set((((AvatarModel)model).id, OPEN_PASSPORT_SOURCE)); |
| 0 | 143 | | } |
| | 144 | |
|
| | 145 | | public void OnDestroy() |
| | 146 | | { |
| 308 | 147 | | if (entity != null) |
| 0 | 148 | | DataStore.i.sceneBoundariesChecker?.Remove(entity, this); |
| | 149 | |
|
| 308 | 150 | | Cleanup(); |
| | 151 | |
|
| 308 | 152 | | if (poolableObject != null && poolableObject.isInsidePool) |
| 1 | 153 | | poolableObject.RemoveFromPool(); |
| 308 | 154 | | } |
| | 155 | |
|
| | 156 | | public override IEnumerator ApplyChanges(BaseModel newModel) |
| | 157 | | { |
| 1 | 158 | | isGlobalSceneAvatar = scene.sceneData.sceneNumber == EnvironmentSettings.AVATAR_GLOBAL_SCENE_NUMBER; |
| | 159 | |
|
| 1 | 160 | | var model = (AvatarModel)newModel; |
| 1 | 161 | | bool needsLoading = !model.HaveSameWearablesAndColors(currentAvatar); |
| 1 | 162 | | currentAvatar.CopyFrom(model); |
| | 163 | |
|
| 1 | 164 | | if (string.IsNullOrEmpty(model.bodyShape) || model.wearables.Count == 0) |
| 1 | 165 | | yield break; |
| | 166 | | #if UNITY_EDITOR |
| 0 | 167 | | gameObject.name = $"Avatar Shape {model.name}"; |
| | 168 | | #endif |
| 0 | 169 | | everythingIsLoaded = false; |
| | 170 | |
|
| | 171 | | bool avatarDone = false; |
| | 172 | | bool avatarFailed = false; |
| | 173 | |
|
| 0 | 174 | | yield return null; //NOTE(Brian): just in case we have a Object.Destroy waiting to be resolved. |
| | 175 | |
|
| | 176 | | // To deal with the cases in which the entity transform was configured before the AvatarShape |
| 0 | 177 | | if (!initializedPosition && scene.componentsManagerLegacy.HasComponent(entity, CLASS_ID_COMPONENT.TRANSFORM) |
| | 178 | | { |
| 0 | 179 | | initializedPosition = true; |
| | 180 | |
|
| 0 | 181 | | OnEntityTransformChanged(entity.gameObject.transform.localPosition, |
| | 182 | | entity.gameObject.transform.localRotation, true); |
| | 183 | | } |
| | 184 | |
|
| | 185 | | // NOTE: we subscribe here to transform changes since we might "lose" the message |
| | 186 | | // if we subscribe after a any yield |
| 0 | 187 | | entity.OnTransformChange -= OnEntityTransformChanged; |
| 0 | 188 | | entity.OnTransformChange += OnEntityTransformChanged; |
| | 189 | |
|
| 0 | 190 | | var wearableItems = model.wearables.ToList(); |
| 0 | 191 | | wearableItems.Add(model.bodyShape); |
| | 192 | |
|
| 0 | 193 | | if (avatar.status != IAvatar.Status.Loaded || needsLoading) |
| | 194 | | { |
| 0 | 195 | | HashSet<string> emotes = new HashSet<string>(currentAvatar.emotes.Select(x => x.urn)); |
| 0 | 196 | | UniTask<EmbeddedEmotesSO>.Awaiter embeddedEmotesTask = emotesCatalogService.Ref.GetEmbeddedEmotes().GetA |
| 0 | 197 | | yield return new WaitUntil(() => embeddedEmotesTask.IsCompleted); |
| 0 | 198 | | var embeddedEmoteIds = embeddedEmotesTask.GetResult().GetAllIds(); |
| | 199 | |
|
| | 200 | | //here we add emote ids to both new and old emote loading flow to merge the results later |
| | 201 | | //because some users might have emotes as wearables and others only as emotes |
| 0 | 202 | | foreach (var emoteId in embeddedEmoteIds) |
| | 203 | | { |
| 0 | 204 | | emotes.Add(emoteId); |
| 0 | 205 | | wearableItems.Add(emoteId); |
| | 206 | | } |
| | 207 | |
|
| | 208 | | //TODO Add Collider to the AvatarSystem |
| | 209 | | //TODO Without this the collider could get triggered disabling the avatar container, |
| | 210 | | // this would stop the loading process due to the underlying coroutines of the AssetLoader not starting |
| 0 | 211 | | avatarCollider.gameObject.SetActive(false); |
| | 212 | |
|
| 0 | 213 | | SetImpostor(model.id); |
| 0 | 214 | | loadingCts?.Cancel(); |
| 0 | 215 | | loadingCts?.Dispose(); |
| 0 | 216 | | loadingCts = new CancellationTokenSource(); |
| | 217 | |
|
| 0 | 218 | | if (DataStore.i.avatarConfig.useHologramAvatar.Get()) |
| | 219 | | { |
| 0 | 220 | | UserProfile profile = userProfileBridge.Get(model.id); |
| 0 | 221 | | playerName.SetName(model.name, profile?.hasClaimedName ?? false, profile?.isGuest ?? false); |
| 0 | 222 | | playerName.Show(true); |
| | 223 | | } |
| | 224 | |
|
| 0 | 225 | | var forceRender = new HashSet<string>(userProfileBridge.Get(model.id)?.avatar.forceRender ?? new HashSet |
| | 226 | |
|
| 0 | 227 | | var avatarSettings = new AvatarSettings |
| | 228 | | { |
| | 229 | | playerName = model.name, |
| | 230 | | bodyshapeId = model.bodyShape, |
| | 231 | | eyesColor = model.eyeColor, |
| | 232 | | skinColor = model.skinColor, |
| | 233 | | hairColor = model.hairColor, |
| | 234 | | forceRender = forceRender, |
| | 235 | | }; |
| | 236 | |
|
| 0 | 237 | | yield return avatar.Load(wearableItems, emotes.ToList(), avatarSettings, loadingCts.Token) |
| | 238 | | .ToCoroutine(e => |
| | 239 | | { |
| 0 | 240 | | if (e is not OperationCanceledException) |
| 0 | 241 | | throw e; |
| 0 | 242 | | }); |
| 0 | 243 | | } |
| | 244 | |
|
| 0 | 245 | | sceneEmoteHandler.SetExpressionLamportTimestamp(model.expressionTriggerTimestamp); |
| | 246 | |
|
| 0 | 247 | | if (sceneEmoteHandler.IsSceneEmote(model.expressionTriggerId)) |
| 0 | 248 | | sceneEmoteHandler |
| | 249 | | .LoadAndPlayEmote(model.bodyShape, model.expressionTriggerId) |
| | 250 | | .Forget(); |
| 0 | 251 | | else { avatar.GetEmotesController().PlayEmote(model.expressionTriggerId, model.expressionTriggerTimestamp); |
| | 252 | |
|
| 0 | 253 | | onPointerDown.OnPointerDownReport -= PlayerClicked; |
| 0 | 254 | | onPointerDown.OnPointerDownReport += PlayerClicked; |
| 0 | 255 | | onPointerDown.OnPointerEnterReport -= PlayerPointerEnter; |
| 0 | 256 | | onPointerDown.OnPointerEnterReport += PlayerPointerEnter; |
| 0 | 257 | | onPointerDown.OnPointerExitReport -= PlayerPointerExit; |
| 0 | 258 | | onPointerDown.OnPointerExitReport += PlayerPointerExit; |
| | 259 | |
|
| 0 | 260 | | outlineOnHover.OnPointerEnterReport -= PlayerPointerEnter; |
| 0 | 261 | | outlineOnHover.OnPointerEnterReport += PlayerPointerEnter; |
| 0 | 262 | | outlineOnHover.OnPointerExitReport -= PlayerPointerExit; |
| 0 | 263 | | outlineOnHover.OnPointerExitReport += PlayerPointerExit; |
| | 264 | |
|
| 0 | 265 | | UpdatePlayerStatus(model); |
| | 266 | |
|
| 0 | 267 | | onPointerDown.Initialize( |
| | 268 | | pointerEventModel, |
| | 269 | | entity, player |
| | 270 | | ); |
| | 271 | |
|
| 0 | 272 | | outlineOnHover.Initialize(entity, player?.avatar); |
| | 273 | |
|
| 0 | 274 | | avatarCollider.gameObject.SetActive(true); |
| | 275 | |
|
| 0 | 276 | | everythingIsLoaded = true; |
| 0 | 277 | | OnAvatarShapeUpdated?.Invoke(entity, this); |
| | 278 | |
|
| 0 | 279 | | onPointerDown.SetColliderEnabled(isGlobalSceneAvatar); |
| 0 | 280 | | onPointerDown.SetOnClickReportEnabled(isGlobalSceneAvatar); |
| 0 | 281 | | } |
| | 282 | |
|
| | 283 | | public void SetImpostor(string userId) |
| | 284 | | { |
| 0 | 285 | | currentLazyObserver?.RemoveListener(avatar.SetImpostorTexture); |
| | 286 | |
|
| 0 | 287 | | if (string.IsNullOrEmpty(userId)) |
| 0 | 288 | | return; |
| | 289 | |
|
| 0 | 290 | | UserProfile userProfile = UserProfileController.GetProfileByUserId(userId); |
| | 291 | |
|
| 0 | 292 | | if (userProfile == null) |
| 0 | 293 | | return; |
| | 294 | |
|
| 0 | 295 | | currentLazyObserver = userProfile.bodySnapshotObserver; |
| 0 | 296 | | currentLazyObserver.AddListener(avatar.SetImpostorTexture); |
| 0 | 297 | | } |
| | 298 | |
|
| | 299 | | private void PlayerPointerExit() |
| | 300 | | { |
| 0 | 301 | | playerName?.SetForceShow(false); |
| 0 | 302 | | } |
| | 303 | |
|
| | 304 | | private void PlayerPointerEnter() |
| | 305 | | { |
| 0 | 306 | | playerName?.SetForceShow(true); |
| 0 | 307 | | } |
| | 308 | |
|
| | 309 | | private void UpdatePlayerStatus(AvatarModel model) |
| | 310 | | { |
| | 311 | | // Remove the player status if the userId changes |
| 0 | 312 | | if (player != null && (player.id != model.id || player.name != model.name)) |
| 0 | 313 | | otherPlayers.Remove(player.id); |
| | 314 | |
|
| 0 | 315 | | if (isGlobalSceneAvatar && string.IsNullOrEmpty(model?.id)) |
| 0 | 316 | | return; |
| | 317 | |
|
| 0 | 318 | | bool isNew = player == null; |
| | 319 | |
|
| 0 | 320 | | if (isNew) { player = new Player(); } |
| | 321 | |
|
| 0 | 322 | | bool isNameDirty = player.name != model.name; |
| | 323 | |
|
| 0 | 324 | | player.id = model.id; |
| 0 | 325 | | player.name = model.name; |
| 0 | 326 | | player.isTalking = model.talking; |
| 0 | 327 | | player.worldPosition = entity.gameObject.transform.position; |
| 0 | 328 | | player.avatar = avatar; |
| 0 | 329 | | player.onPointerDownCollider = onPointerDown; |
| 0 | 330 | | player.collider = avatarCollider; |
| | 331 | |
|
| 0 | 332 | | if (isNew) |
| | 333 | | { |
| 0 | 334 | | player.playerName = playerName; |
| 0 | 335 | | player.playerName.Show(); |
| 0 | 336 | | player.anchorPoints = anchorPoints; |
| | 337 | |
|
| 0 | 338 | | if (isGlobalSceneAvatar) |
| | 339 | | { |
| | 340 | | // TODO: Note: This is having a problem, sometimes the users has been detected as new 2 times and it |
| | 341 | | // we should investigate this |
| 0 | 342 | | if (otherPlayers.ContainsKey(player.id)) |
| 0 | 343 | | otherPlayers.Remove(player.id); |
| | 344 | |
|
| 0 | 345 | | otherPlayers.Add(player.id, player); |
| | 346 | | } |
| | 347 | |
|
| 0 | 348 | | avatarReporterController.ReportAvatarRemoved(); |
| | 349 | | } |
| | 350 | |
|
| 0 | 351 | | avatarReporterController.SetUp(entity.scene.sceneData.sceneNumber, player.id); |
| | 352 | |
|
| 0 | 353 | | float height = AvatarSystemUtils.AVATAR_Y_OFFSET + avatar.extents.y; |
| | 354 | |
|
| 0 | 355 | | anchorPoints.Prepare(avatarContainer.transform, baseAvatarReferences.Anchors, height); |
| | 356 | |
|
| 0 | 357 | | player.playerName.SetIsTalking(model.talking); |
| 0 | 358 | | player.playerName.SetYOffset(Mathf.Max(MINIMUM_PLAYERNAME_HEIGHT, height)); |
| | 359 | |
|
| 0 | 360 | | if (isNameDirty) |
| | 361 | | { |
| 0 | 362 | | UserProfile profile = userProfileBridge.Get(model.id); |
| 0 | 363 | | player.playerName.SetName(model.name, profile?.hasClaimedName ?? false, profile?.isGuest ?? false); |
| | 364 | | } |
| 0 | 365 | | } |
| | 366 | |
|
| | 367 | | private void Update() |
| | 368 | | { |
| 1 | 369 | | if (player != null) |
| | 370 | | { |
| 0 | 371 | | player.worldPosition = entity.gameObject.transform.position; |
| 0 | 372 | | player.forwardDirection = entity.gameObject.transform.forward; |
| 0 | 373 | | avatarReporterController.ReportAvatarPosition(player.worldPosition); |
| | 374 | | } |
| 1 | 375 | | } |
| | 376 | |
|
| | 377 | | private void OnEntityTransformChanged(Vector3 newPosition, Quaternion newRotation) |
| | 378 | | { |
| 0 | 379 | | OnEntityTransformChanged(newPosition, newRotation, !initializedPosition); |
| 0 | 380 | | } |
| | 381 | |
|
| | 382 | | private void OnEntityTransformChanged(in Vector3 position, in Quaternion rotation, bool inmediate) |
| | 383 | | { |
| 0 | 384 | | if (isGlobalSceneAvatar) { avatarMovementController.OnTransformChanged(position, rotation, inmediate); } |
| | 385 | | else |
| | 386 | | { |
| 0 | 387 | | var scenePosition = Utils.GridToWorldPosition(entity.scene.sceneData.basePosition.x, entity.scene.sceneD |
| 0 | 388 | | avatarMovementController.OnTransformChanged(scenePosition + position, rotation, inmediate); |
| | 389 | | } |
| | 390 | |
|
| 0 | 391 | | initializedPosition = true; |
| 0 | 392 | | } |
| | 393 | |
|
| | 394 | | public override void OnPoolGet() |
| | 395 | | { |
| 1 | 396 | | base.OnPoolGet(); |
| | 397 | |
|
| 1 | 398 | | everythingIsLoaded = false; |
| 1 | 399 | | initializedPosition = false; |
| 1 | 400 | | model = new AvatarModel(); |
| 1 | 401 | | player = null; |
| 1 | 402 | | } |
| | 403 | |
|
| | 404 | | public void ApplyHideAvatarModifier() |
| | 405 | | { |
| 0 | 406 | | if (!currentActiveModifiers.ContainsKey(AvatarModifierAreaID.HIDE_AVATAR)) |
| | 407 | | { |
| 0 | 408 | | avatar.AddVisibilityConstraint(VISIBILITY_CONSTRAINT_HIDE_AREA); |
| 0 | 409 | | onPointerDown.gameObject.SetActive(false); |
| 0 | 410 | | playerNameContainer.SetActive(false); |
| 0 | 411 | | stickersControllers.ToggleHideArea(true); |
| | 412 | | } |
| | 413 | |
|
| 0 | 414 | | currentActiveModifiers.AddRefCount(AvatarModifierAreaID.HIDE_AVATAR); |
| 0 | 415 | | } |
| | 416 | |
|
| | 417 | | public void RemoveHideAvatarModifier() |
| | 418 | | { |
| 0 | 419 | | currentActiveModifiers.RemoveRefCount(AvatarModifierAreaID.HIDE_AVATAR); |
| | 420 | |
|
| 0 | 421 | | if (!currentActiveModifiers.ContainsKey(AvatarModifierAreaID.HIDE_AVATAR)) |
| | 422 | | { |
| 0 | 423 | | avatar.RemoveVisibilityConstrain(VISIBILITY_CONSTRAINT_HIDE_AREA); |
| 0 | 424 | | onPointerDown.gameObject.SetActive(true); |
| 0 | 425 | | playerNameContainer.SetActive(true); |
| 0 | 426 | | stickersControllers.ToggleHideArea(false); |
| | 427 | | } |
| 0 | 428 | | } |
| | 429 | |
|
| | 430 | | public void ApplyHidePassportModifier() |
| | 431 | | { |
| 0 | 432 | | if (!currentActiveModifiers.ContainsKey(AvatarModifierAreaID.DISABLE_PASSPORT)) { DisablePassport(); } |
| | 433 | |
|
| 0 | 434 | | currentActiveModifiers.AddRefCount(AvatarModifierAreaID.DISABLE_PASSPORT); |
| 0 | 435 | | } |
| | 436 | |
|
| | 437 | | public void RemoveHidePassportModifier() |
| | 438 | | { |
| 0 | 439 | | currentActiveModifiers.RemoveRefCount(AvatarModifierAreaID.DISABLE_PASSPORT); |
| | 440 | |
|
| 0 | 441 | | if (!currentActiveModifiers.ContainsKey(AvatarModifierAreaID.DISABLE_PASSPORT)) { EnablePasssport(); } |
| 0 | 442 | | } |
| | 443 | |
|
| | 444 | | private void EnablePasssport() |
| | 445 | | { |
| 0 | 446 | | if (onPointerDown.collider == null) |
| 0 | 447 | | return; |
| | 448 | |
|
| 0 | 449 | | onPointerDown.SetPassportEnabled(true); |
| 0 | 450 | | } |
| | 451 | |
|
| | 452 | | private void DisablePassport() |
| | 453 | | { |
| 0 | 454 | | if (onPointerDown.collider == null) |
| 0 | 455 | | return; |
| | 456 | |
|
| 0 | 457 | | onPointerDown.SetPassportEnabled(false); |
| 0 | 458 | | } |
| | 459 | |
|
| | 460 | | public override void Cleanup() |
| | 461 | | { |
| 310 | 462 | | base.Cleanup(); |
| | 463 | |
|
| 310 | 464 | | playerName?.Hide(true); |
| | 465 | |
|
| 310 | 466 | | if (player != null) |
| | 467 | | { |
| | 468 | | // AvatarShape used from the SDK doesn't register the avatars in 'otherPlayers' |
| 0 | 469 | | if (!string.IsNullOrEmpty(player.id)) |
| 0 | 470 | | otherPlayers.Remove(player.id); |
| | 471 | |
|
| 0 | 472 | | player = null; |
| | 473 | | } |
| | 474 | |
|
| 310 | 475 | | loadingCts?.Cancel(); |
| 310 | 476 | | loadingCts?.Dispose(); |
| 310 | 477 | | loadingCts = null; |
| 310 | 478 | | currentLazyObserver?.RemoveListener(avatar.SetImpostorTexture); |
| 310 | 479 | | avatar.Dispose(); |
| | 480 | |
|
| 313 | 481 | | if (poolableObject != null) { poolableObject.OnRelease -= Cleanup; } |
| | 482 | |
|
| 310 | 483 | | onPointerDown.OnPointerDownReport -= PlayerClicked; |
| 310 | 484 | | onPointerDown.OnPointerEnterReport -= PlayerPointerEnter; |
| 310 | 485 | | onPointerDown.OnPointerExitReport -= PlayerPointerExit; |
| 310 | 486 | | outlineOnHover.OnPointerEnterReport -= PlayerPointerEnter; |
| 310 | 487 | | outlineOnHover.OnPointerExitReport -= PlayerPointerExit; |
| | 488 | |
|
| 310 | 489 | | if (entity != null) |
| | 490 | | { |
| 1 | 491 | | entity.OnTransformChange = null; |
| 1 | 492 | | entity = null; |
| | 493 | | } |
| | 494 | |
|
| 310 | 495 | | avatarReporterController.ReportAvatarRemoved(); |
| 310 | 496 | | sceneEmoteHandler.CleanUp(); |
| 310 | 497 | | } |
| | 498 | |
|
| | 499 | | public void UpdateOutOfBoundariesState(bool isInsideBoundaries) |
| | 500 | | { |
| 0 | 501 | | if (scene.isPersistent) |
| 0 | 502 | | isInsideBoundaries = true; |
| | 503 | |
|
| 0 | 504 | | if (isInsideBoundaries) |
| 0 | 505 | | avatar.RemoveVisibilityConstrain(VISIBILITY_CONSTRAINT_OUTSIDE_SCENE_BOUNDS); |
| | 506 | | else |
| 0 | 507 | | avatar.AddVisibilityConstraint(VISIBILITY_CONSTRAINT_OUTSIDE_SCENE_BOUNDS); |
| | 508 | |
|
| 0 | 509 | | onPointerDown.gameObject.SetActive(isInsideBoundaries); |
| 0 | 510 | | playerNameContainer.SetActive(isInsideBoundaries); |
| 0 | 511 | | stickersControllers.ToggleHideArea(!isInsideBoundaries); |
| 0 | 512 | | } |
| | 513 | |
|
| | 514 | | public override int GetClassId() |
| | 515 | | { |
| 1 | 516 | | return (int)CLASS_ID_COMPONENT.AVATAR_SHAPE; |
| | 517 | | } |
| | 518 | |
|
| | 519 | | [ContextMenu("Print current profile")] |
| | 520 | | private void PrintCurrentProfile() |
| | 521 | | { |
| 0 | 522 | | Debug.Log(JsonUtility.ToJson(model)); |
| 0 | 523 | | } |
| | 524 | | } |
| | 525 | | } |