rimworld-animations-patch_m.../Source/Scripts/Defs/ApparelTexture2DPack.cs

58 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using RimWorld;
using UnityEngine;
namespace Rimworld_Animations_Patch
{
public class ApparelTexture2DPack
{
public List<Texture2D> textures = new List<Texture2D>();
private static Dictionary<string, ApparelTexture2DPack> cachedMaskTextures = new Dictionary<string, ApparelTexture2DPack>();
public static ApparelTexture2DPack PackMaskTextures(string path)
{
ApparelTexture2DPack pack = new ApparelTexture2DPack();
for (int i = 0; i < 3; i++)
{
string direction = new Rot4(i).ToStringWord().ToLower();
Texture2D maskTexture = ContentFinder<Texture2D>.Get(path + "_" + direction, true);
pack.textures.Add(maskTexture);
}
return pack;
}
public static ApparelTexture2DPack GetCachedMaskTexturesForBodyType(BodyTypeDef bodyType)
{
string path = "Masks/apparel_shirt_mask_" + bodyType.defName;
if (cachedMaskTextures.TryGetValue(path, out ApparelTexture2DPack pack) == false)
{ pack = PackMaskTextures(path); }
return pack;
}
public void PackTexturesForBodyType(Graphic graphic, BodyTypeDef bodyType)
{
textures.Clear();
for (int i = 0; i < 3; i++)
{
Texture2D origTexture = (Texture2D)graphic.MatAt(new Rot4(i)).mainTexture;
Texture2D maskTexture = GetCachedMaskTexturesForBodyType(bodyType).textures[i];
Texture2D maskedTexture = GraphicMaskingUtility.ApplyMaskToTexture2D(origTexture, maskTexture, true);
textures.Add(maskedTexture);
}
}
}
}