rimworld-animation-studio/Assets/Scripts/AnimationComponents/AnimationClips/ThingAnimationClip.cs

54 lines
2.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
namespace RimWorldAnimationStudio
{
public class ThingAnimationClip : AnimationClip
{
[XmlAttribute("Class")] public string className = "Rimworld_Animations.ThingAnimationClip";
[XmlArray("keyframes"), XmlArrayItem("li")] public List<ThingKeyframe> keyframes = new List<ThingKeyframe>();
[XmlIgnore] public SimpleCurve PositionX = new SimpleCurve();
[XmlIgnore] public SimpleCurve PositionZ = new SimpleCurve();
[XmlIgnore] public SimpleCurve Rotation = new SimpleCurve();
public override int duration { get { return keyframes.Max(x => x.atTick.Value); } }
public override void BuildSimpleCurves()
{
int duration = 0;
//getting the length of the whole clip
foreach (ThingKeyframe frame in keyframes)
{
duration += frame.tickDuration;
}
//guarantees loops don't get cut off mid-anim
//this.duration = duration;
int keyframePosition = 0;
foreach (ThingKeyframe frame in keyframes)
{
if (frame.atTick.HasValue)
{
PositionX.Add((float)frame.atTick / (float)duration, frame.positionX, true);
PositionZ.Add((float)frame.atTick / (float)duration, frame.positionZ, true);
Rotation.Add((float)frame.atTick / (float)duration, frame.rotation, true);
}
else
{
PositionX.Add((float)keyframePosition / (float)duration, frame.positionX, true);
PositionZ.Add((float)keyframePosition / (float)duration, frame.positionZ, true);
Rotation.Add((float)keyframePosition / (float)duration, frame.rotation, true);
keyframePosition += frame.tickDuration;
}
}
}
}
}