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 PawnRenderNodeWorker_GraphicVariants : PawnRenderNodeWorker { public override bool CanDrawNow(PawnRenderNode node, PawnDrawParms parms) { if (!base.CanDrawNow(node, parms)) return false; if (parms.Portrait) return false; //don't draw if not visible at tick if (node.AnimationWorker is AnimationWorker_KeyframesExtended extendedAnimator && !extendedAnimator.visibleAtTick(node.tree.AnimationTick)) { return false; } return true; } protected override Material GetMaterial(PawnRenderNode node, PawnDrawParms parms) { //if node is animating, and is a graphic variant type of node //and node is one with graphic variants //and texpathvariant is set if ((node.AnimationWorker is AnimationWorker_KeyframesExtended extendedAnimWorker) && (node is PawnRenderNode_GraphicVariants nodeWithGraphicVariants) && extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick) != null) { Material materialVariant = GetMaterialVariant(nodeWithGraphicVariants, parms, (int)extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick)); if (materialVariant != null) { return materialVariant; } } //otherwise return original texture return base.GetMaterial(node, parms); } public virtual Material GetMaterialVariant(PawnRenderNode_GraphicVariants node, PawnDrawParms parms, int variant) { Material material = node.getGraphicVariant(variant)?.NodeGetMat(parms); if (material == null) return null; if (!parms.Portrait && parms.flags.FlagSet(PawnRenderFlags.Invisible)) { material = InvisibilityMatPool.GetInvisibleMat(material); } return material; } } }