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

56 lines
2.1 KiB
C#
Raw Normal View History

2022-09-13 05:36:34 +00:00
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
namespace RimWorldAnimationStudio
{
public class ThingAnimationClip : AnimationClip
{
[XmlAttribute("Class")] public string className = "Rimworld_Animations.ThingAnimationClip";
2022-09-13 05:36:34 +00:00
[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 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);
2022-09-13 05:36:34 +00:00
if (frame.soundEffect != null)
{ SoundEffects.Add((int)frame.atTick, frame.soundEffect); }
2022-09-13 05:36:34 +00:00
}
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);
2022-09-13 05:36:34 +00:00
if (frame.soundEffect != null)
{ SoundEffects.Add(keyframePosition, frame.soundEffect); }
2022-09-13 05:36:34 +00:00
keyframePosition += frame.tickDuration;
}
}
}
}
}