mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
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";
|
|
[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);
|
|
|
|
if (frame.soundEffect != null)
|
|
{ SoundEffects.Add((int)frame.atTick, frame.soundEffect); }
|
|
}
|
|
|
|
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);
|
|
|
|
if (frame.soundEffect != null)
|
|
{ SoundEffects.Add(keyframePosition, frame.soundEffect); }
|
|
|
|
keyframePosition += frame.tickDuration;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|