mirror of
https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
synced 2024-08-15 00:43:45 +00:00
105 lines
3.9 KiB
C#
105 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using RimWorld;
|
|
using rjw.Modules.Interactions.Helpers;
|
|
using rjw.Modules.Interactions.Objects;
|
|
using UnityEngine;
|
|
using Verse;
|
|
using Verse.AI;
|
|
using rjw.Modules.Interactions.Enums;
|
|
|
|
namespace Rimworld_Animations {
|
|
public static class AnimationUtility {
|
|
|
|
|
|
public static void StartAnimation(List<Pawn> participants)
|
|
{
|
|
participants[0].Drawer.renderer.SetAnimation(AnimationDefOf.TestAnimation1);
|
|
participants[1].Drawer.renderer.SetAnimation(AnimationDefOf.TestAnimation2);
|
|
}
|
|
|
|
//startgroupanimator with anchor
|
|
//don't anchor to self if anchor is self
|
|
public static void StartGroupAnimation(List<Pawn> participants, GroupAnimationDef groupAnimationDef, int reorder, Thing anchor)
|
|
{
|
|
|
|
int seed = GenTicks.TicksGame;
|
|
|
|
for (int i = 0; i < participants.Count; i++)
|
|
{
|
|
|
|
groupAnimationDef.GetOffset(i, participants[i], out Vector3? position, out int? rotation, reorder);
|
|
|
|
if (anchor is Pawn pawn && pawn == participants[i])
|
|
{
|
|
|
|
List<AnimationDef> allAnimationsForPawn = groupAnimationDef.GetAllAnimationsForActor(i, seed, reorder);
|
|
participants[i].TryGetComp<CompExtendedAnimator>().PlayGroupAnimation(allAnimationsForPawn, position, rotation);
|
|
}
|
|
else
|
|
{
|
|
//each participant gets their own unique extendedanimatoranchor, important for scribe_deep saving
|
|
List<AnimationDef> allAnimationsForPawn = groupAnimationDef.GetAllAnimationsForActor(i, seed, reorder);
|
|
BaseExtendedAnimatorAnchor animatorAnchor = new ExtendedAnimatorAnchor_Thing(anchor);
|
|
participants[i].TryGetComp<CompExtendedAnimator>().PlayGroupAnimation(allAnimationsForPawn, position, rotation, animatorAnchor);
|
|
}
|
|
}
|
|
}
|
|
|
|
//startgroupanimation without anchor; just play where standing
|
|
public static void StartGroupAnimation(List<Pawn> participants, GroupAnimationDef groupAnimationDef, int reorder)
|
|
{
|
|
int seed = GenTicks.TicksGame;
|
|
|
|
for (int i = 0; i < participants.Count; i++)
|
|
{
|
|
List<AnimationDef> allAnimationsForPawn = groupAnimationDef.GetAllAnimationsForActor(i, seed, reorder);
|
|
groupAnimationDef.GetOffset(i, participants[i], out Vector3? position, out int? rotation, reorder);
|
|
participants[i].TryGetComp<CompExtendedAnimator>().PlayGroupAnimation(allAnimationsForPawn, position, rotation);
|
|
}
|
|
}
|
|
|
|
|
|
public static void StopGroupAnimation(List<Pawn> participants)
|
|
{
|
|
foreach(Pawn pawn in participants)
|
|
{
|
|
pawn.TryGetComp<CompExtendedAnimator>()?.StopAnimating();
|
|
}
|
|
}
|
|
|
|
public static void StopGroupAnimation(Pawn participant)
|
|
{
|
|
participant.TryGetComp<CompExtendedAnimator>()?.StopAnimating();
|
|
}
|
|
|
|
public static GroupAnimationDef FindGroupAnimation(List<Pawn> participants, out int reorder)
|
|
{
|
|
// go through each context in each GroupAnimationDef
|
|
// if you find one where it returns canAnimationBeUsed (and reorders),
|
|
// return that animation
|
|
|
|
int reorder2 = 0;
|
|
|
|
DefDatabase<GroupAnimationDef>.AllDefsListForReading.TryRandomElement((GroupAnimationDef x) =>
|
|
x.canAnimationBeUsed(participants, out reorder2), out GroupAnimationDef result);
|
|
|
|
reorder = reorder2;
|
|
if (result != null) return result;
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
public static int GetAnimationLength(Pawn pawn)
|
|
{
|
|
return pawn.TryGetComp<CompExtendedAnimator>().AnimationLength;
|
|
}
|
|
|
|
}
|
|
}
|