rimworld-animation-studio/Assets/Scripts/GUI/ActorKeyframeCard.cs

108 lines
4.2 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;
public void Update()
{
if (Workspace.animationDef == null)
{ return; }
positionXField.interactable = AnimationController.Instance.isAnimating == false;
positionZField.interactable = AnimationController.Instance.isAnimating == false;
rotationField.interactable = AnimationController.Instance.isAnimating == false;
headBobField.interactable = AnimationController.Instance.isAnimating == false;
headRotationField.interactable = AnimationController.Instance.isAnimating == false;
appendageRotationField.interactable = AnimationController.Instance.isAnimating == false;
}
public void OnValueChanged()
{
PawnKeyframe keyframe = Workspace.Instance.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.animationDef.actors[Workspace.actorID].controlGenitalAngle = keyframe.genitalAngle != 0;
Workspace.Instance.GetPawnAnimationClip(Workspace.actorID).BuildSimpleCurves();
Workspace.Instance.RecordEvent("Actor position / orientation");
}
public void AdjustActor(Vector2 deltaOffset)
{
float deltaAngle = -deltaOffset.x * 33.3333f + deltaOffset.y * 33.3333f;
int facing = deltaOffset.x < 0 ? 3 : deltaOffset.y < 0 ? 2 : deltaOffset.x > 0 ? 1 : 0;
switch (Workspace.actorManipulationMode)
{
case ActorManipulationMode.Pan: MoveActor(deltaOffset); break;
case ActorManipulationMode.Rotate: RotateActor(deltaAngle); break;
case ActorManipulationMode.Face: FaceActor(facing); break;
}
}
public void MoveActor(Vector2 deltaOffset)
{
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(true);
if (Workspace.selectedBodyPart == null)
{
keyframe.bodyOffsetX += deltaOffset.x;
keyframe.bodyOffsetZ += deltaOffset.y;
}
else if (Workspace.selectedBodyPart.isHead)
{ keyframe.headBob += deltaOffset.y; }
Workspace.Instance.GetCurrentPawnAnimationClip().BuildSimpleCurves();
Workspace.Instance.RecordEvent("Actor position / orientation");
}
public void RotateActor(float deltaAngle)
{
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(true);
if (Workspace.selectedBodyPart == null)
{ keyframe.bodyAngle += deltaAngle; }
else if (Workspace.selectedBodyPart.isHead)
{ keyframe.headAngle += deltaAngle; }
else
{ keyframe.genitalAngle -= deltaAngle; }
Workspace.Instance.GetCurrentPawnAnimationClip().BuildSimpleCurves();
Workspace.Instance.RecordEvent("Actor position / orientation");
}
public void FaceActor(int facing)
{
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(true);
if (Workspace.selectedBodyPart == null)
{ keyframe.bodyFacing = facing; }
else if (Workspace.selectedBodyPart.isHead)
{ keyframe.headFacing = facing; }
Workspace.Instance.GetCurrentPawnAnimationClip().BuildSimpleCurves();
Workspace.Instance.RecordEvent("Actor position / orientation");
}
}
}