70 lines
3.4 KiB
C#
70 lines
3.4 KiB
C#
using System.Text;
|
|
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// TEMPORARY DEBUG. F8 dumps the build ghost in hand and what the placement ray hits, to the
|
|
/// console and the BepInEx log - for the Trol War Totem, whose ghost stays invisible where every
|
|
/// other station's now shows. Remove once that is fixed.
|
|
/// </summary>
|
|
public class PlacementGhostDebug : MonoBehaviour
|
|
{
|
|
private void Update()
|
|
{
|
|
if (!Input.GetKeyDown(KeyCode.F8)) return;
|
|
|
|
Player player = Player.m_localPlayer;
|
|
if (player == null) return;
|
|
|
|
var sb = new StringBuilder();
|
|
GameObject ghost = Traverse.Create(player).Field<GameObject>("m_placementGhost").Value;
|
|
sb.AppendLine($"[GhostDebug] status={Traverse.Create(player).Field("m_placementStatus").GetValue()} ghost={(ghost != null ? ghost.name : "none")}");
|
|
|
|
Camera cam = GameCamera.instance != null ? GameCamera.instance.GetComponent<Camera>() : null;
|
|
if (GameCamera.instance != null && Physics.Raycast(GameCamera.instance.transform.position, GameCamera.instance.transform.forward, out RaycastHit hit, 50f))
|
|
{
|
|
sb.AppendLine($"[GhostDebug] ray hit '{hit.collider.name}' layer={LayerMask.LayerToName(hit.collider.gameObject.layer)} " +
|
|
$"dist={hit.distance:0.0} heightmap={(hit.collider.GetComponent<Heightmap>() != null)} rigidbody={(hit.collider.attachedRigidbody != null)}");
|
|
}
|
|
|
|
if (ghost != null)
|
|
{
|
|
sb.AppendLine($"[GhostDebug] ghost active={ghost.activeInHierarchy} pos={ghost.transform.position} scale={ghost.transform.lossyScale} " +
|
|
$"layer={LayerMask.LayerToName(ghost.layer)} cameraMask has ghost layer={(cam != null && (cam.cullingMask & (1 << ghost.layer)) != 0)}");
|
|
|
|
foreach (LODGroup lod in ghost.GetComponentsInChildren<LODGroup>(true))
|
|
{
|
|
sb.AppendLine($"[GhostDebug] LODGroup on '{lod.name}' enabled={lod.enabled} active={lod.gameObject.activeInHierarchy} lods={lod.lodCount}");
|
|
}
|
|
|
|
foreach (Renderer r in ghost.GetComponentsInChildren<Renderer>(true))
|
|
{
|
|
Material m = r.sharedMaterial;
|
|
sb.AppendLine($"[GhostDebug] renderer '{PathOf(r.transform, ghost.transform)}' {r.GetType().Name} enabled={r.enabled} " +
|
|
$"forceOff={r.forceRenderingOff} active={r.gameObject.activeInHierarchy} visible={r.isVisible} " +
|
|
$"layer={LayerMask.LayerToName(r.gameObject.layer)} bounds={r.bounds.size} " +
|
|
$"shader={(m != null && m.shader != null ? m.shader.name : "none")}");
|
|
}
|
|
}
|
|
|
|
string text = sb.ToString();
|
|
Jotunn.Logger.LogInfo(text);
|
|
if (Console.instance != null)
|
|
{
|
|
foreach (string line in text.Split('\n'))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(line)) Console.instance.Print(line.TrimEnd());
|
|
}
|
|
}
|
|
}
|
|
|
|
private static string PathOf(Transform t, Transform root)
|
|
{
|
|
string path = t.name;
|
|
for (Transform p = t.parent; p != null && p != root; p = p.parent) path = p.name + "/" + path;
|
|
return path;
|
|
}
|
|
}
|
|
}
|