mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace RimWorldAnimationStudio
|
|
{
|
|
public class AnimationTimeline : MonoBehaviour
|
|
{
|
|
public int actorID;
|
|
public KeyframeSlider keyframeSliderPrefab;
|
|
|
|
public void Initialize(int actorID)
|
|
{
|
|
this.actorID = actorID;
|
|
|
|
Reset();
|
|
|
|
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
|
|
|
|
if (clip == null || clip.keyframes.NullOrEmpty())
|
|
{
|
|
Debug.Log("Clip was empty");
|
|
|
|
clip = new PawnAnimationClip();
|
|
clip.keyframes.Add(new PawnKeyframe());
|
|
clip.BuildSimpleCurves();
|
|
}
|
|
|
|
foreach (PawnKeyframe keyframe in clip.keyframes)
|
|
{
|
|
KeyframeSlider keyframeSlider = Instantiate(keyframeSliderPrefab, transform);
|
|
keyframeSlider.Initialize(this, actorID, keyframe.keyframeID);
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
foreach(KeyframeSlider keyframeSlider in GetComponentsInChildren<KeyframeSlider>())
|
|
{ Destroy(keyframeSlider.gameObject); }
|
|
}
|
|
|
|
public void AddPawnKeyFrame(int keyframeID)
|
|
{
|
|
KeyframeSlider keyframeSlider = Instantiate(keyframeSliderPrefab, transform);
|
|
keyframeSlider.Initialize(this, actorID, keyframeID);
|
|
}
|
|
|
|
public void RemovePawnKeyFrame(int keyframeID)
|
|
{
|
|
KeyframeSlider keyframeSlider = GetComponentsInChildren<KeyframeSlider>().FirstOrDefault(x => x.keyframeID == keyframeID);
|
|
Destroy(keyframeSlider?.gameObject);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (Workspace.actorID == actorID)
|
|
{ GetComponent<Image>().color = Constants.ColorGoldYellow; }
|
|
|
|
else
|
|
{ GetComponent<Image>().color = Constants.ColorGrey; }
|
|
}
|
|
|
|
public void InitiateUpdateOfGhostFrames()
|
|
{
|
|
BroadcastMessage("UpdateGhostFrames");
|
|
}
|
|
}
|
|
}
|