Skip to content

Instantly share code, notes, and snippets.

@CustomPhase
Created April 27, 2017 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CustomPhase/77ed1276485ad3be0ab78429f2ce8981 to your computer and use it in GitHub Desktop.
Save CustomPhase/77ed1276485ad3be0ab78429f2ce8981 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RhubarbData
{
public float time;
public string phoneme;
public float delay;
}
public class RhubarbAnimator : MonoBehaviour {
public TextAsset textFile;
public List<RhubarbData> data;
int current = 0;
Animator anim;
public bool animate = false;
// Use this for initialization
void Awake () {
anim = GetComponent<Animator>();
if (textFile!=null)
{
data = new List<RhubarbData>();
string fs = textFile.text;
string[] fLines = fs.Split("\n|\r|\r\n"[0]);
for (int i = 0; i<fLines.Length; i++)
{
RhubarbData rd = new RhubarbData();
string[] parts = fLines[i].Split('\t');
if (parts.Length >= 2)
{
rd.time = float.Parse(parts[0]);
rd.phoneme = parts[1].Trim();
rd.delay = 0;
if (i>0 && data[i-1]!=null)
{
rd.delay = rd.time - data[i - 1].time;
}
data.Add(rd);
StartCoroutine(DelayedAnimation(rd.time, rd.phoneme));
//CustomTimerManager.timerManager.Add(rd.time, Animate, rd.phoneme);
}
}
}
}
void Animate(string p)
{
anim.CrossFade("anim_" + p, 0.24f, 0);
}
IEnumerator DelayedAnimation(float time, string phoneme)
{
float t = time;
string p = phoneme;
yield return new WaitForSeconds(t);
anim.CrossFade("anim_" + p, 0.24f, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment