| | 1 | | using DCL; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | | using TMPro; |
| | 5 | |
|
| | 6 | | internal class ExploreFriendsView : MonoBehaviour |
| | 7 | | { |
| | 8 | | [SerializeField] RawImage friendPortrait; |
| | 9 | | [SerializeField] Image friendBackground; |
| | 10 | | [SerializeField] ShowHideAnimator showHideAnimator; |
| | 11 | | [SerializeField] TextMeshProUGUI friendName; |
| | 12 | | [SerializeField] UIHoverCallback hoverCallback; |
| | 13 | |
|
| | 14 | | UserProfile userProfile; |
| | 15 | |
|
| | 16 | | public void SetUserProfile(UserProfile profile, Color backgroundColor) |
| | 17 | | { |
| 2 | 18 | | userProfile = profile; |
| 2 | 19 | | friendName.text = profile.userName; |
| 2 | 20 | | friendBackground.color = backgroundColor; |
| 2 | 21 | | userProfile.snapshotObserver.AddListener(OnFaceSnapshotLoaded); |
| 2 | 22 | | gameObject.SetActive(true); |
| 2 | 23 | | } |
| | 24 | |
|
| | 25 | | void OnFaceSnapshotLoaded(Texture2D texture) |
| | 26 | | { |
| 0 | 27 | | friendPortrait.texture = texture; |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | void OnHeadHoverEnter() |
| | 31 | | { |
| 0 | 32 | | if (!userProfile) |
| 0 | 33 | | return; |
| | 34 | |
|
| 0 | 35 | | if (!showHideAnimator.gameObject.activeSelf) |
| 0 | 36 | | showHideAnimator.gameObject.SetActive(true); |
| | 37 | |
|
| 0 | 38 | | showHideAnimator.Show(); |
| 0 | 39 | | } |
| | 40 | |
|
| 0 | 41 | | void OnHeadHoverExit() { showHideAnimator.Hide(); } |
| | 42 | |
|
| | 43 | | void Awake() |
| | 44 | | { |
| 2 | 45 | | hoverCallback.OnPointerEnter += OnHeadHoverEnter; |
| 2 | 46 | | hoverCallback.OnPointerExit += OnHeadHoverExit; |
| 2 | 47 | | showHideAnimator.gameObject.SetActive(false); |
| 2 | 48 | | } |
| | 49 | |
|
| | 50 | | void OnDestroy() |
| | 51 | | { |
| 2 | 52 | | if (userProfile != null) |
| 2 | 53 | | userProfile.snapshotObserver.RemoveListener(OnFaceSnapshotLoaded); |
| | 54 | |
|
| 2 | 55 | | if (hoverCallback) |
| | 56 | | { |
| 2 | 57 | | hoverCallback.OnPointerEnter -= OnHeadHoverEnter; |
| 2 | 58 | | hoverCallback.OnPointerExit -= OnHeadHoverExit; |
| | 59 | | } |
| 2 | 60 | | } |
| | 61 | | } |