68 lines
2.0 KiB
C#
68 lines
2.0 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 = 0;
|
|
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 int GetStageID()
|
|
{
|
|
if (Workspace.animationDef == null) return -1;
|
|
|
|
return Workspace.animationDef.animationStages.IndexOf(this);
|
|
}
|
|
|
|
public bool MakeNew()
|
|
{
|
|
if (Workspace.animationDef == null)
|
|
{ Debug.LogWarning("Cannot make new animation stage - there is no AnimationDef"); return false; }
|
|
|
|
Workspace.animationDef.animationStages.Add(this);
|
|
|
|
foreach (Actor actor in Workspace.animationDef.actors)
|
|
{
|
|
PawnAnimationClip clip = new PawnAnimationClip();
|
|
|
|
if (clip.MakeNew(actor.GetActorID()))
|
|
{ animationClips.Add(clip); }
|
|
}
|
|
|
|
Initialize();
|
|
playTimeTicksQuick = playTimeTicks;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|