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