I am destroying any instances of GameObject.Find() to save the world #5

Merged
Terkoiz merged 3 commits from :master into master 2024-04-08 03:09:44 -04:00
3 changed files with 10 additions and 13 deletions
Showing only changes of commit 2018f52e91 - Show all commits

View File

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

View File

@ -7,7 +7,7 @@ using KeyboardShortcut = BepInEx.Configuration.KeyboardShortcut;
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
{
internal new static ManualLogSource Logger { get; private set; }

View File

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