Manual timeline, cycle and actor tweaking

This commit is contained in:
AbstractConcept 2022-09-16 17:50:15 -05:00
parent dfa564759b
commit 1dd7781179
165 changed files with 4040 additions and 166 deletions

View file

@ -4,11 +4,12 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class KeyframeSlider : Slider
public class KeyframeSlider : Slider, IPointerClickHandler, IBeginDragHandler, IEndDragHandler
{
public AnimationTimeline timeline;
//public AnimationClip clip;
@ -31,9 +32,8 @@ namespace RimWorldAnimationStudio
this.keyframeID = keyframeID;
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
Debug.Log(keyframe);
value = (float)keyframe.atTick / Workspace.Instance.GetCurrentStageLength();
Debug.Log(keyframe.atTick);
value = (float)keyframe.atTick / Workspace.animationClipWindowSize;
OnValueChanged();
onValueChanged.AddListener(delegate (float value) { OnValueChanged(); });
@ -44,32 +44,15 @@ namespace RimWorldAnimationStudio
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
int stageLength = Workspace.Instance.GetCurrentStageLength();
int newTick = Mathf.RoundToInt(value * stageLength);
/*if (timeline.CanAddKeyFrameAtTick(newTick) == false)
{
int delta = keyframe.atTick > newTick ? 1 : -1;
while (timeline.CanAddKeyFrameAtTick(newTick) == false)
{
newTick += delta;
if (newTick == 1 || newTick == stageLength) { break; }
}
if (timeline.CanAddKeyFrameAtTick(newTick) == false)
{ value = (float)keyframe.atTick / stageLength; return; }
}*/
int newTick = Mathf.RoundToInt(value * Workspace.animationClipWindowSize);
keyframe.atTick = newTick;
Debug.Log("Value changed: " + newTick);
//value = (float)keyframe.atTick / stageLength;
UpdateGhostFrames();
clip.BuildSimpleCurves();
AnimationController.Instance.stageTick = keyframe.atTick.Value;
}
// Ghost sliders are non-interactable slider handle
@ -81,12 +64,11 @@ namespace RimWorldAnimationStudio
if (maxGhosts == 0)
{ return; }
int stageLength = Workspace.Instance.GetCurrentStageLength();
int nGhosts = GetGhostFramesRequired();
for (int i = 0; i < Mathf.Max(nGhosts, ghostSliders.childCount); i++)
{
if ((i - 1) * clip.duration + keyframe.atTick <= stageLength)
if ((i - 1) * clip.duration + keyframe.atTick <= Workspace.animationClipWindowSize)
{
if (ghostSliders.childCount <= i)
{ Instantiate(ghostSliderPrefab, ghostSliders); }
@ -97,7 +79,7 @@ namespace RimWorldAnimationStudio
Slider ghostSlider = ghostSliderObject.GetComponent<Slider>();
Debug.Log(ghostSlider);
ghostSlider.value = (float)((i + 1) * clip.duration + keyframe.atTick) / stageLength;
ghostSlider.value = (float)((i + 1) * clip.duration + keyframe.atTick) / Workspace.animationClipWindowSize;
float mult = 1f - Mathf.Pow((float)i / maxGhosts, 2);
ghostSlider.transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(0, 0.5f, 0.5f, 0.5f * mult);
@ -118,7 +100,36 @@ namespace RimWorldAnimationStudio
if (clip.duration <= 1)
{ return 0; }
return Math.Min(Mathf.CeilToInt((float)Workspace.Instance.GetCurrentStageLength() / clip.duration), maxGhosts);
return Math.Min(Mathf.CeilToInt((float)Workspace.animationClipWindowSize / clip.duration), maxGhosts);
}
public void OnPointerClick(PointerEventData eventData)
{
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
foreach (KeyframeSlider keyframeSlider in timeline.transform.GetComponentsInChildren<KeyframeSlider>())
{
if (keyframeSlider == this)
{ continue; }
keyframeSlider.transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(1f, 1f, 1f);
}
transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(0f, 1f, 0f);
AnimationController.Instance.stageTick = keyframe.atTick.Value;
Workspace.keyframeID = keyframeID;
}
public void OnBeginDrag(PointerEventData eventData)
{
interactable = true;
}
public void OnEndDrag(PointerEventData eventData)
{
interactable = false;
}
}
}