Add rear lights that turn on while reversing
This commit is contained in:
+45
-2
@@ -20,6 +20,8 @@ public class BackupCam : SonsMod
|
||||
const float SearchRadius = 2.5f;
|
||||
const string ScreenPath = "GolfCartScreen/GolfCartGps/Canvas/ScreenMask";
|
||||
const string ScreenImageName = "BackupCamScreen";
|
||||
const string HeadLightPath = "LightsGroup/HeadLights";
|
||||
const string RearLightName = "BackupCamRearLight";
|
||||
|
||||
static readonly string[] TextureProps =
|
||||
{
|
||||
@@ -35,6 +37,7 @@ public class BackupCam : SonsMod
|
||||
GameObject _canvasGo;
|
||||
RawImage _image;
|
||||
GameObject _screenGo;
|
||||
GameObject _rearLightGo;
|
||||
float _screenAspect;
|
||||
float _searchTimer;
|
||||
float _lastReverse = -10f;
|
||||
@@ -52,7 +55,7 @@ public class BackupCam : SonsMod
|
||||
|
||||
protected override void OnSdkInitialized()
|
||||
{
|
||||
RLog.Msg("BackupCam 1.1.1 loaded. Reverse the golf cart to show the camera on its GPS screen. Console: backupcamoffset, backupcamdump");
|
||||
RLog.Msg("BackupCam 1.2.0 loaded. Reverse the golf cart to show the camera on its GPS screen and turn on rear lights. Console: backupcamoffset, backupcamdump");
|
||||
}
|
||||
|
||||
protected override void OnGameStart()
|
||||
@@ -117,6 +120,7 @@ public class BackupCam : SonsMod
|
||||
_cart = null;
|
||||
_body = null;
|
||||
_screenGo = null;
|
||||
_rearLightGo = null;
|
||||
|
||||
var player = LocalPlayer.Transform;
|
||||
var root = player.root;
|
||||
@@ -143,6 +147,7 @@ public class BackupCam : SonsMod
|
||||
_body = body;
|
||||
AttachCamera();
|
||||
AttachScreen();
|
||||
AttachRearLight();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -213,6 +218,43 @@ public class BackupCam : SonsMod
|
||||
_screenAspect = maskRect.height > 0f ? maskRect.width / maskRect.height : 0f;
|
||||
}
|
||||
|
||||
void AttachRearLight()
|
||||
{
|
||||
var root = _cart.transform.root;
|
||||
var existing = root.Find(RearLightName);
|
||||
if (existing != null)
|
||||
{
|
||||
_rearLightGo = existing.gameObject;
|
||||
_rearLightGo.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var head = root.Find(HeadLightPath);
|
||||
if (head == null)
|
||||
{
|
||||
RLog.Msg("BackupCam: headlights not found on this cart, no rear lights");
|
||||
return;
|
||||
}
|
||||
|
||||
var go = Object.Instantiate(head.gameObject, root);
|
||||
go.name = RearLightName;
|
||||
go.SetActive(false);
|
||||
|
||||
foreach (var c in go.GetComponents<Component>())
|
||||
if (c != null && c.GetIl2CppType().Name == "UL_FastGI")
|
||||
Object.Destroy(c);
|
||||
|
||||
var localPos = root.InverseTransformPoint(head.position);
|
||||
var localRot = Quaternion.Inverse(root.rotation) * head.rotation;
|
||||
go.transform.localPosition = new Vector3(localPos.x, localPos.y, -localPos.z);
|
||||
go.transform.localRotation = Quaternion.AngleAxis(180f, Vector3.up) * localRot;
|
||||
|
||||
var light = go.GetComponent<Light>();
|
||||
if (light != null) light.enabled = true;
|
||||
|
||||
_rearLightGo = go;
|
||||
}
|
||||
|
||||
void ApplyOffset()
|
||||
{
|
||||
if (_cam == null) return;
|
||||
@@ -228,6 +270,7 @@ public class BackupCam : SonsMod
|
||||
var onScreen = _screenGo != null;
|
||||
if (_screenGo != null) _screenGo.SetActive(show);
|
||||
if (_canvasGo != null) _canvasGo.SetActive(show && !onScreen);
|
||||
if (_rearLightGo != null) _rearLightGo.SetActive(show);
|
||||
|
||||
if (_cam == null) return;
|
||||
if (onScreen && _screenAspect > 0f) _cam.aspect = _screenAspect;
|
||||
@@ -379,4 +422,4 @@ public class BackupCam : SonsMod
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# BackupCam
|
||||
|
||||
Shows a backup camera on screen while you reverse the golf cart in Sons of the
|
||||
Forest.
|
||||
Shows a backup camera on the golf cart's GPS screen and turns on rear lights
|
||||
while you reverse in Sons of the Forest.
|
||||
|
||||
## Multiplayer
|
||||
|
||||
@@ -53,9 +53,13 @@ Mods\BackupCam\manifest.json
|
||||
|
||||
## Usage
|
||||
|
||||
Get in a golf cart and drive backward. The camera feed appears at the bottom of
|
||||
the screen, mirrored like a real backup camera, and hides shortly after you stop
|
||||
reversing.
|
||||
Get in a golf cart and drive backward. The camera feed replaces the map on the
|
||||
cart's GPS screen, mirrored like a real backup camera, and the map comes back
|
||||
shortly after you stop reversing. Rear lights also turn on while reversing so
|
||||
the camera can see at night. If a cart has no GPS screen, the feed is shown at
|
||||
the bottom of your screen instead.
|
||||
|
||||
The rear lights and camera are only visible to players who have the mod.
|
||||
|
||||
Press F1 to open the console, then use these commands:
|
||||
|
||||
@@ -63,7 +67,7 @@ Press F1 to open the console, then use these commands:
|
||||
| --- | --- |
|
||||
| `backupcamoffset` | Show the current camera height, distance and tilt |
|
||||
| `backupcamoffset 1.1 -1.3 20` | Set camera height, distance behind the cart, and downward tilt |
|
||||
| `backupcamdump` | Write the golf cart's object and material list to `_RedLoader\Latest.log` |
|
||||
| `backupcamdump` | Write the golf cart's objects, components and textures to `UserData\BackupCamDump.txt` |
|
||||
|
||||
## Uninstall
|
||||
|
||||
|
||||
Reference in New Issue
Block a user