fix(dvergur): tint the skin from UpdateColors, and raise the height
The tint was applied the way the race-selection menu appears to do it, with VisEquipment.SetSkinColor followed by UpdateColors, and had no visible effect. That pair is not what colours a player: UpdateColors rebuilds the body material from Valheim own state each refresh, so a tint only survives if it is written after it runs. Every race here that visibly changes colour already has a postfix on UpdateColors setting _SkinColor on the material, and the SetSkinColor calls in the menu are decorative on their own. The Dvergur now follows the Trol. Reading the race from the ZDO with a m_customData fallback and no local-player check covers the main-menu preview and the first spawn frame, where Player.m_localPlayer is still null. Nothing needs saving or restoring either, since the tint stops being applied the moment the race changes. Beard and hair go pale to match; the hood hides most of the hair but the beard shows. Height goes from 0.70 to 0.78. The spec asked for at least -30% but that read as too small beside a human on screen.
This commit is contained in:
parent
79a54fb533
commit
8df7681cea
4 changed files with 60 additions and 47 deletions
|
|
@ -300,6 +300,52 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
// ─── Skin ────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Tints the Dvergur ashen grey.
|
||||
///
|
||||
/// The first attempt did this the way the race-selection menu appears to - VisEquipment's
|
||||
/// SetSkinColor followed by UpdateColors - and nothing happened, because that pair is not
|
||||
/// what actually colours a player. UpdateColors rebuilds the body material from Valheim's
|
||||
/// own state on every refresh, so any tint has to be written *after* it runs. That is why
|
||||
/// every race in this mod that visibly changes colour has a postfix here writing
|
||||
/// _SkinColor onto the material directly, and why the SetSkinColor calls in the selection
|
||||
/// menu are, on their own, decorative.
|
||||
///
|
||||
/// No local-player check and no saved original: the race is read from the ZDO with a
|
||||
/// m_customData fallback so the main-menu preview and the first spawn frame are covered
|
||||
/// too, and the tint simply stops being applied once the player is no longer a Dvergur.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateColors")]
|
||||
public static class Dvergur_VisEquipment_UpdateColors_Patch
|
||||
{
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (__instance == null || !__instance.m_isPlayer) return;
|
||||
|
||||
Player player = __instance.GetComponent<Player>();
|
||||
if (player == null || !DvergurVisuals.IsDvergurPlayer(player)) return;
|
||||
|
||||
if (__instance.m_bodyModel != null && __instance.m_bodyModel.material != null)
|
||||
{
|
||||
__instance.m_bodyModel.material.SetColor("_SkinColor", DvergurConfig.SkinColor);
|
||||
}
|
||||
|
||||
TintRenderers(Traverse.Create(__instance).Field("m_hairItemInstance").GetValue<GameObject>());
|
||||
TintRenderers(Traverse.Create(__instance).Field("m_beardItemInstance").GetValue<GameObject>());
|
||||
}
|
||||
|
||||
private static void TintRenderers(GameObject instance)
|
||||
{
|
||||
if (instance == null) return;
|
||||
foreach (Renderer renderer in instance.GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
if (renderer.material != null) renderer.material.SetColor("_SkinColor", DvergurConfig.HairColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Cosmetic hood ───────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue