Minor refactor and update for SPT 3.9.0

This commit is contained in:
Nympfonic 2024-04-07 22:34:16 +01:00
parent 4839e050f8
commit 2018f52e91
3 changed files with 10 additions and 13 deletions

View File

@ -13,7 +13,7 @@ namespace Terkoiz.Freecam
private GameObject _mainCamera; private GameObject _mainCamera;
private Freecam _freeCamScript; private Freecam _freeCamScript;
private BattleUIScreen _playerUi; private EftBattleUIScreen _playerUi;
private bool _uiHidden; private bool _uiHidden;
private GamePlayerOwner _gamePlayerOwner; private GamePlayerOwner _gamePlayerOwner;
@ -24,14 +24,17 @@ namespace Terkoiz.Freecam
[UsedImplicitly] [UsedImplicitly]
public void Start() public void Start()
{ {
// Find Main Camera // Get Main Camera
_mainCamera = GameObject.Find("FPS Camera"); _mainCamera = GetLocalPlayerFromWorld().GetComponent<PlayerCameraController>().Camera.gameObject;
if (_mainCamera == null) if (_mainCamera == null)
{ {
FreecamPlugin.Logger.LogError("Failed to locate main camera"); FreecamPlugin.Logger.LogError("Failed to locate main camera");
return; return;
} }
// Get Player UI
_playerUi = Singleton<CommonUI>.Instance.EftBattleUIScreen;
// Add Freecam script to main camera in scene // Add Freecam script to main camera in scene
_freeCamScript = _mainCamera.AddComponent<Freecam>(); _freeCamScript = _mainCamera.AddComponent<Freecam>();
if (_freeCamScript == null) if (_freeCamScript == null)
@ -124,16 +127,10 @@ namespace Terkoiz.Freecam
if (GetLocalPlayerFromWorld() == null) if (GetLocalPlayerFromWorld() == null)
return; return;
// If we don't have the UI Component cached, go look for it in the scene
if (_playerUi == null) if (_playerUi == null)
{ {
_playerUi = GameObject.Find("BattleUIScreen").GetComponent<BattleUIScreen>(); FreecamPlugin.Logger.LogError("Failed to locate player UI");
return;
if (_playerUi == null)
{
FreecamPlugin.Logger.LogError("Failed to locate player UI");
return;
}
} }
_playerUi.gameObject.SetActive(_uiHidden); _playerUi.gameObject.SetActive(_uiHidden);

View File

@ -7,7 +7,7 @@ using KeyboardShortcut = BepInEx.Configuration.KeyboardShortcut;
namespace Terkoiz.Freecam namespace Terkoiz.Freecam
{ {
[BepInPlugin("com.terkoiz.freecam", "Terkoiz.Freecam", "1.4.2")] [BepInPlugin("com.terkoiz.freecam", "Terkoiz.Freecam", "1.4.3")]
public class FreecamPlugin : BaseUnityPlugin public class FreecamPlugin : BaseUnityPlugin
{ {
internal new static ManualLogSource Logger { get; private set; } internal new static ManualLogSource Logger { get; private set; }

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net472</TargetFramework> <TargetFramework>net471</TargetFramework>
<Version>1.4.2</Version> <Version>1.4.2</Version>
<Authors>Terkoiz, Kobrakon, CWX</Authors> <Authors>Terkoiz, Kobrakon, CWX</Authors>
<RepositoryUrl>https://dev.sp-tarkov.com/Terkoiz/Freecam</RepositoryUrl> <RepositoryUrl>https://dev.sp-tarkov.com/Terkoiz/Freecam</RepositoryUrl>