rimworld-animations/1.5/Source/RenderSubWorkers/PawnRenderSubWorker_ChangeOffset.cs

51 lines
1.6 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
namespace Rimworld_Animations
{
public class PawnRenderSubWorker_ChangeOffset : PawnRenderSubWorker
{
public override void TransformOffset(PawnRenderNode node, PawnDrawParms parms, ref Vector3 offset, ref Vector3 pivot)
{
if (node.AnimationWorker is AnimationWorker_KeyframesExtended
&& node.tree.pawn.TryGetComp<CompExtendedAnimator>(out CompExtendedAnimator extendedAnimator)
&& extendedAnimator.IsAnimating)
{
Vector3? pawnOffset = extendedAnimator.Offset;
if (pawnOffset != null)
{
offset += (Vector3)pawnOffset;
}
}
}
public override void TransformRotation(PawnRenderNode node, PawnDrawParms parms, ref Quaternion rotation)
{
if (node.AnimationWorker is AnimationWorker_KeyframesExtended
&& node.tree.pawn.TryGetComp<CompExtendedAnimator>(out CompExtendedAnimator extendedAnimator)
&& extendedAnimator.IsAnimating)
{
int? pawnRotation = extendedAnimator.Rotation;
if (pawnRotation != null)
{
Quaternion additionalRotation = Quaternion.AngleAxis((int)pawnRotation, Vector3.up);
rotation *= additionalRotation;
}
}
base.TransformRotation(node, parms, ref rotation);
}
}
}