mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Improvements to timeline
This commit is contained in:
parent
d2ca61c61c
commit
591b176924
99 changed files with 460 additions and 359 deletions
24
Assets/Scripts/Chaser.cs
Normal file
24
Assets/Scripts/Chaser.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class Chaser : MonoBehaviour
|
||||
{
|
||||
public GameObject target;
|
||||
public bool chaseAlongX = true;
|
||||
public bool chaseAlongY = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (target == null)
|
||||
{ return; }
|
||||
|
||||
float x = chaseAlongX ? target.transform.position.x : transform.position.x;
|
||||
float y = chaseAlongY ? target.transform.position.y : transform.position.y;
|
||||
|
||||
transform.position = new Vector3(x, y, 0f);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Chaser.cs.meta
Normal file
11
Assets/Scripts/Chaser.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9584d659e560b88409843604ae04229b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -72,12 +72,12 @@ namespace RimWorldAnimationStudio
|
|||
if (actorBody == this)
|
||||
{ continue; }
|
||||
|
||||
actorBody.bodyRenderer.color = new Color(1f, 1f, 1f);
|
||||
actorBody.headRenderer.color = new Color(1f, 1f, 1f);
|
||||
actorBody.bodyRenderer.color = Constants.ColorWhite;
|
||||
actorBody.headRenderer.color = Constants.ColorWhite;
|
||||
}
|
||||
|
||||
bodyRenderer.color = new Color(0f, 1f, 0f);
|
||||
headRenderer.color = new Color(0f, 1f, 0f);
|
||||
bodyRenderer.color = Constants.ColorGreen;
|
||||
headRenderer.color = Constants.ColorGreen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,26 +23,29 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
Activate();
|
||||
|
||||
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe();
|
||||
|
||||
if (Workspace.Instance.GetCurrentPawnKeyframe() == null)
|
||||
{ Debug.LogWarning("Cannot alter actor - no keyframe data available"); return; }
|
||||
|
||||
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
PawnKeyframe keyframe = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID);
|
||||
|
||||
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
|
||||
{
|
||||
float distance = ((Vector2)mousePosition - (Vector2)transform.position).y;
|
||||
|
||||
Vector3 headOffset = new Vector3(0f, 0.34f, 0f);
|
||||
headOffset = Quaternion.Euler(0, 0, keyframe.bodyAngle) * headOffset;
|
||||
|
||||
distance = Vector2.Dot(parent.transform.up, (Vector2)(mousePosition - parent.transform.position - headOffset));
|
||||
|
||||
Debug.Log(headOffset.ToString());
|
||||
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).headBob = distance;
|
||||
keyframe.headBob = distance;
|
||||
}
|
||||
|
||||
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
||||
{
|
||||
float angle = Vector2.SignedAngle(Vector2.down, (Vector2)mousePosition - (Vector2)transform.position);
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).headAngle = angle;
|
||||
keyframe.headAngle = angle;
|
||||
}
|
||||
|
||||
else if (Workspace.actorManipulationMode == ActorManipulationMode.Face)
|
||||
|
@ -51,9 +54,7 @@ namespace RimWorldAnimationStudio
|
|||
int facing = -Mathf.RoundToInt(angle / 90f);
|
||||
facing = facing < 0 ? facing + 4 : facing;
|
||||
|
||||
Debug.Log(facing.ToString());
|
||||
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).headFacing = facing;
|
||||
keyframe.headFacing = facing;
|
||||
}
|
||||
|
||||
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(parent.actorID);
|
||||
|
@ -66,11 +67,11 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
foreach (ActorBody actorBody in AnimationController.Instance.GetComponentsInChildren<ActorBody>())
|
||||
{
|
||||
actorBody.bodyRenderer.color = new Color(1f, 1f, 1f);
|
||||
actorBody.headRenderer.color = new Color(1f, 1f, 1f);
|
||||
actorBody.bodyRenderer.color = Constants.ColorWhite;
|
||||
actorBody.headRenderer.color = Constants.ColorWhite;
|
||||
}
|
||||
|
||||
bodyPartRenderer.color = new Color(0f, 1f, 0f);
|
||||
bodyPartRenderer.color = Constants.ColorGreen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,12 +66,10 @@ namespace RimWorldAnimationStudio
|
|||
if (ghostSliders.childCount <= i)
|
||||
{ Instantiate(ghostSliderPrefab, ghostSliders); }
|
||||
|
||||
GameObject ghostSliderObject = ghostSliders.GetChild(i).gameObject;
|
||||
Debug.Log(ghostSliderObject);
|
||||
GameObject ghostSliderObject = ghostSliders.GetChild(i).gameObject;
|
||||
ghostSliderObject.SetActive(true);
|
||||
|
||||
Slider ghostSlider = ghostSliderObject.GetComponent<Slider>();
|
||||
Debug.Log(ghostSlider);
|
||||
ghostSlider.value = (int)((i + 1) * clip.duration + keyframe.atTick);
|
||||
|
||||
float mult = 1f - Mathf.Pow((float)i / maxGhosts, 2);
|
||||
|
@ -96,12 +94,20 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
Activate();
|
||||
Workspace.actorID = actorID;
|
||||
Workspace.keyframeID = keyframeID;
|
||||
|
||||
if (eventData.clickCount >= 2)
|
||||
{
|
||||
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
Activate();
|
||||
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
Workspace.actorID = actorID;
|
||||
Workspace.keyframeID = keyframeID;
|
||||
|
||||
if (keyframe.atTick == 1)
|
||||
{ return; }
|
||||
|
@ -113,7 +119,8 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
base.OnDrag(eventData);
|
||||
|
||||
Activate();
|
||||
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
Workspace.actorID = actorID;
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
|
@ -121,23 +128,21 @@ namespace RimWorldAnimationStudio
|
|||
interactable = false;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
protected override void Update()
|
||||
{
|
||||
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
base.Update();
|
||||
|
||||
Workspace.keyframeID = keyframeID;
|
||||
if (Workspace.keyframeID == keyframeID && AnimationController.Instance.stageTick == keyframe.atTick.Value)
|
||||
{ transform.FindDeepChild("Handle").GetComponent<Image>().color = Constants.ColorPurple; }
|
||||
|
||||
foreach (AnimationTimeline _timeline in AnimationController.Instance.animationTimelines.GetComponentsInChildren<AnimationTimeline>())
|
||||
{
|
||||
foreach (KeyframeSlider keyframeSlider in _timeline.GetComponentsInChildren<KeyframeSlider>())
|
||||
{
|
||||
if (keyframeSlider.keyframe.atTick.Value == keyframe.atTick.Value)
|
||||
{ keyframeSlider.transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(0f, 1f, 0f); }
|
||||
else if (Workspace.keyframeID == keyframeID)
|
||||
{ transform.FindDeepChild("Handle").GetComponent<Image>().color = Constants.ColorCyan; }
|
||||
|
||||
else
|
||||
{ keyframeSlider.transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(1f, 1f, 1f); }
|
||||
}
|
||||
}
|
||||
else if (AnimationController.Instance.stageTick == keyframe.atTick.Value)
|
||||
{ transform.FindDeepChild("Handle").GetComponent<Image>().color = Constants.ColorPink; }
|
||||
|
||||
else
|
||||
{ transform.FindDeepChild("Handle").GetComponent<Image>().color = Constants.ColorWhite; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
Workspace.stageID = transform.GetSiblingIndex();
|
||||
|
||||
AnimationController.Instance.ResetAnimationTimeline();
|
||||
AnimationController.Instance.InitializeAnimationTimeline();
|
||||
//AnimationController.Instance.ResetAnimationTimeline();
|
||||
//AnimationController.Instance.InitializeAnimationTimeline();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ namespace RimWorldAnimationStudio
|
|||
public AnimationTimeline animationTimelinePrefab;
|
||||
|
||||
// Private timing variables
|
||||
private int lastStageTick = 1;
|
||||
private float timeSinceLastUpdate = 0;
|
||||
private int cycleIndex = 0;
|
||||
|
||||
|
@ -54,9 +55,6 @@ namespace RimWorldAnimationStudio
|
|||
timeSinceLastUpdate -= 1f / 60f;
|
||||
stageTick += 1;
|
||||
|
||||
stageTimelineSlider.value = stageTick;
|
||||
animationClipTimeField.text = stageTick.ToString();
|
||||
|
||||
if (stageTick > Workspace.StageWindowSize)
|
||||
{
|
||||
if (stageLoopDropdown.value == 1)
|
||||
|
@ -73,8 +71,8 @@ namespace RimWorldAnimationStudio
|
|||
++Workspace.stageID;
|
||||
cycleIndex = 0;
|
||||
|
||||
ResetAnimationTimeline();
|
||||
InitializeAnimationTimeline();
|
||||
//ResetAnimationTimeline();
|
||||
//InitializeAnimationTimeline();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,15 +82,29 @@ namespace RimWorldAnimationStudio
|
|||
}
|
||||
|
||||
// Update stage timeline
|
||||
animationClipTimeField.interactable = isAnimating == false;
|
||||
animationClipTimeField.interactable = isAnimating == false;
|
||||
animationClipLengthField.interactable = isAnimating == false;
|
||||
|
||||
if (lastStageTick != stageTick)
|
||||
{
|
||||
stageTimelineSlider.value = stageTick;
|
||||
animationClipTimeField.text = stageTick.ToString();
|
||||
|
||||
lastStageTick = stageTick;
|
||||
}
|
||||
|
||||
// Update animation
|
||||
UpdateAnimation();
|
||||
}
|
||||
|
||||
public void UpdateAnimation()
|
||||
{
|
||||
if (Workspace.Instance.AnimationTimelinesNeedUpdate())
|
||||
{
|
||||
ResetAnimationTimeline();
|
||||
InitializeAnimationTimeline();
|
||||
}
|
||||
|
||||
List<ActorBody> actorBodies = GetComponentsInChildren<ActorBody>().ToList();
|
||||
|
||||
for (int actorID = 0; actorID < actorBodies.Count; actorID++)
|
||||
|
@ -177,21 +189,20 @@ namespace RimWorldAnimationStudio
|
|||
public void Reset()
|
||||
{
|
||||
Workspace.stageID = 0;
|
||||
|
||||
isAnimating = false;
|
||||
ResetAnimationTimeline();
|
||||
StageCardManager.Instance.Reset();
|
||||
}
|
||||
|
||||
public void ResetAnimationTimeline()
|
||||
{
|
||||
isAnimating = false;
|
||||
{
|
||||
timeSinceLastUpdate = 0;
|
||||
cycleIndex = 0;
|
||||
|
||||
foreach (ActorBody actorBody in GetComponentsInChildren<ActorBody>())
|
||||
{ Destroy(actorBody.gameObject); }
|
||||
|
||||
foreach (Transform animationTimeline in animationTimelines)
|
||||
foreach (AnimationTimeline animationTimeline in animationTimelines.GetComponentsInChildren<AnimationTimeline>())
|
||||
{ Destroy(animationTimeline.gameObject); }
|
||||
}
|
||||
|
||||
|
@ -299,7 +310,7 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
clip.BuildSimpleCurves();
|
||||
|
||||
animationTimelines.GetChild(Workspace.actorID).GetComponent<AnimationTimeline>().AddPawnKeyFrame(keyframe.keyframeID);
|
||||
animationTimelines.GetComponentsInChildren<AnimationTimeline>()[Workspace.actorID].AddPawnKeyFrame(keyframe.keyframeID);
|
||||
}
|
||||
|
||||
public void RemovePawnKeyframe()
|
||||
|
@ -311,12 +322,12 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
|
||||
|
||||
if (keyframe.atTick == 1)
|
||||
if (keyframe != null && keyframe.atTick == 1)
|
||||
{ Debug.LogWarning("Cannot delete key frame - the first key frame of an animation cannot be deleted"); return; }
|
||||
|
||||
if (keyframe != null)
|
||||
{
|
||||
animationTimelines.GetChild(actorID).GetComponent<AnimationTimeline>().RemovePawnKeyFrame(keyframe.keyframeID);
|
||||
animationTimelines.GetComponentsInChildren<AnimationTimeline>()[Workspace.actorID].RemovePawnKeyFrame(keyframe.keyframeID);
|
||||
|
||||
PawnAnimationClip clip = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[actorID];
|
||||
clip.keyframes.Remove(keyframe);
|
||||
|
@ -383,8 +394,8 @@ namespace RimWorldAnimationStudio
|
|||
animationClipLengthField.text = newstageWindowSize.ToString();
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].stageWindowSize = newstageWindowSize;
|
||||
|
||||
ResetAnimationTimeline();
|
||||
InitializeAnimationTimeline();
|
||||
//ResetAnimationTimeline();
|
||||
//InitializeAnimationTimeline();
|
||||
}
|
||||
|
||||
public void OnCycleNormalFieldChange()
|
||||
|
|
|
@ -13,5 +13,10 @@ namespace RimWorldAnimationStudio
|
|||
public static Color ColorGoldYellow = new Color(1f, 0.85f, 0f);
|
||||
public static Color ColorGrey = new Color(0.5f, 0.5f, 0.5f);
|
||||
public static Color ColorDarkGrey = new Color(0.2f, 0.2f, 0.2f);
|
||||
public static Color ColorPink = new Color(1.0f, 0.5f, 0.5f);
|
||||
public static Color ColorOrange = new Color(1.0f, 0.7f, 0.0f);
|
||||
public static Color ColorRichOrange = new Color(1.0f, 0.4f, 0.1f);
|
||||
public static Color ColorCyan = new Color(0.0f, 1.0f, 1.0f);
|
||||
public static Color ColorPurple = new Color(0.85f, 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,12 +41,12 @@ namespace RimWorldAnimationStudio
|
|||
}
|
||||
}
|
||||
|
||||
public PawnKeyframe GetCurrentPawnKeyframe(bool makeNewIfNull = true)
|
||||
public PawnKeyframe GetCurrentPawnKeyframe()
|
||||
{
|
||||
int stageTick = AnimationController.Instance.stageTick;
|
||||
PawnKeyframe keyframe = animationDef?.animationStages[stageID]?.animationClips[actorID]?.keyframes.FirstOrDefault(x => x.atTick == stageTick);
|
||||
|
||||
if (keyframe != null || makeNewIfNull == false)
|
||||
if (keyframe != null)
|
||||
{ return keyframe; }
|
||||
|
||||
AnimationController.Instance.AddPawnKeyframe();
|
||||
|
@ -105,5 +105,41 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
// All other data
|
||||
}
|
||||
|
||||
private int lastactorCount = 0;
|
||||
private int lastStageID = 0;
|
||||
private int lastStageCount = 0;
|
||||
private int lastStageWindowSize = 0;
|
||||
|
||||
public bool AnimationTimelinesNeedUpdate()
|
||||
{
|
||||
if (animationDef == null) return false;
|
||||
|
||||
bool update = false;
|
||||
|
||||
if (lastStageID != stageID)
|
||||
{ update = true; }
|
||||
|
||||
if (lastStageCount != animationDef.animationStages.Count)
|
||||
{ update = true; }
|
||||
|
||||
if (lastactorCount != animationDef.actors.Count)
|
||||
{ update = true; }
|
||||
|
||||
if (lastStageWindowSize != StageWindowSize)
|
||||
{ update = true; }
|
||||
|
||||
if (update)
|
||||
{
|
||||
lastStageID = stageID;
|
||||
lastStageCount = animationDef.animationStages.Count;
|
||||
lastactorCount = animationDef.actors.Count;
|
||||
lastStageWindowSize = StageWindowSize;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue