rimworld-animation-studio/Assets/Scripts/GUI/AnimationTimeline.cs

68 lines
2 KiB
C#
Raw Normal View History

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);
}
2022-09-18 05:01:12 +00:00
public void Update()
{
if (Workspace.actorID == actorID)
{ GetComponent<Image>().color = Constants.ColorGoldYellow; }
else
{ GetComponent<Image>().color = Constants.ColorGrey; }
}
}
}