Example mod Show Bolt Size; docs for publishing mods
Shows the size of the bolt closest to the crosshair (Screw FSM "BoltSize"). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using HutongGames.PlayMaker;
|
||||
using MSCO;
|
||||
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.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.0")]
|
||||
|
||||
namespace ShowBoltSize
|
||||
{
|
||||
/// <summary>
|
||||
/// Zeigt unter dem Fadenkreuz die Größe der Schraube, auf die man schaut ("10 mm"). Jede Schraube hat die FSM "Screw"
|
||||
/// mit der Variable "BoltSize". Deren Kollider sind nur mit Werkzeug in der Hand aktiv - deshalb kein Raycast, sondern:
|
||||
/// die Schraube, die am nächsten an der Blickrichtung liegt (bis 1,3 m). Nur Anzeige, ändert nichts am Spiel.
|
||||
/// </summary>
|
||||
public class ShowBoltSize : MscoMod
|
||||
{
|
||||
public override string ID { get { return "showboltsize"; } }
|
||||
public override string Name { get { return "Show Bolt Size"; } }
|
||||
public override string Version { get { return "1.0.0"; } }
|
||||
public override string Author { get { return "MBM"; } }
|
||||
|
||||
const float MaxDistance = 1.3f;
|
||||
const float BoltRadius = 0.025f; // so groß wirkt eine Schraube beim Zielen
|
||||
const float ScanInterval = 2f;
|
||||
|
||||
sealed class Bolt
|
||||
{
|
||||
public Transform Transform;
|
||||
public FsmFloat SizeF;
|
||||
public FsmInt SizeI;
|
||||
}
|
||||
|
||||
readonly List<Bolt> bolts = new List<Bolt>();
|
||||
bool inGame;
|
||||
float nextScan;
|
||||
string label;
|
||||
GUIStyle style;
|
||||
|
||||
public override void OnMenuLoad() { inGame = false; bolts.Clear(); label = null; }
|
||||
public override void OnGameLoad() { inGame = true; nextScan = 0f; }
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
label = null;
|
||||
if (!inGame) return;
|
||||
Camera cam = Camera.main;
|
||||
if (cam == null) return;
|
||||
if (Time.realtimeSinceStartup >= nextScan) Scan();
|
||||
|
||||
Transform eye = cam.transform;
|
||||
Bolt best = null;
|
||||
float bestAngle = float.MaxValue;
|
||||
foreach (Bolt b in bolts)
|
||||
{
|
||||
if (b.Transform == null || !b.Transform.gameObject.activeInHierarchy) continue;
|
||||
Vector3 to = b.Transform.position - eye.position;
|
||||
float distance = to.magnitude;
|
||||
if (distance > MaxDistance || distance < 0.05f) continue;
|
||||
float angle = Vector3.Angle(eye.forward, to);
|
||||
float limit = Mathf.Atan2(BoltRadius, distance) * Mathf.Rad2Deg + 0.5f;
|
||||
if (angle < limit && angle < bestAngle)
|
||||
{
|
||||
bestAngle = angle;
|
||||
best = b;
|
||||
}
|
||||
}
|
||||
if (best != null) label = Describe(best);
|
||||
}
|
||||
|
||||
void Scan()
|
||||
{
|
||||
nextScan = Time.realtimeSinceStartup + ScanInterval;
|
||||
bolts.Clear();
|
||||
foreach (PlayMakerFSM fsm in Object.FindObjectsOfType<PlayMakerFSM>())
|
||||
{
|
||||
if (fsm == null || fsm.FsmName != "Screw") continue;
|
||||
FsmFloat f = fsm.FsmVariables.FindFsmFloat("BoltSize");
|
||||
FsmInt i = fsm.FsmVariables.FindFsmInt("BoltSize");
|
||||
if (f == null && i == null) continue;
|
||||
bolts.Add(new Bolt { Transform = fsm.transform, SizeF = f, SizeI = i });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Größe in mm. Das Spiel speichert sie je nach Schraube als 10 oder als 1.0 (= 10 mm).</summary>
|
||||
static string Describe(Bolt b)
|
||||
{
|
||||
float value = b.SizeF != null ? b.SizeF.Value : b.SizeI.Value;
|
||||
if (value <= 0f) return null;
|
||||
float mm = value < 2.5f ? value * 10f : value;
|
||||
return Mathf.RoundToInt(mm) + " mm";
|
||||
}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
if (label == null) return;
|
||||
if (style == null)
|
||||
{
|
||||
style = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontSize = 16, fontStyle = FontStyle.Bold };
|
||||
style.normal.textColor = Color.white;
|
||||
}
|
||||
var r = new Rect(Screen.width / 2f - 50f, Screen.height / 2f + 22f, 100f, 26f);
|
||||
Color old = GUI.color;
|
||||
GUI.color = new Color(0f, 0f, 0f, 0.6f);
|
||||
GUI.DrawTexture(r, Texture2D.whiteTexture);
|
||||
GUI.color = old;
|
||||
GUI.Label(r, label, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
MSCO-Mod "Show Bolt Size". Bauen: msbuild ShowBoltSize.csproj -p:Configuration=Release
|
||||
Ergebnis bin\Release\ShowBoltSize.dll - im Launcher unter Mods hochladen oder nach <Spielordner>\MSCO\Mods kopieren.
|
||||
GamePath anpassen, wenn My Summer Car woanders liegt.
|
||||
-->
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>ShowBoltSize</RootNamespace>
|
||||
<AssemblyName>ShowBoltSize</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Unity Full v3.5</TargetFrameworkProfile>
|
||||
<LangVersion>13</LangVersion>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<GamePath Condition=" '$(GamePath)' == '' ">F:\SteamLibrary\steamapps\common\My Summer Car</GamePath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="UnityEngine">
|
||||
<HintPath>$(GamePath)\mysummercar_Data\Managed\UnityEngine.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="PlayMaker">
|
||||
<HintPath>$(GamePath)\mysummercar_Data\Managed\PlayMaker.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="MSCO">
|
||||
<HintPath>$(GamePath)\MSCO\MSCO.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ShowBoltSize.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user