mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
118 lines
4.5 KiB
C#
118 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace RimWorldAnimationStudio
|
|
{
|
|
public class AnimationTimeline : MonoBehaviour, IPointerClickHandler
|
|
{
|
|
public int actorID;
|
|
public KeyframeSlider keyframeSliderPrefab;
|
|
|
|
private Transform anchorTransform;
|
|
|
|
public void Initialize(int actorID)
|
|
{
|
|
anchorTransform = transform.parent;
|
|
this.actorID = actorID;
|
|
|
|
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
|
|
clip.BuildSimpleCurves();
|
|
|
|
foreach (KeyframeSlider slider in GetComponentsInChildren<KeyframeSlider>())
|
|
{ RemovePawnKeyFrame(slider.keyframeID);}
|
|
|
|
foreach (PawnKeyframe keyframe in clip.keyframes)
|
|
{ AddPawnKeyFrame(keyframe.keyframeID); }
|
|
|
|
/*int keyframeCount = clip.keyframes.Count;
|
|
int childCount = GetComponentsInChildren<KeyframeSlider>().Count();
|
|
|
|
for (int i = 0; i < Mathf.Max(keyframeCount, childCount); i++)
|
|
{
|
|
// Add new keyframe sliders as required
|
|
if (i >= childCount)
|
|
{ AddPawnKeyFrame(clip.keyframes[i].keyframeID); }
|
|
|
|
// Get objects to update
|
|
KeyframeSlider keyframeSlider = GetComponentsInChildren<KeyframeSlider>()[i];
|
|
|
|
// Update values
|
|
if (i < keyframeCount)
|
|
{ keyframeSlider.Initialize(this, actorID, clip.keyframes[i].keyframeID); }
|
|
|
|
// Remove excess objects as required
|
|
else
|
|
{ RemovePawnKeyFrame(GetComponentsInChildren<KeyframeSlider>()[i].keyframeID); }
|
|
}*/
|
|
}
|
|
|
|
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.ColorMidGrey; }
|
|
}
|
|
|
|
public void InitiateUpdateOfGhostFrames()
|
|
{
|
|
if (AnimationController.Instance.IsTimelineDirty()) return;
|
|
|
|
BroadcastMessage("UpdateGhostFrames");
|
|
}
|
|
|
|
public void OnMoveTimeline(int delta)
|
|
{
|
|
int? siblingIndex = anchorTransform.parent.GetComponentsInChildren<AnimationTimeline>()?.ToList()?.IndexOf(this);
|
|
int? siblingCount = anchorTransform.parent.GetComponentsInChildren<AnimationTimeline>()?.ToList()?.Count();
|
|
|
|
if (siblingIndex != null && siblingCount != null && MoveAnimationTimeline(siblingIndex.Value, delta))
|
|
{ AnimationController.Instance.InitializeAnimationTimeline(); }
|
|
}
|
|
|
|
public bool MoveAnimationTimeline(int startIndex, int delta)
|
|
{
|
|
if (startIndex + delta < 0 || startIndex + delta >= Workspace.animationDef.animationStages[Workspace.stageID].animationClips.Count)
|
|
{ Debug.Log("Cannot move animation timeline - movement would exceed bounds"); return false; }
|
|
|
|
Actor actor = Workspace.animationDef.actors[startIndex];
|
|
Workspace.animationDef.actors[startIndex] = Workspace.animationDef.actors[startIndex + delta];
|
|
Workspace.animationDef.actors[startIndex + delta] = actor;
|
|
|
|
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(startIndex);
|
|
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[startIndex] = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[startIndex + delta];
|
|
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[startIndex + delta] = clip;
|
|
|
|
Workspace.actorID = startIndex + delta;
|
|
|
|
Workspace.Instance.RecordEvent("Timeline move");
|
|
|
|
return true;
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
Workspace.actorID = actorID;
|
|
Workspace.keyframeID.Clear();
|
|
}
|
|
}
|
|
}
|