add Lyrics support
This commit is contained in:
@@ -17,6 +17,12 @@ public class UmaCharaData
|
||||
public string tail_model_id;
|
||||
}
|
||||
|
||||
public class UmaLyricsData
|
||||
{
|
||||
public float time;
|
||||
public string text;
|
||||
}
|
||||
|
||||
public enum UmaFileType
|
||||
{
|
||||
_3d_cutt,
|
||||
|
||||
@@ -28,6 +28,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
public UmaContainer CurrentOtherContainer;
|
||||
|
||||
public List<AudioSource> CurrentAudioSources = new List<AudioSource>();
|
||||
public List<UmaLyricsData> CurrentLyrics = new List<UmaLyricsData>();
|
||||
|
||||
public AnimatorOverrideController OverrideController;
|
||||
|
||||
@@ -381,20 +382,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
string lyricsVar = $"live/musicscores/m{songid}/m{songid}_lyrics";
|
||||
UmaDatabaseEntry lyricsAsset = Main.AbList.FirstOrDefault(a => a.Name.Contains(nameVar));
|
||||
if(lyricsAsset != null)
|
||||
{
|
||||
string filePath = GetABPath(lyricsAsset);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
AssetBundle bundle = AssetBundle.LoadFromFile(filePath);
|
||||
Main.LoadedBundles.Add(lyricsAsset.Name, bundle);
|
||||
UI.LoadedAssetsAdd(lyricsAsset);
|
||||
TextAsset asset = bundle.LoadAsset<TextAsset>(Path.GetFileName(lyricsVar));
|
||||
Debug.Log(asset.text);
|
||||
}
|
||||
}
|
||||
LoadLiveLyrics(songid);
|
||||
}
|
||||
|
||||
private void AddAudioSource(AudioClip clip)
|
||||
@@ -435,7 +423,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
int sampleRate = stream.WaveFormat.SampleRate;
|
||||
|
||||
AudioClip clip = AudioClip.Create(
|
||||
Path.GetFileName(awb.Name).Replace(".awb", wave.WaveId.ToString()),
|
||||
Path.GetFileNameWithoutExtension(awb.Name)+"_"+wave.WaveId.ToString(),
|
||||
(int)(stream.Length / channels / bytesPerSample),
|
||||
channels,
|
||||
sampleRate,
|
||||
@@ -447,8 +435,37 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
|
||||
return clips;
|
||||
}
|
||||
|
||||
|
||||
public void LoadLiveLyrics(int songid)
|
||||
{
|
||||
if (CurrentLyrics.Count > 0) CurrentLyrics.Clear();
|
||||
|
||||
string lyricsVar = $"live/musicscores/m{songid}/m{songid}_lyrics";
|
||||
UmaDatabaseEntry lyricsAsset = Main.AbList.FirstOrDefault(a => a.Name.Contains(lyricsVar));
|
||||
if (lyricsAsset != null)
|
||||
{
|
||||
string filePath = GetABPath(lyricsAsset);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
UI.LoadedAssetsAdd(lyricsAsset);
|
||||
AssetBundle bundle = AssetBundle.LoadFromFile(filePath);
|
||||
Main.LoadedBundles.Add(lyricsAsset.Name, bundle);
|
||||
TextAsset asset = bundle.LoadAsset<TextAsset>(Path.GetFileNameWithoutExtension(lyricsVar));
|
||||
string[] lines = asset.text.Split("\n"[0]);
|
||||
for (int i = 1; i < lines.Length; i++)
|
||||
{
|
||||
string[] words = lines[i].Split(',');
|
||||
UmaLyricsData lyricsData = new UmaLyricsData()
|
||||
{
|
||||
time = float.Parse(words[0])/1000,
|
||||
text = words[1].Replace("[COMMA]",",")
|
||||
};
|
||||
CurrentLyrics.Add(lyricsData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RecursiveLoadAsset(UmaDatabaseEntry entry, bool IsSubAsset = false)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(entry.Prerequisites))
|
||||
@@ -504,7 +521,6 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
bbb.wrapMode = WrapMode.Loop;
|
||||
CurrentUMAContainer.OverrideController["clip"] = bbb;
|
||||
CurrentUMAContainer.UmaAnimator.Play("clip", 0, 0);
|
||||
|
||||
}
|
||||
|
||||
if (!CurrentLiveContainer)
|
||||
|
||||
@@ -39,6 +39,7 @@ public class UmaViewerUI : MonoBehaviour,FaceLoadCallBack
|
||||
public Button AudioPlayButton;
|
||||
public TextMeshProUGUI TitleText;
|
||||
public TextMeshProUGUI ProgressText;
|
||||
public Text LyricsText;
|
||||
|
||||
//settings
|
||||
public TMP_InputField SSWidth, SSHeight;
|
||||
@@ -277,8 +278,8 @@ public class UmaViewerUI : MonoBehaviour,FaceLoadCallBack
|
||||
foreach (var entry in Main.AbList.Where(a => a.Name.Contains(nameVar) && a.Name.EndsWith("awb")))
|
||||
{
|
||||
var container = Instantiate(UmaContainerPrefab, LiveCharaSoundList.content).GetComponent<UmaUIContainer>();
|
||||
string[] split = entry.Name.Split('_');
|
||||
string name = split[split.Length - 2] + getCharaName(split[split.Length - 2]) + " " + split[split.Length - 1].Replace(".awb","");
|
||||
string[] split = Path.GetFileNameWithoutExtension(entry.Name).Split('_');
|
||||
string name = split[split.Length - 2] + getCharaName(split[split.Length - 2]) + " " + split[split.Length - 1];
|
||||
container.Name.text = name;
|
||||
container.Button.onClick.AddListener(() => {
|
||||
HighlightChildImage(LiveCharaSoundList.content, container.GetComponent<Image>());
|
||||
@@ -475,6 +476,7 @@ public class UmaViewerUI : MonoBehaviour,FaceLoadCallBack
|
||||
TitleText.text = MianSource.clip.name;
|
||||
ProgressText.text = string.Format("{0} / {1}", ToTimeFormat(MianSource.time), ToTimeFormat(MianSource.clip.length));
|
||||
AudioSlider.SetValueWithoutNotify(MianSource.time/ MianSource.clip.length);
|
||||
LyricsText.text = GetCurrentLyrics(MianSource.time);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -484,6 +486,7 @@ public class UmaViewerUI : MonoBehaviour,FaceLoadCallBack
|
||||
TitleText.text = "No Audio";
|
||||
ProgressText.text = "00:00:00 / 00:00:00";
|
||||
AudioSlider.SetValueWithoutNotify(0);
|
||||
LyricsText.text = "";
|
||||
}
|
||||
|
||||
public static string ToTimeFormat(float time)
|
||||
@@ -495,4 +498,16 @@ public class UmaViewerUI : MonoBehaviour,FaceLoadCallBack
|
||||
seconds = seconds % 3600 % 60;
|
||||
return string.Format("{0:D2}:{1:D2}:{2:D2}", hour, minute, seconds);
|
||||
}
|
||||
|
||||
public string GetCurrentLyrics(float time)
|
||||
{
|
||||
for(int i = Builder.CurrentLyrics.Count-1; i >=0; i--)
|
||||
{
|
||||
if(Builder.CurrentLyrics[i].time< time)
|
||||
{
|
||||
return Builder.CurrentLyrics[i].text;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user