public static void ResolveApparelGraphics_Postfix(PawnGraphicSet __instance) { Pawn pawn = __instance.pawn; // Set up the hair cut graphic if (Controller.settings.MergeHair) { HairCutPawn hairPawn = CutHairDB.GetHairCache(pawn); List <Apparel> wornApparel = pawn.apparel.WornApparel .Where(x => x.def.apparel.LastLayer == ApparelLayerDefOf.Overhead).ToList(); HeadCoverage coverage = HeadCoverage.None; if (!wornApparel.NullOrEmpty()) { if (wornApparel.Any(x => x.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.UpperHead))) { coverage = HeadCoverage.UpperHead; } if (wornApparel.Any(x => x.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.FullHead))) { coverage = HeadCoverage.FullHead; } } if (coverage != 0) { hairPawn.HairCutGraphic = CutHairDB.Get <Graphic_Multi_Four>( pawn.story.hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, pawn.story.hairColor, coverage); } } }
private static T GetInner <T>(GraphicRequest req, HeadCoverage coverage) where T : Graphic, new() { string oldPath = req.path; string name = Path.GetFileNameWithoutExtension(oldPath); string newPath = MergedHairPath + name + "_" + coverage; req.path = newPath; if (AllGraphics.TryGetValue(req, out Graphic graphic)) { return((T)graphic); } // no graphics found, create => graphic = Activator.CreateInstance <T>(); // // Check if textures already present and readable, else create if (ContentFinder <Texture2D> .Get(req.path + "_back", false) != null) { graphic.Init(req); // graphic.MatFront.mainTexture = ContentFinder<Texture2D>.Get(newPath + "_front"); // graphic.MatSide.mainTexture = ContentFinder<Texture2D>.Get(newPath + "_side"); // graphic.MatBack.mainTexture = ContentFinder<Texture2D>.Get(newPath + "_back"); } else { req.path = oldPath; graphic.Init(req); Texture2D temptexturefront = graphic.MatFront.mainTexture as Texture2D; Texture2D temptextureside = graphic.MatSide.mainTexture as Texture2D; Texture2D temptextureback = graphic.MatBack.mainTexture as Texture2D; Texture2D temptextureside2 = (graphic as Graphic_Multi_Four)?.MatLeft.mainTexture as Texture2D; temptexturefront = FaceTextures.MakeReadable(temptexturefront); temptextureside = FaceTextures.MakeReadable(temptextureside); temptextureback = FaceTextures.MakeReadable(temptextureback); temptextureside2 = FaceTextures.MakeReadable(temptextureside2); // new mask textures if (coverage == HeadCoverage.UpperHead) { _maskTexFrontBack = FaceTextures.MaskTexUppherheadFrontBack; _maskTexSide = FaceTextures.MaskTexUpperheadSide; } else { _maskTexFrontBack = FaceTextures.MaskTexFullheadFrontBack; _maskTexSide = FaceTextures.MaskTexFullheadSide; } CutOutHair(ref temptexturefront, _maskTexFrontBack); CutOutHair(ref temptextureside, _maskTexSide); CutOutHair(ref temptextureback, _maskTexFrontBack); CutOutHair(ref temptextureside2, _maskTexSide); req.path = newPath; // if (!name.NullOrEmpty() && !File.Exists(req.path + "_front.png")) // { // byte[] bytes = temptexturefront.EncodeToPNG(); // File.WriteAllBytes(req.path + "_front.png", bytes); // byte[] bytes2 = temptextureside.EncodeToPNG(); // File.WriteAllBytes(req.path + "_side.png", bytes2); // byte[] bytes3 = temptextureback.EncodeToPNG(); // File.WriteAllBytes(req.path + "_back.png", bytes3); // } temptexturefront.Compress(true); temptextureside.Compress(true); temptextureback.Compress(true); temptextureside2.Compress(true); temptexturefront.mipMapBias = 0.5f; temptextureside.mipMapBias = 0.5f; temptextureback.mipMapBias = 0.5f; temptextureside2.mipMapBias = 0.5f; temptexturefront.Apply(false, true); temptextureside.Apply(false, true); temptextureback.Apply(false, true); temptextureside2.Apply(false, true); graphic.MatFront.mainTexture = temptexturefront; graphic.MatSide.mainTexture = temptextureside; graphic.MatBack.mainTexture = temptextureback; ((Graphic_Multi_Four)graphic).MatLeft.mainTexture = temptextureside2; // Object.Destroy(temptexturefront); // Object.Destroy(temptextureside); // Object.Destroy(temptextureback); } AllGraphics.Add(req, graphic); // } return((T)graphic); }
// ReSharper disable once MissingXmlDoc public static Graphic Get <T>(string path, Shader shader, Vector2 drawSize, Color color, HeadCoverage coverage) where T : Graphic, new() { // Added second 'color' to get a separate graphic GraphicRequest req = new GraphicRequest(typeof(T), path, shader, drawSize, color, color, null, 0); return(GetInner <T>(req, coverage)); }