| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class ExpressionsHUDController : IHUD |
| | 6 | | { |
| | 7 | | internal ExpressionsHUDView view; |
| | 8 | |
|
| 22 | 9 | | private UserProfile ownUserProfile => UserProfile.GetOwnUserProfile(); |
| | 10 | |
|
| 7 | 11 | | public ExpressionsHUDController() |
| | 12 | | { |
| 7 | 13 | | view = ExpressionsHUDView.Create(); |
| 7 | 14 | | view.Initialize(ExpressionCalled); |
| | 15 | |
|
| 7 | 16 | | ownUserProfile.OnAvatarExpressionSet += OnAvatarExpressionSet; |
| 7 | 17 | | } |
| | 18 | |
|
| | 19 | | public void SetVisibility(bool visible) |
| | 20 | | { |
| 1 | 21 | | view.SetVisiblity(visible); |
| | 22 | |
|
| 1 | 23 | | if ( visible ) |
| | 24 | | { |
| 1 | 25 | | ownUserProfile.snapshotObserver.AddListener(view.UpdateAvatarSprite); |
| 1 | 26 | | } |
| | 27 | | else |
| | 28 | | { |
| 0 | 29 | | ownUserProfile.snapshotObserver.RemoveListener(view.UpdateAvatarSprite); |
| | 30 | | } |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | public void Dispose() |
| | 34 | | { |
| 7 | 35 | | ownUserProfile.snapshotObserver.RemoveListener(view.UpdateAvatarSprite); |
| 7 | 36 | | ownUserProfile.OnAvatarExpressionSet -= OnAvatarExpressionSet; |
| | 37 | |
|
| 7 | 38 | | if (view != null) |
| | 39 | | { |
| 7 | 40 | | view.CleanUp(); |
| 7 | 41 | | UnityEngine.Object.Destroy(view.gameObject); |
| | 42 | | } |
| 7 | 43 | | } |
| | 44 | |
|
| 4 | 45 | | public void ExpressionCalled(string id) { UserProfile.GetOwnUserProfile().SetAvatarExpression(id); } |
| | 46 | |
|
| | 47 | | private void OnAvatarExpressionSet(string id, long timestamp) |
| | 48 | | { |
| 2 | 49 | | if (view.IsContentVisible()) |
| | 50 | | { |
| 0 | 51 | | view.HideContent(); |
| | 52 | | } |
| 2 | 53 | | } |
| | 54 | | } |