rimworld-animations/1.5/Source/Utilities/AnimationUtility.cs

72 lines
2.3 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);
}
public static void StartGroupAnimation(List<Pawn> participants, GroupAnimationDef groupAnimationDef, int reorder)
{
for(int i = 0; i < participants.Count; i++)
{
//todo: pass all animationstages to ExtendedAnimator, and queue animations
participants[i].Drawer.renderer.SetAnimation(
groupAnimationDef.animationStages[0]
.GetAnimations((i + reorder) % participants.Count, GenTicks.TicksGame)[0].Item2);
}
}
public static void StopGroupAnimation(List<Pawn> participants)
{
foreach(Pawn pawn in participants)
{
pawn.Drawer.renderer.SetAnimation(null);
}
}
public static void StopGroupAnimation(Pawn participant)
{
participant?.Drawer?.renderer?.SetAnimation(null);
}
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;
Log.Message(DefDatabase<GroupAnimationDef>.AllDefsListForReading[0].defName);
DefDatabase<GroupAnimationDef>.AllDefsListForReading.TryRandomElement((GroupAnimationDef x) =>
x.canAnimationBeUsed(participants, out reorder2), out GroupAnimationDef result);
reorder = reorder2;
if (result != null) return result;
return null;
}
}
}