rimworld-animation-studio/Assets/Scripts/GUI/Cards/ActorKeyframeCard.cs
AbstractConcept a55ba7b95b Code refactor
2022-10-28 00:28:51 -05:00

67 lines
No EOL
3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class ActorKeyframeCard : Singleton<ActorKeyframeCard>
{
public InputField positionXField;
public InputField positionZField;
public InputField rotationField;
public InputField headBobField;
public InputField headRotationField;
public InputField appendageRotationField;
private Actor actor { get { return Workspace.GetCurrentActor(); } }
private void Start()
{
EventsManager.onAnimationChanged.AddListener(delegate { UpdateGUI(); });
EventsManager.onStageIDChanged.AddListener(delegate { UpdateGUI(); });
EventsManager.onActorIDChanged.AddListener(delegate { UpdateGUI(); });
EventsManager.onStageTickChanged.AddListener(delegate { UpdateGUI(); });
EventsManager.onKeyframeCountChanged.AddListener(delegate { UpdateGUI(); });
EventsManager.onPawnKeyframeChanged.AddListener(delegate { UpdateGUI(); });
positionXField.onEndEdit.AddListener(delegate { OnValueChanged(); });
positionZField.onEndEdit.AddListener(delegate { OnValueChanged(); });
rotationField.onEndEdit.AddListener(delegate { OnValueChanged(); });
headBobField.onEndEdit.AddListener(delegate { OnValueChanged(); });
headRotationField.onEndEdit.AddListener(delegate { OnValueChanged(); });
appendageRotationField.onEndEdit.AddListener(delegate { OnValueChanged(); });
UpdateGUI();
}
public void OnValueChanged()
{
PawnKeyframe keyframe = Workspace.GetCurrentPawnKeyframe(true);
keyframe.BodyOffsetX = float.Parse(positionXField.text);
keyframe.BodyOffsetZ = float.Parse(positionZField.text);
keyframe.BodyAngle = float.Parse(rotationField.text);
keyframe.HeadBob = float.Parse(headBobField.text);
keyframe.HeadAngle = float.Parse(headRotationField.text);
keyframe.GenitalAngle = float.Parse(appendageRotationField.text);
Workspace.GetCurrentPawnAnimationClip().BuildSimpleCurves();
Workspace.RecordEvent("Actor position / orientation");
}
public void UpdateGUI()
{
ActorPosition actorPosition = actor.GetCurrentPosition();
positionXField.SetTextWithoutNotify(string.Format("{0:0.000}", actorPosition.bodyOffsetX));
positionZField.SetTextWithoutNotify(string.Format("{0:0.000}", actorPosition.bodyOffsetZ));
rotationField.SetTextWithoutNotify(string.Format("{0:0.000}", actorPosition.bodyAngle));
headBobField.SetTextWithoutNotify(string.Format("{0:0.000}", actorPosition.headBob));
headRotationField.SetTextWithoutNotify(string.Format("{0:0.000}", actorPosition.headAngle));
appendageRotationField.SetTextWithoutNotify(string.Format("{0:0.000}", actorPosition.genitalAngle));
}
}
}