Brings in the Sverm race, the War Vulture flying mount, and Skadi's Crystal Golem (replacing the Hidden Hollow). Resolved conflicts: AswidVisuals.cs took war-vulture's skeleton-eye-light rewrite with main's attach/attack/sleep timing guard re-applied on top, and RaceCompendium.cs kept main's rewritten race entries while folding in war-vulture's Sverm/War Vulture pages and the new Claws paragraphs for Aswid and Fenrir.
588 lines
28 KiB
C#
588 lines
28 KiB
C#
using System.Collections.Generic;
|
|
using Jotunn.Managers;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// The Aswid's burning eyes: the vanilla skeleton's own eye lights, worn spectral green until
|
|
/// the last tier and red once it arrives.
|
|
///
|
|
/// They used to be two spheres built from scratch on an Unlit/Color shader, the same trick the
|
|
/// Dvergar and the Sverm still use, because a player's eyes are painted into the skin texture
|
|
/// and Custom/Player has no emission channel to light them with. Those spheres were fine and
|
|
/// they were also obviously spheres. What the game already has is better: the creature named
|
|
/// 'Skeleton' carries two objects, eye_l and eye_r, parented to its Head bone and drawn with a
|
|
/// material built for exactly this - a lit socket seen from any angle.
|
|
///
|
|
/// Borrowing them is cheap because the skeleton is skinned to the player's own rig: its Head
|
|
/// bone is our Head bone, so the local pose those two objects were authored at lands on a
|
|
/// player's face without a single measurement. The placement config below is deltas on top of
|
|
/// that pose, not a placement of its own, and 0 means "wherever the game put them".
|
|
///
|
|
/// Only the Aswid is changed by this file. The Dvergar (DvergarVisuals) and the Sverm
|
|
/// (SvermVisuals) keep their own spheres - they each own a copy of the sphere code, so nothing
|
|
/// here reaches them.
|
|
///
|
|
/// Runs for local and remote players alike, which is why it takes a Player rather than reading
|
|
/// Player.m_localPlayer.
|
|
/// </summary>
|
|
public static class AswidVisuals
|
|
{
|
|
private const string EyesName = "AswidEyes";
|
|
|
|
// The two objects to look for inside whichever creature the config points at. Both vanilla
|
|
// skeletons carry this pair; the material differs (skeleton_eye vs skeleton_eye_big) and
|
|
// that difference is the whole reason the source is a config and not a constant.
|
|
private static readonly string[] SourceEyeNames = { "eye_l", "eye_r" };
|
|
|
|
public const string PlayerHeadBoneName = "Head";
|
|
|
|
// ─── Placement, and why the numbers are unitless ─────────────────────
|
|
// The offsets below are applied as: local offset = config x scale x (1 / headBone.lossyScale)
|
|
// and lossyScale is the armature's authored 100x times the player's own scale, so the
|
|
// scale cancels and a given config value lands on the same part of the face at any size -
|
|
// Fader-tier growth included. Kept in the arithmetic because it is honest about intent.
|
|
|
|
// ─── Race check ─────────────────────────────────────────────────────
|
|
|
|
/// <summary>
|
|
/// Reads the race off the ZDO so remote players render correctly, falling back to
|
|
/// m_customData for the main-menu preview which has no ZNetView. Mirrors the check
|
|
/// AswidSkinColorPatch already does inline in AswidPatches.cs.
|
|
/// </summary>
|
|
private static bool IsAswidPlayer(Player player)
|
|
{
|
|
if (player == null) return false;
|
|
|
|
ZNetView nview = player.GetComponent<ZNetView>();
|
|
if (nview != null && nview.IsValid())
|
|
{
|
|
return nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Aswid";
|
|
}
|
|
|
|
return player.m_customData != null &&
|
|
player.m_customData.TryGetValue("Race", out string race) &&
|
|
race == "Aswid";
|
|
}
|
|
|
|
// ─── Eyes ───────────────────────────────────────────────────────────
|
|
|
|
/// <summary>
|
|
/// The skull's own idea of forward, up and right, measured once while the head is still
|
|
/// looking where the body is, plus what the eyes currently in place were built from. Kept
|
|
/// on the eye holder so it survives as long as the eyes do, and so nothing is tempted to
|
|
/// work it out again from a rig that has since moved.
|
|
/// </summary>
|
|
private class EyeFrame : MonoBehaviour
|
|
{
|
|
public Vector3 LocalForward = Vector3.forward;
|
|
public Vector3 LocalUp = Vector3.up;
|
|
public Vector3 LocalRight = Vector3.right;
|
|
|
|
// What these eyes were cloned from, and whether they were flattened onto a plain
|
|
// colour shader. Either one changing in Configuration Manager means the pair has to be
|
|
// built again rather than merely moved.
|
|
public string SourceModel = "";
|
|
public bool FlatShader;
|
|
}
|
|
|
|
/// <summary>The pose an eye was authored at on the creature. Everything else is a delta on this.</summary>
|
|
private class EyeBase : MonoBehaviour
|
|
{
|
|
public Vector3 Position;
|
|
public Quaternion Rotation = Quaternion.identity;
|
|
public Vector3 Scale = Vector3.one;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reapplies the eyes every frame, which is what makes the Configuration Manager sliders
|
|
/// move them while you watch. Added to a player once they turn out to be an Aswid and
|
|
/// destroyed when they stop being one; VisEquipment's own refresh is what puts it back.
|
|
/// </summary>
|
|
public class EyeTicker : MonoBehaviour
|
|
{
|
|
private Player m_player;
|
|
|
|
private void Awake()
|
|
{
|
|
m_player = GetComponent<Player>();
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (m_player == null)
|
|
{
|
|
Destroy(this);
|
|
return;
|
|
}
|
|
|
|
ApplyEyes(m_player);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Keeps the pair of lit sockets burning over the player's painted-on eyes. Safe to call
|
|
/// for anyone: it removes them again from whoever is not a living Aswid.
|
|
///
|
|
/// Parented straight onto the head bone rather than Character.m_eye - the Dvergar tried
|
|
/// m_eye first and found it sits half a metre above the head bone, outside the scaled rig
|
|
/// entirely, which floated the eyes above the model and turned them with the camera
|
|
/// instead of the face. Anchoring on the bone itself sidesteps both.
|
|
/// </summary>
|
|
public static void ApplyEyes(Player player)
|
|
{
|
|
if (player == null) return;
|
|
|
|
Transform headBone = FindHeadBone(player);
|
|
if (headBone == null) return; // rig not up yet; try again next frame
|
|
|
|
Transform eyes = headBone.Find(EyesName);
|
|
|
|
if (!IsAswidPlayer(player) || player.IsDead())
|
|
{
|
|
if (eyes != null)
|
|
{
|
|
// Renamed first: Destroy is deferred to the end of the frame, and every call
|
|
// until then would otherwise find it again.
|
|
eyes.name = EyesName + "_Removed";
|
|
Object.Destroy(eyes.gameObject);
|
|
}
|
|
|
|
EyeTicker ticker = player.GetComponent<EyeTicker>();
|
|
if (ticker != null) Object.Destroy(ticker);
|
|
return;
|
|
}
|
|
|
|
if (player.GetComponent<EyeTicker>() == null)
|
|
{
|
|
player.gameObject.AddComponent<EyeTicker>();
|
|
}
|
|
|
|
// A different source creature, or the shader override being flipped, changes what the
|
|
// eyes are rather than where they sit - so the pair is thrown away and built again.
|
|
if (eyes != null)
|
|
{
|
|
EyeFrame existing = eyes.GetComponent<EyeFrame>();
|
|
if (existing == null ||
|
|
existing.SourceModel != AswidConfig.EyeSourceModel.Value ||
|
|
existing.FlatShader != AswidConfig.EyeFlatColorShader.Value)
|
|
{
|
|
eyes.name = EyesName + "_Removed";
|
|
Object.Destroy(eyes.gameObject);
|
|
eyes = null;
|
|
}
|
|
}
|
|
|
|
if (eyes == null)
|
|
{
|
|
// BuildEyes takes a one-time reading of the head bone's pose to work out which way
|
|
// the skull faces, and caches it for as long as the eyes exist. Sitting, attached,
|
|
// mid-attack or asleep, the head can be turned away from the body's own forward at
|
|
// that instant, which is how the snap-to-axis has picked the wrong side and left
|
|
// the eyes behind the skull before (see DvergarVisuals.ApplyEyes). Waiting for a
|
|
// plain standing pose costs nothing - ApplyEyes runs again on the next tick either
|
|
// way.
|
|
if (player.IsAttached() || player.IsAttachedToShip() || player.InAttack() || player.IsSleeping())
|
|
{
|
|
return;
|
|
}
|
|
eyes = BuildEyes(player, headBone);
|
|
}
|
|
if (eyes == null) return; // already logged once by the builder
|
|
|
|
PlaceEyes(player, headBone, eyes);
|
|
PaintEyes(eyes, GetEyeColor(player));
|
|
}
|
|
|
|
/// <summary>
|
|
/// The head bone the body mesh is actually skinned to - not the Animator's. See
|
|
/// DvergarVisuals.FindHeadBone for why: the avatar's HumanBodyBones.Head moves with the
|
|
/// player but ignores the head's own idle animation, and only VisEquipment.m_bodyModel's
|
|
/// own bone array is the one the skinned mesh - and every animation - actually drives.
|
|
///
|
|
/// THE ANIMATOR'S HEAD IS NOT AN ACCEPTABLE ANSWER, and this used to fall back to it
|
|
/// "so that something renders if the body model is not up yet". That fallback is what put
|
|
/// the eyes at the wrong height: the avatar's HumanBodyBones.Head is a DIFFERENT transform,
|
|
/// sitting at a different place in the hierarchy, so a holder parented to it hangs at the
|
|
/// wrong height for as long as it lives - and it lives until the player changes race. It
|
|
/// only ever bit once the claws landed, because equipping an item on spawn moved the first
|
|
/// build a few frames earlier, into the window where the body model is not up yet.
|
|
///
|
|
/// Returning null costs nothing: the ticker calls this again next frame, and a frame with
|
|
/// no eyes is invisible next to a session with them on the jaw.
|
|
/// </summary>
|
|
private static Transform FindHeadBone(Player player)
|
|
{
|
|
VisEquipment visEq = player.GetComponent<VisEquipment>();
|
|
if (visEq == null || visEq.m_bodyModel == null || visEq.m_bodyModel.bones == null) return null;
|
|
|
|
foreach (Transform bone in visEq.m_bodyModel.bones)
|
|
{
|
|
if (bone != null && bone.name == PlayerHeadBoneName) return bone;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// How much bigger than baseline this particular Aswid currently is. Read straight off the
|
|
/// player root, not off the "Visual" child the Dvergar reads: the Fader-tier growth
|
|
/// (AswidPatches.cs, Aswid_PlayerUpdate_Patch) scales __instance.transform - the root -
|
|
/// directly, so that is where the +10% actually lives.
|
|
/// </summary>
|
|
private static float GetPlayerScale(Player player) => player.transform.localScale.x;
|
|
|
|
/// <summary>
|
|
/// The tier this particular Aswid is rendering at. Off the ZDO, so a remote player's eyes
|
|
/// burn at their own standing rather than at ours; without one - the main-menu preview -
|
|
/// fall back to what this client can work out, the same fallback the Skeleton's visuals
|
|
/// make (SkeletonVisuals.GetProgressionState).
|
|
/// </summary>
|
|
private static int GetProgressionState(Player player)
|
|
{
|
|
ZNetView nview = player != null ? player.GetComponent<ZNetView>() : null;
|
|
if (nview != null && nview.IsValid())
|
|
{
|
|
return nview.GetZDO().GetInt("RacesOfValheim_AswidState", 0);
|
|
}
|
|
|
|
return BossProgressionManager.GetCurrentProgressionState();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Spectral green for as long as the Aswid is still becoming one, and red only at the end.
|
|
///
|
|
/// The red was the colour from the start and it reads as arrival, so it is worth not
|
|
/// spending it early: every tier below the last burns a cold green instead, dimmer on
|
|
/// purpose - the green is the eyes of something dead, the red is the eyes of something
|
|
/// that has finished feeding. Each has its own brightness rather than sharing one, because
|
|
/// "not too bright" is exactly the difference between them.
|
|
/// </summary>
|
|
private static Color GetEyeColor(Player player)
|
|
{
|
|
bool final = GetProgressionState(player) >= AswidConfig.EyeFinalStage.Value;
|
|
|
|
float strength = final
|
|
? AswidConfig.EyeGlowStrength.Value
|
|
: AswidConfig.EarlyEyeGlowStrength.Value;
|
|
|
|
Color hue = final
|
|
? new Color(AswidConfig.EyeColorRed.Value, AswidConfig.EyeColorGreen.Value, AswidConfig.EyeColorBlue.Value)
|
|
: new Color(AswidConfig.EarlyEyeColorRed.Value, AswidConfig.EarlyEyeColorGreen.Value, AswidConfig.EarlyEyeColorBlue.Value);
|
|
|
|
return new Color(hue.r * strength, hue.g * strength, hue.b * strength, 1f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves each eye off the pose it was authored at, by the config's deltas, in the head
|
|
/// bone's own coordinates. Every value at 0 (and size at 1) leaves them exactly where the
|
|
/// game's own skeleton wears them, which is the intended starting point.
|
|
///
|
|
/// See DvergarVisuals.PlaceEyes for the full derivation of the axes: they are measured
|
|
/// once at build time and snapped to the skull's square axes, because the raw measurement
|
|
/// is taken at whatever pose the head happens to hold that frame and arrives tilted.
|
|
/// </summary>
|
|
private static void PlaceEyes(Player player, Transform headBone, Transform holder)
|
|
{
|
|
float lossy = headBone.lossyScale.x;
|
|
if (Mathf.Abs(lossy) < 0.0001f) return;
|
|
|
|
float toLocal = 1f / lossy;
|
|
|
|
EyeFrame frame = holder.GetComponent<EyeFrame>();
|
|
if (frame == null) return;
|
|
|
|
float scale = GetPlayerScale(player) * toLocal;
|
|
|
|
Vector3 shift = frame.LocalForward * (AswidConfig.EyeForwardOffset.Value * scale)
|
|
+ frame.LocalUp * (AswidConfig.EyeHeightOffset.Value * scale);
|
|
|
|
Quaternion twist = Quaternion.Euler(
|
|
AswidConfig.EyeRotationX.Value,
|
|
AswidConfig.EyeRotationY.Value,
|
|
AswidConfig.EyeRotationZ.Value);
|
|
|
|
for (int i = 0; i < holder.childCount; i++)
|
|
{
|
|
Transform eye = holder.GetChild(i);
|
|
EyeBase authored = eye.GetComponent<EyeBase>();
|
|
if (authored == null) continue;
|
|
|
|
// Which way "outwards" is for this particular eye, read from where the creature
|
|
// put it rather than from the order the children happen to be in. Widening then
|
|
// pushes both eyes apart whichever one this is.
|
|
float side = Mathf.Sign(Vector3.Dot(authored.Position, frame.LocalRight));
|
|
if (side == 0f) side = i == 0 ? -1f : 1f;
|
|
|
|
eye.localPosition = authored.Position + shift +
|
|
frame.LocalRight * (side * AswidConfig.EyeSeparationOffset.Value * scale);
|
|
eye.localRotation = twist * authored.Rotation;
|
|
eye.localScale = authored.Scale * AswidConfig.EyeSizeMultiplier.Value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tints the borrowed material red - the one thing about these eyes that is not the
|
|
/// skeleton's.
|
|
///
|
|
/// Every colour property the shader turns out to have is written, rather than guessing
|
|
/// which one it uses: a Valheim VFX material can carry _Color, _TintColor, _EmissionColor
|
|
/// or none of them, and writing a property a shader does not have is an error while
|
|
/// writing all of the ones it does is free.
|
|
/// </summary>
|
|
private static void PaintEyes(Transform holder, Color glow)
|
|
{
|
|
bool smoke = AswidConfig.EyeSmoke.Value;
|
|
|
|
foreach (Renderer renderer in holder.GetComponentsInChildren<Renderer>(true))
|
|
{
|
|
Material material = renderer.material;
|
|
if (material == null) continue;
|
|
|
|
if (material.HasProperty("_Color")) material.SetColor("_Color", glow);
|
|
if (material.HasProperty("_TintColor")) material.SetColor("_TintColor", glow);
|
|
if (material.HasProperty("_BaseColor")) material.SetColor("_BaseColor", glow);
|
|
if (material.HasProperty("_EmissionColor")) material.SetColor("_EmissionColor", glow);
|
|
}
|
|
|
|
// The smoke curling out of the sockets is authored on the creature but left switched
|
|
// off there, waiting for a script that this clone does not have. Off by default here
|
|
// too: it is a much louder effect than the glow itself.
|
|
foreach (ParticleSystem ps in holder.GetComponentsInChildren<ParticleSystem>(true))
|
|
{
|
|
if (ps.gameObject.activeSelf != smoke) ps.gameObject.SetActive(smoke);
|
|
if (!smoke) continue;
|
|
|
|
ParticleSystem.MainModule main = ps.main;
|
|
main.startColor = new ParticleSystem.MinMaxGradient(glow);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rounds a direction to the nearest of the six axis directions. Whichever component is
|
|
/// largest wins, sign included.
|
|
/// </summary>
|
|
private static Vector3 SnapToAxis(Vector3 direction)
|
|
{
|
|
float x = Mathf.Abs(direction.x);
|
|
float y = Mathf.Abs(direction.y);
|
|
float z = Mathf.Abs(direction.z);
|
|
|
|
if (x >= y && x >= z) return new Vector3(Mathf.Sign(direction.x), 0f, 0f);
|
|
if (y >= z) return new Vector3(0f, Mathf.Sign(direction.y), 0f);
|
|
return new Vector3(0f, 0f, Mathf.Sign(direction.z));
|
|
}
|
|
|
|
private static Transform BuildEyes(Player player, Transform headBone)
|
|
{
|
|
string modelName = AswidConfig.EyeSourceModel.Value;
|
|
|
|
List<Transform> sources = FindSourceEyes(modelName);
|
|
if (sources.Count == 0) return null; // already logged once by the finder
|
|
|
|
// Anything of ours left anywhere else on this player goes first. ApplyEyes only ever
|
|
// looks under the head bone, so a holder that ended up on some other transform is
|
|
// invisible to it - it would build a second pair beside the wrong one rather than
|
|
// replace it. That is exactly the state the animator fallback used to leave behind.
|
|
SweepStrayHolders(player, headBone);
|
|
|
|
GameObject holder = new GameObject(EyesName);
|
|
holder.transform.SetParent(headBone, false);
|
|
holder.transform.localPosition = Vector3.zero;
|
|
holder.transform.localRotation = Quaternion.identity;
|
|
holder.transform.localScale = Vector3.one;
|
|
|
|
// Ask the rig which way it faces, once, and round the answer to the skull's own axes -
|
|
// see DvergarVisuals.BuildEyes for why the raw, unrounded measurement puts the eyes at
|
|
// the jaw instead of the eye line.
|
|
Transform root = headBone.root;
|
|
EyeFrame frame = holder.AddComponent<EyeFrame>();
|
|
frame.LocalForward = SnapToAxis(headBone.InverseTransformDirection(root.forward));
|
|
frame.LocalUp = SnapToAxis(headBone.InverseTransformDirection(root.up));
|
|
frame.LocalRight = Vector3.Cross(frame.LocalUp, frame.LocalForward).normalized;
|
|
frame.SourceModel = modelName;
|
|
frame.FlatShader = AswidConfig.EyeFlatColorShader.Value;
|
|
|
|
foreach (Transform source in sources)
|
|
{
|
|
GameObject eye = Object.Instantiate(source.gameObject, holder.transform);
|
|
eye.name = source.name;
|
|
|
|
// Remembered before anything moves it, because everything the config does is
|
|
// expressed as a delta on this.
|
|
EyeBase authored = eye.AddComponent<EyeBase>();
|
|
authored.Position = source.localPosition;
|
|
authored.Rotation = source.localRotation;
|
|
authored.Scale = source.localScale;
|
|
|
|
eye.transform.localPosition = source.localPosition;
|
|
eye.transform.localRotation = source.localRotation;
|
|
eye.transform.localScale = source.localScale;
|
|
|
|
// Allowlist, not a blocklist - the same rule the skeleton's own glow and the head
|
|
// flame are cloned under. Whatever rode along goes, whatever type it turns out to
|
|
// be; EyeBase is added back afterwards because it is ours.
|
|
foreach (Component comp in eye.GetComponentsInChildren<Component>(true))
|
|
{
|
|
if (comp is Transform || comp is MeshRenderer || comp is MeshFilter ||
|
|
comp is ParticleSystem || comp is ParticleSystemRenderer || comp is EyeBase)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
Object.Destroy(comp);
|
|
}
|
|
|
|
foreach (Renderer renderer in eye.GetComponentsInChildren<Renderer>(true))
|
|
{
|
|
renderer.enabled = true;
|
|
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
|
renderer.receiveShadows = false;
|
|
|
|
// The escape hatch, for if the borrowed material turns out not to take a tint:
|
|
// a plain colour shader renders past 1 so the bloom pass picks it up, at the
|
|
// cost of the socket's own texture.
|
|
if (!AswidConfig.EyeFlatColorShader.Value) continue;
|
|
|
|
Shader flat = ResolveGlowShader();
|
|
if (flat != null) renderer.material = new Material(flat);
|
|
}
|
|
|
|
eye.SetActive(true);
|
|
}
|
|
|
|
LogMaterialsOnce(modelName, holder.transform);
|
|
|
|
// What the pair was actually anchored to. If the height is ever wrong again, this line
|
|
// is the answer rather than the start of another guess: it names the bone, its parent,
|
|
// and the axes the offsets are measured along.
|
|
Jotunn.Logger.LogInfo(
|
|
$"[Aswid] Eyes built on bone '{headBone.name}' (parent '{(headBone.parent != null ? headBone.parent.name : "-")}') " +
|
|
$"at world y={headBone.position.y:F2}, lossyScale={headBone.lossyScale.x:F1}, " +
|
|
$"localUp={frame.LocalUp}, localForward={frame.LocalForward}.");
|
|
|
|
return holder.transform;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Destroys every eye holder on this player that is not parented to the bone we are about
|
|
/// to build on. Runs only when a pair is being built, which is on a race change or a config
|
|
/// change - never on a hot path.
|
|
/// </summary>
|
|
private static void SweepStrayHolders(Player player, Transform keepParent)
|
|
{
|
|
if (player == null) return;
|
|
|
|
foreach (Transform t in player.GetComponentsInChildren<Transform>(true))
|
|
{
|
|
if (t == null || t.name != EyesName) continue;
|
|
if (t.parent == keepParent) continue;
|
|
|
|
Jotunn.Logger.LogInfo(
|
|
$"[Aswid] Removing a stray eye holder parented to '{(t.parent != null ? t.parent.name : "-")}'.");
|
|
|
|
// Renamed first: Destroy is deferred to the end of the frame, and this sweep would
|
|
// otherwise find it again on the next build.
|
|
t.name = EyesName + "_Removed";
|
|
Object.Destroy(t.gameObject);
|
|
}
|
|
}
|
|
|
|
private static readonly HashSet<string> warnedSources = new HashSet<string>();
|
|
private static readonly HashSet<string> loggedMaterials = new HashSet<string>();
|
|
|
|
/// <summary>
|
|
/// The creature's own eye objects, by name. Not cached: this runs when the pair is built,
|
|
/// which is on a race change or a config change and not on any hot path.
|
|
/// </summary>
|
|
private static List<Transform> FindSourceEyes(string modelName)
|
|
{
|
|
List<Transform> found = new List<Transform>();
|
|
|
|
GameObject prefab = PrefabManager.Cache.GetPrefab<GameObject>(modelName);
|
|
if (prefab == null)
|
|
{
|
|
if (warnedSources.Add(modelName))
|
|
{
|
|
Jotunn.Logger.LogWarning(
|
|
$"[Aswid] Eye source prefab '{modelName}' not found - the eyes stay dark. " +
|
|
"Check the model name in Configuration Manager.");
|
|
}
|
|
return found;
|
|
}
|
|
|
|
foreach (Transform t in prefab.GetComponentsInChildren<Transform>(true))
|
|
{
|
|
string lower = t.name.ToLower();
|
|
foreach (string wanted in SourceEyeNames)
|
|
{
|
|
if (lower == wanted) { found.Add(t); break; }
|
|
}
|
|
}
|
|
|
|
if (found.Count == 0 && warnedSources.Add(modelName + ":eyes"))
|
|
{
|
|
Jotunn.Logger.LogWarning(
|
|
$"[Aswid] '{modelName}' carries no {string.Join("/", SourceEyeNames)} objects - the eyes stay dark.");
|
|
}
|
|
|
|
return found;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Says what the borrowed material actually is, once per source. If red does not take,
|
|
/// this line is the answer: it names the shader and every colour property it exposes.
|
|
/// </summary>
|
|
private static void LogMaterialsOnce(string modelName, Transform holder)
|
|
{
|
|
if (!loggedMaterials.Add(modelName)) return;
|
|
|
|
foreach (Renderer renderer in holder.GetComponentsInChildren<Renderer>(true))
|
|
{
|
|
Material material = renderer.sharedMaterial;
|
|
if (material == null) continue;
|
|
|
|
List<string> properties = new List<string>();
|
|
foreach (string name in new[] { "_Color", "_TintColor", "_BaseColor", "_EmissionColor" })
|
|
{
|
|
if (material.HasProperty(name)) properties.Add(name);
|
|
}
|
|
|
|
Jotunn.Logger.LogInfo(
|
|
$"[Aswid] Eye '{renderer.name}' from '{modelName}': material '{material.name}' " +
|
|
$"shader '{(material.shader != null ? material.shader.name : "none")}' " +
|
|
$"colour properties: {(properties.Count > 0 ? string.Join(", ", properties.ToArray()) : "none")}");
|
|
}
|
|
}
|
|
|
|
private static Shader cachedGlowShader;
|
|
private static bool glowShaderResolved;
|
|
|
|
/// <summary>
|
|
/// Finds a shader that will render a flat colour past 1 so the bloom pass picks it up.
|
|
/// Opaque first, deliberately - see DvergarVisuals.ResolveGlowShader: a transparent shader
|
|
/// with depth writing off draws over the head from angles that should hide it.
|
|
/// </summary>
|
|
private static Shader ResolveGlowShader()
|
|
{
|
|
if (glowShaderResolved) return cachedGlowShader;
|
|
glowShaderResolved = true;
|
|
|
|
string[] candidates = { "Unlit/Color", "Standard", "Particles/Standard Unlit", "Sprites/Default", "UI/Default" };
|
|
foreach (string name in candidates)
|
|
{
|
|
Shader shader = Shader.Find(name);
|
|
if (shader == null) continue;
|
|
|
|
Jotunn.Logger.LogInfo($"[Aswid] Eye glow shader resolved to '{name}'.");
|
|
cachedGlowShader = shader;
|
|
return cachedGlowShader;
|
|
}
|
|
|
|
Jotunn.Logger.LogWarning(
|
|
"[Aswid] No glow shader resolved (" + string.Join(", ", candidates) + "); eyes stay unlit.");
|
|
return null;
|
|
}
|
|
}
|
|
}
|