| | 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 | | bool IsInvisible { get; } |
| | 20 | | } |
| | 21 | |
|
| | 22 | | public class AvatarLODController : IAvatarLODController |
| | 23 | | { |
| | 24 | | private const string VISIBILITY_CONSTRAIN = "behind_camera_or_out_of_limits"; |
| 148 | 25 | | public Player player { get; } |
| | 26 | |
|
| 5 | 27 | | public bool IsInvisible { get; private set; } |
| | 28 | |
|
| 25 | 29 | | public AvatarLODController(Player player) |
| | 30 | | { |
| 25 | 31 | | this.player = player; |
| 25 | 32 | | player?.avatar?.SetLODLevel(0); |
| 22 | 33 | | } |
| | 34 | |
|
| | 35 | | public void SetLOD0() => |
| 30 | 36 | | SetLODLevel(0, setPointerColliderEnabled: true); |
| | 37 | |
|
| | 38 | | public void SetLOD1() => |
| 2 | 39 | | SetLODLevel(1, setPointerColliderEnabled: true); |
| | 40 | |
|
| | 41 | | public void SetLOD2() => |
| 2 | 42 | | SetLODLevel(2, setPointerColliderEnabled: false); |
| | 43 | |
|
| | 44 | | private void SetLODLevel(int level, bool setPointerColliderEnabled) |
| | 45 | | { |
| 34 | 46 | | if (player?.avatar == null) |
| 30 | 47 | | return; |
| | 48 | |
|
| 4 | 49 | | player.onPointerDownCollider.SetColliderEnabled(setPointerColliderEnabled); |
| 4 | 50 | | player.avatar.SetLODLevel(level); |
| 4 | 51 | | player.avatar.RemoveVisibilityConstrain(VISIBILITY_CONSTRAIN); |
| | 52 | |
|
| 4 | 53 | | IsInvisible = false; |
| 4 | 54 | | } |
| | 55 | |
|
| | 56 | | public void SetInvisible() |
| | 57 | | { |
| 1 | 58 | | if (player?.avatar == null) |
| 0 | 59 | | return; |
| | 60 | |
|
| 1 | 61 | | player.avatar.AddVisibilityConstraint(VISIBILITY_CONSTRAIN); |
| 1 | 62 | | player.onPointerDownCollider.SetColliderEnabled(false); |
| 1 | 63 | | IsInvisible = true; |
| 1 | 64 | | } |
| | 65 | |
|
| | 66 | | public void SetAnimationThrottling(int framesBetweenUpdates) => |
| 24 | 67 | | player?.avatar?.SetAnimationThrottling(framesBetweenUpdates); |
| | 68 | |
|
| | 69 | | public void SetNameVisible(bool visible) |
| | 70 | | { |
| 24 | 71 | | if (visible) |
| 10 | 72 | | player?.playerName.Show(); |
| | 73 | | else |
| 14 | 74 | | player?.playerName.Hide(); |
| 14 | 75 | | } |
| | 76 | |
|
| | 77 | | public void UpdateImpostorTint(float distanceToMainPlayer) => |
| 0 | 78 | | player?.avatar?.SetImpostorTint(AvatarRendererHelpers.CalculateImpostorTint(distanceToMainPlayer)); |
| | 79 | |
|
| 3 | 80 | | public void Dispose() { } |
| | 81 | | } |
| | 82 | | } |