rimworld-animation-studio/Assets/Scripts/AnimationComponents/AnimationStage.cs

60 lines
1.8 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
using UnityEngine;
namespace RimWorldAnimationStudio
{
public class AnimationStage
{
public string stageName = "NewStage";
public int stageIndex = 0;
public int playTimeTicks = 0;
public int playTimeTicksQuick = -1;
public bool isLooping = false;
[XmlArray("animationClips"), XmlArrayItem("li")] public List<PawnAnimationClip> animationClips = new List<PawnAnimationClip>();
[XmlIgnore] public int stageWindowSize = -1;
public void Initialize()
{
foreach (PawnAnimationClip clip in animationClips)
{
clip.BuildSimpleCurves();
// Select playTimeTicks as longest playtime of all the animations
if (clip.duration > playTimeTicks)
{ playTimeTicks = clip.duration; }
}
}
public void ValidateData()
{
// Sort keyframes by atTick
foreach (PawnAnimationClip clip in animationClips)
{ clip.keyframes = clip.keyframes.OrderBy(x => x.atTick).ToList(); }
}
public bool MakeNew()
{
if (Workspace.animationDef == null)
{ Debug.LogWarning("Cannot make new animation stage - there is no AnimationDef"); return false; }
foreach(Actor actor in Workspace.animationDef.actors)
{
PawnAnimationClip clip = new PawnAnimationClip();
if (clip.MakeNew())
{ animationClips.Add(clip); }
}
Initialize();
Workspace.animationDef.animationStages.Add(this);
return true;
}
}
}