public bool TryGetPathWithPropertyFromChannel(ChannelCurve channel, out PathWithProperty pathWithProp) { var index = Channels.ToList().IndexOf(channel); if (index == -1) { pathWithProp = default(PathWithProperty); return(false); } foreach (var node in Root.Traverse()) { for (int i = 0; i < node.Channels.Length; ++i, --index) { if (index == 0) { pathWithProp = new PathWithProperty { Path = GetPath(node), Property = node.Channels[i].ToProperty(), IsLocation = node.Channels[i].IsLocation(), }; return(true); } } } throw new BvhException("channel is not found"); }
static void AddCurve(Bvh bvh, AnimationClip clip, ChannelCurve ch, float toMeter) { if (ch == null) { return; } var pathWithProp = default(Bvh.PathWithProperty); bvh.TryGetPathWithPropertyFromChannel(ch, out pathWithProp); var curve = new AnimationCurve(); for (int i = 0; i < bvh.FrameCount; ++i) { var time = (float)(i * bvh.FrameTime.TotalSeconds); var value = ch.Keys[i] * toMeter; curve.AddKey(time, value); } clip.SetCurve(pathWithProp.Path, typeof(Transform), pathWithProp.Property, curve); }