From 370b682c04bf969e69c601a2ec4b56be10d1036e Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 30 Nov 2021 19:17:26 +0000 Subject: [PATCH] add new rendertexture --- .../Patches/SatelliteProjectorPatches.cs | 8 +++++ .../SatelliteProjectorManager.cs | 32 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/QSB/SatelliteSync/Patches/SatelliteProjectorPatches.cs b/QSB/SatelliteSync/Patches/SatelliteProjectorPatches.cs index 68bd873e..d8548903 100644 --- a/QSB/SatelliteSync/Patches/SatelliteProjectorPatches.cs +++ b/QSB/SatelliteSync/Patches/SatelliteProjectorPatches.cs @@ -10,6 +10,14 @@ namespace QSB.SatelliteSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + [HarmonyPostfix] + [HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.Awake))] + public static void CreateNewRenderTexture(SatelliteSnapshotController __instance) + { + __instance._snapshotTexture = SatelliteProjectorManager.Instance.SatelliteCameraSnapshot; + __instance._satelliteCamera.targetTexture = __instance._snapshotTexture; + } + [HarmonyPrefix] [HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.OnPressInteract))] public static bool UseProjector() diff --git a/QSB/SatelliteSync/SatelliteProjectorManager.cs b/QSB/SatelliteSync/SatelliteProjectorManager.cs index 1cc126d9..48ca392b 100644 --- a/QSB/SatelliteSync/SatelliteProjectorManager.cs +++ b/QSB/SatelliteSync/SatelliteProjectorManager.cs @@ -9,15 +9,44 @@ namespace QSB.SatelliteSync public static SatelliteProjectorManager Instance { get; private set; } public SatelliteSnapshotController Projector { get; private set; } + public RenderTexture SatelliteCameraSnapshot + { + get + { + if (_satelliteCameraSnapshot == null) + { + _satelliteCameraSnapshot = new RenderTexture(512, 512, 16) + { + name = "SatelliteCameraSnapshot", + hideFlags = HideFlags.HideAndDontSave + }; + _satelliteCameraSnapshot.Create(); + } + + return _satelliteCameraSnapshot; + } + } + + private static RenderTexture _satelliteCameraSnapshot; public void Start() { Instance = this; QSBSceneManager.OnUniverseSceneLoaded += OnSceneLoaded; + QSBNetworkManager.Instance.OnClientConnected += OnConnected; } public void OnDestroy() => QSBSceneManager.OnUniverseSceneLoaded -= OnSceneLoaded; + public void OnConnected() + { + if (QSBSceneManager.CurrentScene == OWScene.SolarSystem) + { + Projector._snapshotTexture = SatelliteCameraSnapshot; + Projector._satelliteCamera.targetTexture = Projector._snapshotTexture; + } + } + private void OnSceneLoaded(OWScene oldScene, OWScene newScene) { if (newScene == OWScene.SolarSystem) @@ -25,6 +54,9 @@ namespace QSB.SatelliteSync Projector = QSBWorldSync.GetUnityObjects().First(); Projector._loopingSource.spatialBlend = 1f; Projector._oneShotSource.spatialBlend = 1f; + + Projector._snapshotTexture = SatelliteCameraSnapshot; + Projector._satelliteCamera.targetTexture = Projector._snapshotTexture; } }