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

60 lines
1.8 KiB
C#
Raw Normal View History

2022-09-13 05:36:34 +00:00
using System.Collections.Generic;
2022-09-21 21:15:25 +00:00
using System.Linq;
2022-09-13 05:36:34 +00:00
using System.Xml;
using System.Xml.Serialization;
using UnityEngine;
2022-09-13 05:36:34 +00:00
namespace RimWorldAnimationStudio
{
public class AnimationStage
{
public string stageName = "NewStage";
2022-09-13 05:36:34 +00:00
public int stageIndex = 0;
public int playTimeTicks = 0;
public int playTimeTicksQuick = -1;
public bool isLooping = false;
2022-09-13 05:36:34 +00:00
2022-09-18 05:01:12 +00:00
[XmlArray("animationClips"), XmlArrayItem("li")] public List<PawnAnimationClip> animationClips = new List<PawnAnimationClip>();
[XmlIgnore] public int stageWindowSize = -1;
2022-09-13 05:36:34 +00:00
public void Initialize()
{
2022-09-19 00:07:44 +00:00
foreach (PawnAnimationClip clip in animationClips)
2022-09-13 05:36:34 +00:00
{
clip.BuildSimpleCurves();
2022-09-27 05:56:35 +00:00
// Select playTimeTicks as longest playtime of all the animations
2022-09-13 05:36:34 +00:00
if (clip.duration > playTimeTicks)
2022-09-27 05:56:35 +00:00
{ playTimeTicks = clip.duration; }
2022-09-13 05:36:34 +00:00
}
}
2022-09-21 21:15:25 +00:00
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;
}
2022-09-13 05:36:34 +00:00
}
}