Show Bolt Size 1.0.3: size from the game's own wrench check (FPSCamera/2Spanner/Raycast 'Check' BoltSize) - the bolts' own BoltSize is 0; one-time dump of the tool FSMs for diagnosis
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,9 +7,9 @@ using UnityEngine;
|
||||
[assembly: AssemblyTitle("Show Bolt Size")]
|
||||
[assembly: AssemblyProduct("Show Bolt Size")]
|
||||
[assembly: AssemblyDescription("Shows the size of the bolt you look at, so you pick the right wrench.")]
|
||||
[assembly: AssemblyVersion("1.0.2.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.2.0")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.2")]
|
||||
[assembly: AssemblyVersion("1.0.3.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.3.0")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.3")]
|
||||
|
||||
namespace ShowBoltSize
|
||||
{
|
||||
@@ -22,7 +22,7 @@ namespace ShowBoltSize
|
||||
{
|
||||
public override string ID { get { return "showboltsize"; } }
|
||||
public override string Name { get { return "Show Bolt Size"; } }
|
||||
public override string Version { get { return "1.0.2"; } }
|
||||
public override string Version { get { return "1.0.3"; } }
|
||||
public override string Author { get { return "MBM"; } }
|
||||
|
||||
const float MaxDistance = 1.5f;
|
||||
@@ -48,7 +48,17 @@ namespace ShowBoltSize
|
||||
float nextDiagnostic;
|
||||
bool shownOnce;
|
||||
|
||||
public override void OnMenuLoad() { inGame = false; bolts.Clear(); label = null; camera = null; reported = false; }
|
||||
// Das Spiel selbst: Schraubenschlüssel/Ratsche in der Hand -> FPSCamera/2Spanner/Raycast, FSM "Check" mit "BoltSize"
|
||||
// (die Größe der Schraube, auf die das Werkzeug gerade zielt). Die Variable "BoltSize" der Schrauben ist oft 0.
|
||||
PlayMakerFSM toolCheck;
|
||||
FsmFloat toolSize;
|
||||
FsmInt toolSizeI;
|
||||
float lastToolSize = -1f;
|
||||
int toolLogs;
|
||||
bool dumped;
|
||||
float dumpAt = -1f;
|
||||
|
||||
public override void OnMenuLoad() { inGame = false; bolts.Clear(); label = null; camera = null; reported = false; toolCheck = null; toolSize = null; toolSizeI = null; }
|
||||
public override void OnGameLoad() { inGame = true; nextScan = 0f; }
|
||||
|
||||
/// <summary>
|
||||
@@ -73,6 +83,7 @@ namespace ShowBoltSize
|
||||
Camera cam = FindCamera();
|
||||
if (cam == null) return;
|
||||
if (Time.realtimeSinceStartup >= nextScan) Scan(cam);
|
||||
float fromTool = ToolSize(cam);
|
||||
|
||||
// Die Schraube, die am nächsten an der Blicklinie liegt (Abstand zur Linie, nicht Winkel)
|
||||
Transform eye = cam.transform;
|
||||
@@ -90,7 +101,11 @@ namespace ShowBoltSize
|
||||
if (off < nearestOff) { nearestOff = off; nearest = b; }
|
||||
if (along <= MaxDistance && off < AimTolerance && off < bestOff) { bestOff = off; best = b; }
|
||||
}
|
||||
if (best != null)
|
||||
if (fromTool > 0f)
|
||||
{
|
||||
label = Format(fromTool); // was das Spiel für das Werkzeug ermittelt - immer richtig
|
||||
}
|
||||
else if (best != null)
|
||||
{
|
||||
label = Describe(best);
|
||||
if (!shownOnce) { shownOnce = true; Log("first bolt: " + Info(best, eyePos, forward) + " -> " + label); }
|
||||
@@ -103,6 +118,44 @@ namespace ShowBoltSize
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Größe aus dem Werkzeug des Spielers (nur mit Schraubenschlüssel/Ratsche in der Hand), sonst 0. Beim ersten Mal
|
||||
/// wird außerdem einmal die Werkzeug-FSM in MSCOsmdump.txt geschrieben (Fehlersuche).
|
||||
/// </summary>
|
||||
float ToolSize(Camera cam)
|
||||
{
|
||||
if (toolCheck == null)
|
||||
{
|
||||
Transform raycast = cam.transform.Find("2Spanner/Raycast");
|
||||
if (raycast == null) return 0f;
|
||||
foreach (PlayMakerFSM f in raycast.GetComponents<PlayMakerFSM>())
|
||||
if (f.FsmName == "Check") { toolCheck = f; break; }
|
||||
if (toolCheck == null) return 0f;
|
||||
toolSize = toolCheck.FsmVariables.FindFsmFloat("BoltSize");
|
||||
toolSizeI = toolCheck.FsmVariables.FindFsmInt("BoltSize");
|
||||
Log("tool found: " + toolCheck.name + "/" + toolCheck.FsmName + (toolSize != null ? " with float BoltSize" : toolSizeI != null ? " with int BoltSize" : " without BoltSize"));
|
||||
}
|
||||
if (!toolCheck.gameObject.activeInHierarchy || !toolCheck.enabled) return 0f;
|
||||
if (!dumped)
|
||||
{
|
||||
if (dumpAt < 0f) dumpAt = Time.realtimeSinceStartup + 2f; // erst laufen lassen, dann sind die Aktionen geladen
|
||||
else if (Time.realtimeSinceStartup >= dumpAt)
|
||||
{
|
||||
dumped = true;
|
||||
try { Log("tool dump: " + FsmDump.Write("2spanner#0|raycast#0")); }
|
||||
catch (System.Exception e) { Log("tool dump failed: " + e.Message); }
|
||||
}
|
||||
}
|
||||
float value = toolSize != null ? toolSize.Value : toolSizeI != null ? toolSizeI.Value : 0f;
|
||||
if (value != lastToolSize && toolLogs < 12)
|
||||
{
|
||||
lastToolSize = value;
|
||||
toolLogs++;
|
||||
Log("tool BoltSize=" + value + " (state " + toolCheck.ActiveStateName + ")");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static string Info(Bolt b, Vector3 eyePos, Vector3 forward)
|
||||
{
|
||||
Vector3 to = Center(b) - eyePos;
|
||||
@@ -140,6 +193,11 @@ namespace ShowBoltSize
|
||||
{
|
||||
float value = b.SizeF != null ? b.SizeF.Value : b.SizeI.Value;
|
||||
if (value <= 0f) return "? mm"; // Größe unbekannt - aber die Schraube wurde erkannt
|
||||
return Format(value);
|
||||
}
|
||||
|
||||
static string Format(float value)
|
||||
{
|
||||
float mm = value < 2.5f ? value * 10f : value;
|
||||
return Mathf.RoundToInt(mm) + " mm";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user