public static RhubarbTrack Auto(string rhubarbPath, string audioPath, string dialog, bool _isG = true, bool _isH = true, bool _isX = true) { rhubarbPath = FixPath(rhubarbPath); audioPath = FixPath(audioPath); string dialogPath = FixPath(Path.Combine(Directory.GetCurrentDirectory(), "Assets/dialog.txt")); RhubarbTrack rhubarbTrack = ScriptableObject.CreateInstance <RhubarbTrack>(); rhubarbTrack.keyframes = new List <RhubarbKeyframe>(); bool isDialog = !string.IsNullOrEmpty(dialog); string extendedMouthShapesArgument = ExtendedMouthShapeArgument(_isG, _isH, _isX); if (isDialog) { File.WriteAllText(dialogPath, dialog); } Process process = new Process(); #if UNITY_EDITOR_WIN process.StartInfo.FileName = rhubarbPath; string command = ""; command += "\"" + audioPath + "\" "; command += isDialog ? "--dialogFile \"" + dialogPath + "\" " : ""; command += "--extendedShapes " + extendedMouthShapesArgument; process.StartInfo.Arguments = command; #endif #if UNITY_EDITOR_OSX process.StartInfo.FileName = "/bin/bash"; string command = rhubarbPath + " "; command += audioPath + " "; command += isDialog ? "--dialogFile " + dialogPath + " " : ""; command += "--extendedShapes " + extendedMouthShapesArgument; process.StartInfo.Arguments = "-c \" " + command + " \""; #endif process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); while (!process.StandardOutput.EndOfStream) { string line = process.StandardOutput.ReadLine(); RhubarbKeyframe keyframe = new RhubarbKeyframe(); keyframe.Deserialize(line); rhubarbTrack.keyframes.Add(keyframe); } if (isDialog) { File.Delete(dialogPath); } return(rhubarbTrack); }
public void Deserialize(string text) { keyframes = new List <RhubarbKeyframe>(); string[] lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) { RhubarbKeyframe keyframe = new RhubarbKeyframe(); if (keyframe.Deserialize(lines[i])) { keyframes.Add(keyframe); } } }
private void CreateRhubarb() { TimelineAsset timelineAsset = (TimelineAsset)_timeline.playableAsset; RhubarbPlayableTrack track = timelineAsset.CreateTrack <RhubarbPlayableTrack>(null, "Rhubarb Track"); _timeline.SetGenericBinding(track, _rhubarbSprite); string audioPath = Path.Combine(Directory.GetCurrentDirectory(), AssetDatabase.GetAssetPath(_audioClip)); RhubarbTrack rhubarbTrack = RhubarbEditorProcess.Auto(_rhubarbPath, audioPath, _isUseDialog ? _dialogText : null, _isMouthShapeG, _isMouthShapeH, _isMouthShapeX); for (int i = 0; i < rhubarbTrack.keyframes.Count - 1; i++) { RhubarbKeyframe keyframe = rhubarbTrack.keyframes[i]; RhubarbKeyframe nextKeyframe = rhubarbTrack.keyframes[i + 1]; TimelineClip clip = track.CreateClip <RhubarbPlayableClip>(); clip.start = Rhubarb.FrameToTime(keyframe.frame); clip.duration = Rhubarb.FrameToTime(nextKeyframe.frame - keyframe.frame); ((RhubarbPlayableClip)clip.asset).template.MouthShape = keyframe.phoneme; } }