mirror of
https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
synced 2024-08-15 00:43:45 +00:00
79 lines
2.2 KiB
C#
79 lines
2.2 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
|
|
{
|
|
|
|
protected new PawnRenderNodeProperties_GraphicVariants props;
|
|
protected Dictionary<int, Graphic> variants;
|
|
|
|
public Graphic getGraphicVariant(int variant)
|
|
{
|
|
if (variants == null || !variants.ContainsKey(variant))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return variants[variant];
|
|
}
|
|
|
|
public PawnRenderNode_GraphicVariants(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree) : base(pawn, props, tree) {
|
|
|
|
this.props = (PawnRenderNodeProperties_GraphicVariants)props;
|
|
|
|
}
|
|
|
|
protected virtual Dictionary<int, Graphic> GraphicVariantsFor(Pawn pawn)
|
|
{
|
|
|
|
if (props.texPathVariantsDef == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return GenerateVariants(pawn, props.texPathVariantsDef);
|
|
|
|
}
|
|
|
|
protected override void EnsureMaterialsInitialized()
|
|
{
|
|
|
|
if (variants == null)
|
|
{
|
|
variants = GraphicVariantsFor(this.tree.pawn);
|
|
}
|
|
|
|
base.EnsureMaterialsInitialized();
|
|
}
|
|
|
|
|
|
//used by all, including base classes, to create texPathVariants for pawn
|
|
protected Dictionary<int, Graphic> GenerateVariants(Pawn pawn, TexPathVariantsDef texPathVariants)
|
|
{
|
|
|
|
Dictionary<int, Graphic> variantGraphics = new Dictionary<int, Graphic>();
|
|
|
|
//for each graphic variant
|
|
for (int i = 0; i < texPathVariants.variants.Count; i++)
|
|
{
|
|
|
|
//get new graphic
|
|
Graphic variant = GraphicDatabase.Get<Graphic_Multi>(texPathVariants.variants[i], this.ShaderFor(pawn), 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;
|
|
|
|
}
|
|
}
|
|
}
|