2022-09-16 14:18:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2022-10-13 05:33:18 +00:00
|
|
|
|
using UnityEngine.EventSystems;
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
|
|
|
|
namespace RimWorldAnimationStudio
|
|
|
|
|
{
|
2022-10-13 05:33:18 +00:00
|
|
|
|
public class AnimationTimeline : MonoBehaviour, IPointerClickHandler
|
2022-09-16 14:18:06 +00:00
|
|
|
|
{
|
|
|
|
|
public int actorID;
|
|
|
|
|
public KeyframeSlider keyframeSliderPrefab;
|
|
|
|
|
|
2022-10-13 05:33:18 +00:00
|
|
|
|
private Transform anchorTransform;
|
|
|
|
|
|
2022-09-16 14:18:06 +00:00
|
|
|
|
public void Initialize(int actorID)
|
|
|
|
|
{
|
2022-10-13 05:33:18 +00:00
|
|
|
|
anchorTransform = transform.parent;
|
2022-09-16 14:18:06 +00:00
|
|
|
|
this.actorID = actorID;
|
|
|
|
|
|
2022-10-27 05:56:04 +00:00
|
|
|
|
PawnAnimationClip clip = Workspace.GetPawnAnimationClip(actorID);
|
2022-10-15 06:00:47 +00:00
|
|
|
|
clip.BuildSimpleCurves();
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
2022-10-15 06:00:47 +00:00
|
|
|
|
foreach (KeyframeSlider slider in GetComponentsInChildren<KeyframeSlider>())
|
|
|
|
|
{ RemovePawnKeyFrame(slider.keyframeID);}
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
2022-10-27 05:56:04 +00:00
|
|
|
|
foreach (PawnKeyframe keyframe in clip.Keyframes)
|
2022-10-15 06:00:47 +00:00
|
|
|
|
{ AddPawnKeyFrame(keyframe.keyframeID); }
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
2022-10-15 06:00:47 +00:00
|
|
|
|
/*int keyframeCount = clip.keyframes.Count;
|
2022-10-14 19:00:57 +00:00
|
|
|
|
int childCount = GetComponentsInChildren<KeyframeSlider>().Count();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Mathf.Max(keyframeCount, childCount); i++)
|
|
|
|
|
{
|
|
|
|
|
// Add new keyframe sliders as required
|
|
|
|
|
if (i >= childCount)
|
2022-10-15 06:00:47 +00:00
|
|
|
|
{ AddPawnKeyFrame(clip.keyframes[i].keyframeID); }
|
2022-10-14 19:00:57 +00:00
|
|
|
|
|
|
|
|
|
// 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
|
2022-10-15 06:00:47 +00:00
|
|
|
|
{ RemovePawnKeyFrame(GetComponentsInChildren<KeyframeSlider>()[i].keyframeID); }
|
|
|
|
|
}*/
|
2022-09-16 14:18:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
public void AddPawnKeyFrame(int keyframeID)
|
2022-09-16 14:18:06 +00:00
|
|
|
|
{
|
2022-09-18 00:06:33 +00:00
|
|
|
|
KeyframeSlider keyframeSlider = Instantiate(keyframeSliderPrefab, transform);
|
|
|
|
|
keyframeSlider.Initialize(this, actorID, keyframeID);
|
|
|
|
|
}
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
public void RemovePawnKeyFrame(int keyframeID)
|
|
|
|
|
{
|
|
|
|
|
KeyframeSlider keyframeSlider = GetComponentsInChildren<KeyframeSlider>().FirstOrDefault(x => x.keyframeID == keyframeID);
|
|
|
|
|
Destroy(keyframeSlider?.gameObject);
|
2022-09-16 14:18:06 +00:00
|
|
|
|
}
|
2022-09-18 05:01:12 +00:00
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2022-10-27 05:56:04 +00:00
|
|
|
|
if (Workspace.ActorID == actorID)
|
2022-09-18 05:01:12 +00:00
|
|
|
|
{ GetComponent<Image>().color = Constants.ColorGoldYellow; }
|
|
|
|
|
|
|
|
|
|
else
|
2022-10-12 05:22:29 +00:00
|
|
|
|
{ GetComponent<Image>().color = Constants.ColorMidGrey; }
|
2022-09-18 05:01:12 +00:00
|
|
|
|
}
|
2022-09-19 00:07:44 +00:00
|
|
|
|
|
|
|
|
|
public void InitiateUpdateOfGhostFrames()
|
|
|
|
|
{
|
2022-10-14 19:00:57 +00:00
|
|
|
|
if (AnimationController.Instance.IsTimelineDirty()) return;
|
|
|
|
|
|
2022-09-19 00:07:44 +00:00
|
|
|
|
BroadcastMessage("UpdateGhostFrames");
|
|
|
|
|
}
|
2022-09-21 05:40:58 +00:00
|
|
|
|
|
|
|
|
|
public void OnMoveTimeline(int delta)
|
|
|
|
|
{
|
2022-10-13 05:33:18 +00:00
|
|
|
|
int? siblingIndex = anchorTransform.parent.GetComponentsInChildren<AnimationTimeline>()?.ToList()?.IndexOf(this);
|
|
|
|
|
int? siblingCount = anchorTransform.parent.GetComponentsInChildren<AnimationTimeline>()?.ToList()?.Count();
|
2022-09-21 05:40:58 +00:00
|
|
|
|
|
|
|
|
|
if (siblingIndex != null && siblingCount != null && MoveAnimationTimeline(siblingIndex.Value, delta))
|
2022-10-14 19:00:57 +00:00
|
|
|
|
{ AnimationController.Instance.InitializeAnimationTimeline(); }
|
2022-09-21 05:40:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool MoveAnimationTimeline(int startIndex, int delta)
|
|
|
|
|
{
|
2022-10-27 05:56:04 +00:00
|
|
|
|
if (startIndex + delta < 0 || startIndex + delta >= Workspace.GetCurrentAnimationStage().AnimationClips.Count)
|
2022-10-02 05:42:07 +00:00
|
|
|
|
{ Debug.Log("Cannot move animation timeline - movement would exceed bounds"); return false; }
|
2022-09-21 05:40:58 +00:00
|
|
|
|
|
2022-10-27 05:56:04 +00:00
|
|
|
|
Actor actor = Workspace.animationDef.Actors[startIndex];
|
|
|
|
|
Workspace.animationDef.Actors[startIndex] = Workspace.animationDef.Actors[startIndex + delta];
|
|
|
|
|
Workspace.animationDef.Actors[startIndex + delta] = actor;
|
2022-09-21 05:40:58 +00:00
|
|
|
|
|
2022-10-27 05:56:04 +00:00
|
|
|
|
PawnAnimationClip clip = Workspace.GetPawnAnimationClip(startIndex);
|
|
|
|
|
Workspace.GetCurrentAnimationStage().AnimationClips[startIndex] = Workspace.GetCurrentAnimationStage().AnimationClips[startIndex + delta];
|
|
|
|
|
Workspace.GetCurrentAnimationStage().AnimationClips[startIndex + delta] = clip;
|
2022-09-21 05:40:58 +00:00
|
|
|
|
|
2022-10-27 05:56:04 +00:00
|
|
|
|
Workspace.ActorID = startIndex + delta;
|
2022-09-21 05:40:58 +00:00
|
|
|
|
|
2022-10-27 05:56:04 +00:00
|
|
|
|
Workspace.RecordEvent("Timeline move");
|
2022-09-21 05:40:58 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-10-13 05:33:18 +00:00
|
|
|
|
|
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
|
|
|
{
|
2022-10-27 05:56:04 +00:00
|
|
|
|
Workspace.ActorID = actorID;
|
2022-10-13 05:33:18 +00:00
|
|
|
|
Workspace.keyframeID.Clear();
|
|
|
|
|
}
|
2022-09-16 14:18:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|