| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL |
| | 6 | | { |
| | 7 | | //TODO Rename to IAvatar (not now to avoid conflicts) |
| | 8 | | public interface IAvatarLODController : IDisposable |
| | 9 | | { |
| | 10 | | Player player { get; } |
| | 11 | | void SetLOD0(); |
| | 12 | | void SetLOD1(); |
| | 13 | | void SetLOD2(); |
| | 14 | | public void SetAnimationThrottling(int framesBetweenUpdates); |
| | 15 | | void SetInvisible(); |
| | 16 | | void UpdateImpostorTint(float distanceToMainPlayer); |
| | 17 | | void SetNameVisible(bool visible); |
| | 18 | | } |
| | 19 | |
|
| | 20 | | public class AvatarLODController : IAvatarLODController |
| | 21 | | { |
| 28 | 22 | | private string VISIBILITY_CONSTRAIN = "behind_camera_or_out_of_limits"; |
| 46 | 23 | | public Player player { get; } |
| | 24 | |
|
| 28 | 25 | | public AvatarLODController(Player player) |
| | 26 | | { |
| 28 | 27 | | this.player = player; |
| 28 | 28 | | if (player?.avatar == null) |
| 6 | 29 | | return; |
| 22 | 30 | | player.avatar.SetLODLevel(0); |
| 22 | 31 | | } |
| | 32 | |
|
| | 33 | | public void SetLOD0() |
| | 34 | | { |
| 24 | 35 | | if (player?.avatar == null) |
| 22 | 36 | | return; |
| | 37 | |
|
| 2 | 38 | | player.onPointerDownCollider.SetColliderEnabled(true); |
| 2 | 39 | | player.avatar.SetLODLevel(0); |
| 2 | 40 | | player.avatar.RemoveVisibilityConstrain(VISIBILITY_CONSTRAIN); |
| 2 | 41 | | } |
| | 42 | |
|
| | 43 | | public void SetLOD1() |
| | 44 | | { |
| 2 | 45 | | if (player?.avatar == null) |
| 1 | 46 | | return; |
| | 47 | |
|
| 1 | 48 | | player.onPointerDownCollider.SetColliderEnabled(true); |
| 1 | 49 | | player.avatar.SetLODLevel(1); |
| 1 | 50 | | player.avatar.RemoveVisibilityConstrain(VISIBILITY_CONSTRAIN); |
| 1 | 51 | | } |
| | 52 | |
|
| | 53 | | public void SetLOD2() |
| | 54 | | { |
| 2 | 55 | | if (player?.avatar == null) |
| 1 | 56 | | return; |
| | 57 | |
|
| 1 | 58 | | player.onPointerDownCollider.SetColliderEnabled(false); |
| 1 | 59 | | player.avatar.SetLODLevel(2); |
| 1 | 60 | | player.avatar.RemoveVisibilityConstrain(VISIBILITY_CONSTRAIN); |
| 1 | 61 | | } |
| | 62 | |
|
| | 63 | | public void SetInvisible() |
| | 64 | | { |
| 6 | 65 | | if (player?.avatar == null) |
| 5 | 66 | | return; |
| | 67 | |
|
| 1 | 68 | | player.avatar.AddVisibilityConstrain(VISIBILITY_CONSTRAIN); |
| 1 | 69 | | player.onPointerDownCollider.SetColliderEnabled(false); |
| 1 | 70 | | } |
| | 71 | |
|
| | 72 | | public void SetAnimationThrottling(int framesBetweenUpdates) |
| | 73 | | { |
| 21 | 74 | | if (player?.avatar == null) |
| 21 | 75 | | return; |
| | 76 | |
|
| 0 | 77 | | player.avatar.SetAnimationThrottling(framesBetweenUpdates); |
| 0 | 78 | | } |
| | 79 | |
|
| | 80 | | public void SetNameVisible(bool visible) |
| | 81 | | { |
| 26 | 82 | | if (visible) |
| 9 | 83 | | player?.playerName.Show(); |
| | 84 | | else |
| 17 | 85 | | player?.playerName.Hide(); |
| 17 | 86 | | } |
| | 87 | | public void UpdateImpostorTint(float distanceToMainPlayer) |
| | 88 | | { |
| 0 | 89 | | if (player?.avatar == null) |
| 0 | 90 | | return; |
| | 91 | |
|
| 0 | 92 | | player.avatar.SetImpostorTint(AvatarRendererHelpers.CalculateImpostorTint(distanceToMainPlayer)); |
| 0 | 93 | | } |
| | 94 | |
|
| 6 | 95 | | public void Dispose() { } |
| | 96 | | } |
| | 97 | | } |