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