mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
107 lines
4.7 KiB
C#
107 lines
4.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Xml;
|
|
using System.Xml.Serialization;
|
|
using UnityEngine;
|
|
|
|
namespace RimWorldAnimationStudio
|
|
{
|
|
public class PawnAnimationClip : AnimationClip
|
|
{
|
|
[XmlAttribute("Class")] public string className = "Rimworld_Animations.PawnAnimationClip";
|
|
[XmlArray("keyframes"), XmlArrayItem("li")] public List<PawnKeyframe> keyframes = new List<PawnKeyframe>();
|
|
|
|
[XmlIgnore] public Dictionary<int, bool> quiver = new Dictionary<int, bool>();
|
|
[XmlIgnore] public SimpleCurve GenitalAngle = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve BodyAngle = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve HeadAngle = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve HeadBob = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve BodyOffsetX = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve BodyOffsetZ = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve HeadFacing = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve BodyFacing = new SimpleCurve();
|
|
|
|
public override void BuildSimpleCurves()
|
|
{
|
|
BodyAngle.Clear();
|
|
HeadAngle.Clear();
|
|
BodyOffsetX.Clear();
|
|
BodyOffsetZ.Clear();
|
|
HeadFacing.Clear();
|
|
BodyFacing.Clear();
|
|
HeadBob.Clear();
|
|
GenitalAngle.Clear();
|
|
|
|
int duration = 0;
|
|
|
|
foreach (PawnKeyframe frame in keyframes)
|
|
{ duration += frame.tickDuration; }
|
|
|
|
this.duration = duration;
|
|
int keyframePosition = 0;
|
|
|
|
for (int i = 0; i < keyframes.Count; i++)
|
|
{
|
|
PawnKeyframe keyframe = keyframes[i];
|
|
|
|
if (keyframe.atTick.HasValue)
|
|
{
|
|
if (keyframe.HasValidKeyframeID() == false)
|
|
{ keyframe.GenerateKeyframeID(); }
|
|
|
|
BodyAngle.Add((float)keyframe.atTick / (float)duration, keyframe.bodyAngle, true);
|
|
HeadAngle.Add((float)keyframe.atTick / (float)duration, keyframe.headAngle, true);
|
|
BodyOffsetX.Add((float)keyframe.atTick / (float)duration, keyframe.bodyOffsetX, true);
|
|
BodyOffsetZ.Add((float)keyframe.atTick / (float)duration, keyframe.bodyOffsetZ, true);
|
|
HeadFacing.Add((float)keyframe.atTick / (float)duration, keyframe.headFacing, true);
|
|
BodyFacing.Add((float)keyframe.atTick / (float)duration, keyframe.bodyFacing, true);
|
|
HeadBob.Add((float)keyframe.atTick / (float)duration, keyframe.headBob, true);
|
|
|
|
if (keyframe.genitalAngle.HasValue)
|
|
{ GenitalAngle.Add((float)keyframe.atTick / (float)duration, keyframe.genitalAngle.Value, true); }
|
|
|
|
if (i + 1 < keyframes.Count)
|
|
{ keyframes[i].tickDuration = keyframes[i + 1].atTick.Value - keyframes[i].atTick.Value; }
|
|
}
|
|
|
|
else
|
|
{
|
|
BodyAngle.Add((float)keyframePosition / (float)duration, keyframe.bodyAngle, true);
|
|
HeadAngle.Add((float)keyframePosition / (float)duration, keyframe.headAngle, true);
|
|
BodyOffsetX.Add((float)keyframePosition / (float)duration, keyframe.bodyOffsetX, true);
|
|
BodyOffsetZ.Add((float)keyframePosition / (float)duration, keyframe.bodyOffsetZ, true);
|
|
HeadFacing.Add((float)keyframePosition / (float)duration, keyframe.headFacing, true);
|
|
BodyFacing.Add((float)keyframePosition / (float)duration, keyframe.bodyFacing, true);
|
|
HeadBob.Add((float)keyframePosition / (float)duration, keyframe.headBob, true);
|
|
|
|
if (keyframe.genitalAngle.HasValue)
|
|
{ GenitalAngle.Add((float)keyframePosition / (float)duration, keyframe.genitalAngle.Value, true); }
|
|
|
|
if (keyframe.tickDuration != 1 && keyframe.quiver.HasValue)
|
|
{
|
|
quiver.Add(keyframePosition, true);
|
|
quiver.Add(keyframePosition + keyframe.tickDuration - 1, false);
|
|
}
|
|
|
|
keyframe.atTick = keyframePosition + 1;
|
|
keyframePosition += keyframe.tickDuration;
|
|
}
|
|
}
|
|
|
|
keyframes[keyframes.Count - 1].tickDuration = 1;
|
|
}
|
|
|
|
public bool MakeNew()
|
|
{
|
|
PawnKeyframe keyframeA = new PawnKeyframe();
|
|
keyframeA.tickDuration = 60;
|
|
keyframes.Add(keyframeA);
|
|
|
|
PawnKeyframe keyframeB = new PawnKeyframe();
|
|
keyframes.Add(keyframeB);
|
|
|
|
BuildSimpleCurves();
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|