public void PlayClip(int i, float blend) { if (i < clips.Count) { current = i; t = 0.0f; MegaPlayingClip pclip = PopClip(); //new MegaPlayingClip(); // TODO: have a pool for these pclip.t = 0.0f; pclip.targetblendtime = blend; MegaPlayingClip cclip = playing[playing.Count - 1]; cclip.blendtime = -Mathf.Abs(cclip.blendtime); cclip.targetblendtime = -blend; playing.Add(pclip); } }
void PushClip(MegaPlayingClip clip) { clippool.Push(clip); }
public void UpdatePlayingClips() { if (playing.Count == 0) { return; } // reset blends morph.ClearBlends(); for (int i = playing.Count - 1; i >= 0; i--) { MegaPlayingClip pclip = playing[i]; MegaMorphAnimClip clip = clips[pclip.clipIndex]; if (pclip.t >= 0.0f) { pclip.t += Time.deltaTime * clip.speed; float dt = clip.end - clip.start; switch (clip.loop) { case MegaRepeatMode.Loop: pclip.at = Mathf.Repeat(pclip.t, dt); break; case MegaRepeatMode.PingPong: pclip.at = Mathf.PingPong(pclip.t, dt); break; case MegaRepeatMode.Clamp: pclip.at = Mathf.Clamp(pclip.t, 0.0f, dt); break; } pclip.at += clip.start; if (pclip.targetblendtime != 0.0f) { if (pclip.targetblendtime > 0.0f) { pclip.blendtime += Time.deltaTime; if (pclip.blendtime >= pclip.targetblendtime) { pclip.targetblendtime = 0.0f; pclip.weight = 1.0f; } else { pclip.weight = (pclip.targetblendtime - pclip.blendtime) / pclip.targetblendtime; } } else { pclip.blendtime -= Time.deltaTime; if (pclip.blendtime <= pclip.targetblendtime) { pclip.targetblendtime = 0.0f; pclip.weight = 0.0f; } else { pclip.weight = (pclip.targetblendtime - pclip.blendtime) / pclip.targetblendtime; } } } if (pclip.weight != 0.0f) { if (MultipleMorphs) { if (morphs != null) { for (int m = 0; m < morphs.Length; m++) { morphs[m].SetAnimBlend(pclip.at, pclip.weight); } } } else { if (morph) { morph.SetAnimBlend(pclip.at, pclip.weight); } } } else { PushClip(pclip); playing.RemoveAt(i); } } } }