mirror of
https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
synced 2026-06-18 19:35:58 +00:00
88 lines
No EOL
2.6 KiB
C#
88 lines
No EOL
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Verse;
|
|
using UnityEngine;
|
|
using RimWorld;
|
|
|
|
public class PawnScaledOffsets : IExposable
|
|
{
|
|
|
|
public Vector3 smallestSizeOffset = Vector3.zero, largestSizeOffset = Vector3.zero;
|
|
public int smallestSizeRotation = 0, largestSizeRotation = 0;
|
|
|
|
public float smallestSize = -1, largestSize = -1; //-1 is uninitialized
|
|
|
|
public void AssignOffsets(Pawn pawn, Vector3 offset, int rotation)
|
|
{
|
|
if (pawn.BodySize == smallestSize && pawn.BodySize == largestSize)
|
|
{
|
|
smallestSizeOffset = largestSizeOffset = offset;
|
|
smallestSizeRotation = largestSizeRotation = rotation;
|
|
}
|
|
else if (pawn.BodySize < (smallestSize + largestSize) / 2)
|
|
{
|
|
|
|
if (largestSize == -1) largestSize = pawn.BodySize;
|
|
|
|
smallestSize = pawn.BodySize;
|
|
smallestSizeOffset = offset;
|
|
smallestSizeRotation = rotation;
|
|
}
|
|
else
|
|
{
|
|
|
|
if (smallestSize == -1) smallestSize = pawn.BodySize;
|
|
|
|
largestSize = pawn.BodySize;
|
|
largestSizeOffset = offset;
|
|
largestSizeRotation = rotation;
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
smallestSizeOffset = largestSizeOffset = Vector3.zero;
|
|
smallestSizeRotation = largestSizeRotation = 0;
|
|
smallestSize = largestSize = 1;
|
|
}
|
|
|
|
public void GetOffsets(Pawn pawn, out Vector3 offset, out int rotation)
|
|
{
|
|
|
|
if (smallestSize == largestSize)
|
|
{
|
|
offset = smallestSizeOffset;
|
|
rotation = smallestSizeRotation;
|
|
}
|
|
else
|
|
{
|
|
float t = InverseLerpUnclamped(smallestSize, largestSize, pawn.BodySize);
|
|
offset = Vector3.LerpUnclamped(smallestSizeOffset, largestSizeOffset, t);
|
|
rotation = (int)Mathf.LerpUnclamped(smallestSizeRotation, largestSizeRotation, t);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private static float InverseLerpUnclamped(float a, float b, float value)
|
|
{
|
|
return (value - a) / (b - a);
|
|
}
|
|
|
|
public virtual void ExposeData()
|
|
{
|
|
Scribe_Values.Look(ref smallestSizeOffset, "ScaledOffsets_SmallestSizeOffset");
|
|
Scribe_Values.Look(ref largestSizeOffset, "ScaledOffsets_largestSizeOffset");
|
|
|
|
Scribe_Values.Look(ref smallestSizeRotation, "ScaledOffsets_smallestSizeRotation");
|
|
Scribe_Values.Look(ref largestSizeRotation, "ScaledOffsets_largestSizeRotation");
|
|
|
|
Scribe_Values.Look(ref smallestSize, "ScaledOffsets_smallestSize");
|
|
Scribe_Values.Look(ref largestSize, "ScaledOffsets_largestSize");
|
|
}
|
|
|
|
|
|
} |