| | 1 | | using System; |
| | 2 | |
|
| | 3 | | public class ExpressionsHUDController : IHUD |
| | 4 | | { |
| | 5 | | internal ExpressionsHUDView view; |
| 35 | 6 | | private UserProfile ownUserProfile => UserProfile.GetOwnUserProfile(); |
| | 7 | | private Action<UserProfile> userProfileUpdateDelegate; |
| | 8 | |
|
| 7 | 9 | | public ExpressionsHUDController() |
| | 10 | | { |
| 7 | 11 | | view = ExpressionsHUDView.Create(); |
| 7 | 12 | | view.Initialize(ExpressionCalled); |
| 16 | 13 | | userProfileUpdateDelegate = profile => view.UpdateAvatarSprite(profile.faceSnapshot); |
| 7 | 14 | | userProfileUpdateDelegate.Invoke(ownUserProfile); |
| 7 | 15 | | ownUserProfile.OnUpdate += userProfileUpdateDelegate; |
| 7 | 16 | | ownUserProfile.OnAvatarExpressionSet += OnAvatarExpressionSet; |
| 7 | 17 | | } |
| | 18 | |
|
| 2 | 19 | | public void SetVisibility(bool visible) { view.SetVisiblity(visible); } |
| | 20 | |
|
| | 21 | | public void Dispose() |
| | 22 | | { |
| 7 | 23 | | ownUserProfile.OnUpdate -= userProfileUpdateDelegate; |
| 7 | 24 | | ownUserProfile.OnAvatarExpressionSet -= OnAvatarExpressionSet; |
| | 25 | |
|
| 7 | 26 | | if (view != null) |
| | 27 | | { |
| 7 | 28 | | view.CleanUp(); |
| 7 | 29 | | UnityEngine.Object.Destroy(view.gameObject); |
| | 30 | | } |
| 7 | 31 | | } |
| | 32 | |
|
| 4 | 33 | | public void ExpressionCalled(string id) { UserProfile.GetOwnUserProfile().SetAvatarExpression(id); } |
| | 34 | |
|
| | 35 | | private void OnAvatarExpressionSet(string id, long timestamp) |
| | 36 | | { |
| 2 | 37 | | if (view.IsContentVisible()) |
| | 38 | | { |
| 0 | 39 | | view.HideContent(); |
| | 40 | | } |
| 2 | 41 | | } |
| | 42 | | } |