| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class VoiceChatBarComponentView : BaseComponentView, IVoiceChatBarComponentView, IComponentModelConfig |
| | 6 | | { |
| | 7 | | [Header("Prefab References")] |
| | 8 | | [SerializeField] internal VoiceChatButton voiceChatButton; |
| | 9 | | [SerializeField] internal GameObject someoneTalkingContainer; |
| | 10 | | [SerializeField] internal TMP_Text someoneTalkingText; |
| | 11 | | [SerializeField] internal TMP_Text altText; |
| | 12 | | [SerializeField] internal Animator someoneTalkingAnimator; |
| | 13 | | [SerializeField] internal ButtonComponentView endCallButton; |
| | 14 | |
|
| | 15 | | [Header("Configuration")] |
| | 16 | | [SerializeField] internal VoiceChatBarComponentModel model; |
| | 17 | |
|
| | 18 | | public event Action<bool> OnMuteVoiceChat; |
| | 19 | | public event Action OnLeaveVoiceChat; |
| | 20 | |
|
| 0 | 21 | | public RectTransform Transform => (RectTransform)transform; |
| | 22 | |
|
| | 23 | | public override void Awake() |
| | 24 | | { |
| 5 | 25 | | base.Awake(); |
| | 26 | |
|
| 5 | 27 | | endCallButton.onClick.AddListener(() => OnLeaveVoiceChat?.Invoke()); |
| 5 | 28 | | } |
| | 29 | |
|
| | 30 | | public void Configure(BaseComponentModel newModel) |
| | 31 | | { |
| 1 | 32 | | model = (VoiceChatBarComponentModel)newModel; |
| 1 | 33 | | RefreshControl(); |
| 1 | 34 | | } |
| | 35 | |
|
| | 36 | | public override void RefreshControl() |
| | 37 | | { |
| 1 | 38 | | if (model == null) |
| 0 | 39 | | return; |
| | 40 | |
|
| 1 | 41 | | SetTalkingMessage(model.isSomeoneTalking, model.message); |
| 1 | 42 | | } |
| | 43 | |
|
| 2 | 44 | | public override void Show(bool instant = false) { gameObject.SetActive(true); } |
| | 45 | |
|
| 2 | 46 | | public override void Hide(bool instant = false) { gameObject.SetActive(false); } |
| | 47 | |
|
| | 48 | | public void SetTalkingMessage(bool isSomeoneTalking, string message) |
| | 49 | | { |
| 3 | 50 | | model.message = message; |
| | 51 | |
|
| 3 | 52 | | if (someoneTalkingContainer != null) |
| 3 | 53 | | someoneTalkingContainer.SetActive(isSomeoneTalking); |
| | 54 | |
|
| 3 | 55 | | if (altText != null) |
| 3 | 56 | | altText.gameObject.SetActive(!isSomeoneTalking); |
| | 57 | |
|
| 3 | 58 | | if (isSomeoneTalking) |
| | 59 | | { |
| 1 | 60 | | if (someoneTalkingText != null) |
| | 61 | | { |
| 1 | 62 | | someoneTalkingText.text = message; |
| 1 | 63 | | someoneTalkingAnimator.SetBool("Talking", !string.IsNullOrEmpty(message)); |
| | 64 | | } |
| 1 | 65 | | } |
| | 66 | | else |
| | 67 | | { |
| 2 | 68 | | if (altText != null) |
| 2 | 69 | | altText.text = message; |
| | 70 | | } |
| 2 | 71 | | } |
| | 72 | |
|
| 0 | 73 | | public void PlayVoiceChatRecordingAnimation(bool recording) { voiceChatButton.SetOnRecording(recording); } |
| | 74 | |
|
| 0 | 75 | | public void SetVoiceChatEnabledByScene(bool enabled) { voiceChatButton.SetEnabledByScene(enabled); } |
| | 76 | |
|
| | 77 | | public override void Dispose() |
| | 78 | | { |
| 10 | 79 | | base.Dispose(); |
| | 80 | |
|
| 10 | 81 | | endCallButton.onClick.RemoveAllListeners(); |
| 10 | 82 | | } |
| | 83 | |
|
| | 84 | | internal static VoiceChatBarComponentView Create() |
| | 85 | | { |
| 0 | 86 | | VoiceChatBarComponentView voiceChatBarComponentView = Instantiate(Resources.Load<GameObject>("SocialBarV1/VoiceC |
| 0 | 87 | | voiceChatBarComponentView.name = "_VoiceChatBar"; |
| | 88 | |
|
| 0 | 89 | | return voiceChatBarComponentView; |
| | 90 | | } |
| | 91 | | } |