2022-09-16 22:50:15 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace RimWorldAnimationStudio
|
|
|
|
|
{
|
|
|
|
|
public class ActorKeyframeCard : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public InputField positionXField;
|
|
|
|
|
public InputField positionZField;
|
|
|
|
|
public InputField rotationField;
|
|
|
|
|
|
|
|
|
|
private int lastTick = -1;
|
|
|
|
|
private bool isDirty = false;
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
|
|
|
|
if ((Workspace.animationDef == null || AnimationController.Instance.stageTick == lastTick) && isDirty == false)
|
|
|
|
|
{ return; }
|
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
if (Workspace.actorID >= AnimationController.Instance.transform.childCount)
|
|
|
|
|
{ return; }
|
|
|
|
|
|
2022-09-19 05:35:34 +00:00
|
|
|
|
ActorBody actorBody = AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>()[Workspace.actorID];
|
2022-09-18 00:06:33 +00:00
|
|
|
|
string bodyType = actorBody.bodyType;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
|
|
|
|
PawnAnimationClip clip = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[Workspace.actorID];
|
|
|
|
|
float clipPercent = (float)(AnimationController.Instance.stageTick % clip.duration) / clip.duration;
|
|
|
|
|
|
|
|
|
|
Vector3 deltaPos = new Vector3(clip.BodyOffsetX.Evaluate(clipPercent), 0, clip.BodyOffsetZ.Evaluate(clipPercent));
|
|
|
|
|
deltaPos += Workspace.animationDef.actors[Workspace.actorID].bodyTypeOffset.GetOffset(bodyType);
|
|
|
|
|
|
|
|
|
|
float bodyAngle = clip.BodyAngle.Evaluate(clipPercent);
|
|
|
|
|
float headAngle = clip.HeadAngle.Evaluate(clipPercent);
|
|
|
|
|
|
|
|
|
|
if (bodyAngle < 0) bodyAngle = 360 - ((-1f * bodyAngle) % 360);
|
|
|
|
|
if (bodyAngle > 360) bodyAngle %= 360;
|
|
|
|
|
|
|
|
|
|
if (headAngle < 0) headAngle = 360 - ((-1f * headAngle) % 360);
|
|
|
|
|
if (headAngle > 360) headAngle %= 360;
|
|
|
|
|
|
|
|
|
|
int bodyFacing = (int)clip.BodyFacing.Evaluate(clipPercent);
|
|
|
|
|
Vector3 headBob = new Vector3(0, 0, clip.HeadBob.Evaluate(clipPercent)) + PawnUtility.BaseHeadOffsetAt(bodyType, bodyFacing);
|
|
|
|
|
|
|
|
|
|
Vector3 bodyPos = new Vector3(deltaPos.x, deltaPos.z, 0);
|
|
|
|
|
Vector3 headPos = new Vector3(headBob.x, headBob.z, 0);
|
|
|
|
|
|
|
|
|
|
positionXField.text = bodyPos.x.ToString("0.000");
|
|
|
|
|
positionZField.text = bodyPos.y.ToString("0.000");
|
|
|
|
|
rotationField.text = bodyAngle.ToString("0.000");
|
|
|
|
|
|
|
|
|
|
lastTick = AnimationController.Instance.stageTick;
|
|
|
|
|
isDirty = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnValueChanged()
|
|
|
|
|
{
|
|
|
|
|
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[Workspace.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).bodyOffsetX = float.Parse(positionXField.text);
|
|
|
|
|
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[Workspace.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).bodyOffsetZ = float.Parse(positionZField.text);
|
|
|
|
|
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[Workspace.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).bodyAngle = float.Parse(rotationField.text);
|
|
|
|
|
|
|
|
|
|
Workspace.Instance.GetPawnAnimationClip(Workspace.actorID).BuildSimpleCurves();
|
|
|
|
|
isDirty = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|