| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.Serialization; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public class EmotesHUDView : MonoBehaviour |
| | 7 | | { |
| | 8 | | private const string PATH = "EmotesHUD"; |
| | 9 | |
|
| | 10 | | public delegate void ExpressionClicked(string expressionId); |
| | 11 | | public event Action OnClose; |
| | 12 | |
|
| | 13 | | [Serializable] |
| | 14 | | public class ButtonToEmote |
| | 15 | | { |
| | 16 | | public string expressionId; |
| | 17 | | public Button_OnPointerDown button; // When the button is used to lock/unlock the mouse we have to use onPointer |
| | 18 | | } |
| | 19 | |
|
| | 20 | | [SerializeField] internal ButtonToEmote[] buttonToEmotesMap; |
| | 21 | | [SerializeField] internal Button_OnPointerDown[] closeButtons; |
| | 22 | | [SerializeField] internal RawImage avatarPic; |
| | 23 | |
|
| 6 | 24 | | public static EmotesHUDView Create() { return Instantiate(Resources.Load<GameObject>(PATH)).GetComponent<EmotesHUDVi |
| | 25 | |
|
| | 26 | | private void Awake() |
| | 27 | | { |
| 36 | 28 | | for (int i = 0; i < closeButtons.Length; i++) |
| | 29 | | { |
| 12 | 30 | | closeButtons[i].onPointerDown += Close; |
| | 31 | | } |
| 6 | 32 | | } |
| | 33 | |
|
| | 34 | | internal void Initialize(ExpressionClicked clickedDelegate) |
| | 35 | | { |
| 112 | 36 | | foreach (var buttonToExpression in buttonToEmotesMap) |
| | 37 | | { |
| 51 | 38 | | buttonToExpression.button.onPointerDown += () => clickedDelegate?.Invoke(buttonToExpression.expressionId); |
| | 39 | | } |
| 7 | 40 | | } |
| | 41 | |
|
| | 42 | | public void UpdateAvatarSprite(Texture2D avatarTexture) |
| | 43 | | { |
| 0 | 44 | | if (avatarTexture == null) |
| 0 | 45 | | return; |
| | 46 | |
|
| 0 | 47 | | avatarPic.texture = avatarTexture; |
| 0 | 48 | | } |
| | 49 | |
|
| | 50 | | public void SetVisiblity(bool visible) |
| | 51 | | { |
| 8 | 52 | | gameObject.SetActive(visible); |
| 8 | 53 | | if (visible) |
| 1 | 54 | | AudioScriptableObjects.dialogOpen.Play(true); |
| | 55 | | else |
| 7 | 56 | | AudioScriptableObjects.dialogClose.Play(true); |
| 7 | 57 | | } |
| | 58 | |
|
| 0 | 59 | | private void Close() { OnClose?.Invoke(); } |
| 12 | 60 | | public void OnDestroy() { CleanUp(); } |
| | 61 | |
|
| | 62 | | public void CleanUp() |
| | 63 | | { |
| 72 | 64 | | for (int i = 0; i < closeButtons.Length; i++) |
| | 65 | | { |
| 24 | 66 | | closeButtons[i].onPointerDown -= Close; |
| | 67 | | } |
| 12 | 68 | | } |
| | 69 | | } |