rimworld-animations/1.5/Source/PawnRenderNode/PawnRenderNode_GraphicVariants.cs

60 lines
1.7 KiB
C#

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 PawnRenderNode_GraphicVariants : PawnRenderNode
{
private new PawnRenderNodeProperties_GraphicVariants props;
private Dictionary<int, Graphic> variants;
public Graphic getGraphicVariant(int variant)
{
return variants[variant];
}
public PawnRenderNode_GraphicVariants(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree) : base(pawn, props, tree) {
this.props = (PawnRenderNodeProperties_GraphicVariants)props;
}
protected override void EnsureMaterialsInitialized()
{
if (variants == null)
{
variants = GraphicVariantsFor(this.tree.pawn);
}
base.EnsureMaterialsInitialized();
}
protected virtual Dictionary<int, Graphic> GraphicVariantsFor(Pawn pawn)
{
Dictionary<int, Graphic> variantGraphics = new Dictionary<int, Graphic>();
Shader shader = this.ShaderFor(pawn);
//for each graphic variant
for (int i = 0; i < props.texPathVariants.Count; i++)
{
//get new graphic
Graphic variant = GraphicDatabase.Get<Graphic_Multi>(props.texPathVariants[i], shader, Vector2.one, this.ColorFor(pawn));
//add it to the variants dictionary; i + 1 for easier readability in logs
variantGraphics.Add(i + 1, variant);
}
return variantGraphics;
}
}
}