-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSubtitleTrackMixer.cs
38 lines (29 loc) · 1.1 KB
/
SubtitleTrackMixer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using TMPro;
public class SubtitleTrackMixer : PlayableBehaviour
{
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
TextMeshProUGUI text = playerData as TextMeshProUGUI;
string currentText = "";
float currentAlpha = 0f;
if (!text) { return; }
int inputCount = playable.GetInputCount();
for (int i = 0; i < inputCount; i++)
{
float inputWeight = playable.GetInputWeight(i);
if(inputWeight > 0f)
{
ScriptPlayable<SubtitleBehaviour> inputPlayable = (ScriptPlayable<SubtitleBehaviour>)playable.GetInput(i);
SubtitleBehaviour input = inputPlayable.GetBehaviour();
currentText = input.subtitleText;
currentAlpha = inputWeight;
}
}
text.text = currentText;
text.color = new Color(1, 1, 1, currentAlpha);
}
}