Merge pull request #376 from misternebula/fix-satellite-projector-rendertexture

add new rendertexture
This commit is contained in:
_nebula 2021-11-30 19:26:46 +00:00 committed by GitHub
commit 6b7ce21726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -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()

View File

@ -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<SatelliteSnapshotController>().First();
Projector._loopingSource.spatialBlend = 1f;
Projector._oneShotSource.spatialBlend = 1f;
Projector._snapshotTexture = SatelliteCameraSnapshot;
Projector._satelliteCamera.targetTexture = Projector._snapshotTexture;
}
}