Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed Captioning system for SFX #498

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Use captioning from settings in the game.
  • Loading branch information
codeedward committed Sep 4, 2021
commit dd4edfe3d2b13792ad96cb0b3346f0defd825cc0
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh-81552
m_Name: 9a2333a5072248ea8967890cf9726479
serializedVersion: 10
m_SubMeshes:
- serializedVersion: 2
6 changes: 6 additions & 0 deletions UOP1_Project/Assets/Scenes/Managers/Gameplay.unity
Original file line number Diff line number Diff line change
@@ -332,6 +332,12 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: -222.5
objectReference: {fileID: 0}
- target: {fileID: 1461259458714161823, guid: cef07ea384e17ef4bb3abfbd08391f33,
type: 3}
propertyPath: _changeCaptioningEventChannel
value:
objectReference: {fileID: 11400000, guid: bff9c33f31ada7642b239acd0515ac8b,
type: 2}
- target: {fileID: 1915849195831296150, guid: cef07ea384e17ef4bb3abfbd08391f33,
type: 3}
propertyPath: m_AnchorMax.y
4 changes: 4 additions & 0 deletions UOP1_Project/Assets/Scenes/Managers/PersistentManagers.unity
Original file line number Diff line number Diff line change
@@ -482,6 +482,8 @@ MonoBehaviour:
_pool: {fileID: 11400000, guid: db3212ef0dc655a439b72b3b1c02b172, type: 2}
_initialSize: 10
_SFXEventChannel: {fileID: 11400000, guid: c3c796b7c31ad3647a3fbae42e74764e, type: 2}
_changeCaptioningEventChannel: {fileID: 11400000, guid: bff9c33f31ada7642b239acd0515ac8b,
type: 2}
--- !u!4 &888255708
Transform:
m_ObjectHideFlags: 0
@@ -820,6 +822,8 @@ MonoBehaviour:
type: 2}
_changeMusicVolumeEventChannel: {fileID: 11400000, guid: 13e4f5dfe966e1447ba01306e125c0c0,
type: 2}
_changeCaptioningEventChannel: {fileID: 11400000, guid: bff9c33f31ada7642b239acd0515ac8b,
type: 2}
--- !u!1 &1492261400
GameObject:
m_ObjectHideFlags: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3177d113f09ae42448cde1e1a5067d4f, type: 3}
m_Name: ChangeCaptioningIsEnable_Channel
m_EditorClassIdentifier:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 26 additions & 12 deletions UOP1_Project/Assets/Scripts/Captioning/ClosedCaptioningManger.cs
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@ public class ClosedCaptioningManger : MonoBehaviour
[Header("Listening on channels")]
[Tooltip("The ClosedCaptioningManger listens to this event, fired by objects in any scene, to display text for the SFXs")]
[SerializeField] private AudioCueEventChannelSO _SFXEventChannel = default;
[Tooltip("The ClosedCaptioningManger listens to this event, fired by settings menu or SettingsSystem initializator, to turn on/off captioning")]
[SerializeField] private BoolEventChannelSO _changeCaptioningEventChannel = default;

private bool _isCaptioningEnabled = default;

private void Awake()
{
@@ -24,31 +28,36 @@ private void Awake()
private void OnEnable()
{
_SFXEventChannel.OnAudioCuePlayRequested += DisplayCaption;
_changeCaptioningEventChannel.OnEventRaised += OnChangeCaptioning;
}

private void OnDestroy()
{
_SFXEventChannel.OnAudioCuePlayRequested -= DisplayCaption;
_changeCaptioningEventChannel.OnEventRaised -= OnChangeCaptioning;
}

public AudioCueKey DisplayCaption(AudioCueSO audioCue, AudioConfigurationSO settings, Vector3 position = default)
{
VisualisableAudioClip[] clipsToPlay = audioCue.GetClips();
CaptionEmitter[] captionEmitterArray = new CaptionEmitter[clipsToPlay.Length];

int nOfClips = clipsToPlay.Length;
for (int i = 0; i < nOfClips; i++)
if (_isCaptioningEnabled)
{
var currentAudioCaption = clipsToPlay[i].Caption;
if (currentAudioCaption.Visualise && !audioCue.looping)
VisualisableAudioClip[] clipsToPlay = audioCue.GetClips();
CaptionEmitter[] captionEmitterArray = new CaptionEmitter[clipsToPlay.Length];

int nOfClips = clipsToPlay.Length;
for (int i = 0; i < nOfClips; i++)
{
captionEmitterArray[i] = _pool.Request();
if (captionEmitterArray[i] != null)
var currentAudioCaption = clipsToPlay[i].Caption;
if (currentAudioCaption.Visualise && !audioCue.looping)
{
captionEmitterArray[i].Display(currentAudioCaption, position);
StartCoroutine(CleanEmitter(captionEmitterArray[i], currentAudioCaption.Duration));
captionEmitterArray[i] = _pool.Request();
if (captionEmitterArray[i] != null)
{
captionEmitterArray[i].Display(currentAudioCaption, position);
StartCoroutine(CleanEmitter(captionEmitterArray[i], currentAudioCaption.Duration));
}
}
}
}
}

return default;
@@ -59,5 +68,10 @@ private IEnumerator CleanEmitter(CaptionEmitter captionEmitter, float duration)
yield return new WaitForSeconds(duration);
_pool.Return(captionEmitter);
}

private void OnChangeCaptioning(bool isCaptioningEnabled)
{
_isCaptioningEnabled = isCaptioningEnabled;
}
}
}
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ public class SettingsSystem : MonoBehaviour
[SerializeField] private FloatEventChannelSO _changeMasterVolumeEventChannel = default;
[SerializeField] private FloatEventChannelSO _changeSFXVolumeEventChannel = default;
[SerializeField] private FloatEventChannelSO _changeMusicVolumeEventChannel = default;
[SerializeField] private BoolEventChannelSO _changeCaptioningEventChannel = default;

private void Awake()
{
@@ -45,6 +46,7 @@ void SetCurrentSettings()
_urpAsset.msaaSampleCount = _currentSettings.AntiAliasingIndex;

LocalizationSettings.SelectedLocale = _currentSettings.CurrentLocale;
_changeCaptioningEventChannel.RaiseEvent(_currentSettings.IsCaptioningEnabled);
}
void SaveSettings()
{
Original file line number Diff line number Diff line change
@@ -52,7 +52,9 @@ public class UISettingsController : MonoBehaviour
private SettingsType _selectedTab = SettingsType.Audio;
[SerializeField] private InputReader _inputReader = default;
[SerializeField] private VoidEventChannelSO SaveSettingsEvent = default;
[SerializeField] private BoolEventChannelSO _changeCaptioningEventChannel = default;
public UnityAction Closed;

private void OnEnable()
{
_languageComponent._save += SaveLaguageSettings;
@@ -135,6 +137,7 @@ void SwitchTab(float orientation)
public void SaveLaguageSettings(Locale local, bool isCaptioningEnabled)
{
_currentSettings.SaveLanguageSettings(local, isCaptioningEnabled);
_changeCaptioningEventChannel.RaiseEvent(isCaptioningEnabled);
SaveSettingsEvent.RaiseEvent();
}
public void SaveGraphicsSettings(int newResolutionsIndex, int newAntiAliasingIndex, float newShadowDistance, bool fullscreenState)