optimise instance access

This commit is contained in:
2022-12-14 20:22:39 +01:00
parent 22458e6d18
commit 5e2af5468c
3 changed files with 20 additions and 39 deletions

View File

@@ -13,18 +13,7 @@ namespace EscapeRoomEngine.Engine.Runtime
public class Engine : MonoBehaviour
{
public static EngineTheme Theme => Instance.theme;
public static Engine Instance
{
get
{
if (_foundEngine == null)
{
_foundEngine = FindObjectOfType<Engine>();
}
return _foundEngine;
}
}
private static Engine _foundEngine;
public static Engine Instance { get; private set; }
public delegate void UpdateUIHandler();
public event UpdateUIHandler UpdateUIEvent;
@@ -45,6 +34,8 @@ namespace EscapeRoomEngine.Engine.Runtime
private void Awake()
{
Instance = this;
Measure.Clear();
_puzzles = new List<PuzzleModuleDescription>(theme.puzzleTypes);
@@ -57,6 +48,8 @@ namespace EscapeRoomEngine.Engine.Runtime
_playSpaceOrigin.transform.localPosition = new Vector3(-theme.playSpace.x / 2f, 0, -theme.playSpace.y / 2f);
}
#region Generation
public void GenerateRoom()
{
Logger.Log("Generating room...", LogType.RoomGeneration);
@@ -123,6 +116,8 @@ namespace EscapeRoomEngine.Engine.Runtime
room.AddSpace(space, exit);
}
#endregion
public void HidePreviousRoom(bool destroy = true)
{
if (NumberOfRooms > 2)

View File

@@ -1,4 +1,5 @@
using EscapeRoomEngine.Engine.Runtime.Modules;
using System;
using EscapeRoomEngine.Engine.Runtime.Modules;
using Realms;
using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
@@ -8,19 +9,8 @@ namespace EscapeRoomEngine.Engine.Runtime.Measurements
{
public class PuzzleStorage : MonoBehaviour
{
public static PuzzleStorage Instance
{
get
{
if (_foundStorage == null)
{
_foundStorage = FindObjectOfType<PuzzleStorage>();
}
return _foundStorage;
}
}
private static PuzzleStorage _foundStorage;
public static PuzzleStorage Instance { get; private set; }
[SerializeField]
private string databasePath = "measurements.realm";
@@ -31,6 +21,11 @@ namespace EscapeRoomEngine.Engine.Runtime.Measurements
_realm = Realm.GetInstance(databasePath);
}
private void Awake()
{
Instance = this;
}
private void Start()
{
Logger.Log($"Using realm database at {_realm.Config.DatabasePath}", LogType.Measuring);

View File

@@ -14,19 +14,8 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
public class GameControl : MonoBehaviour
{
public static GameControl Instance
{
get
{
if (_foundGameControl == null)
{
_foundGameControl = FindObjectOfType<GameControl>();
}
return _foundGameControl;
}
}
private static GameControl _foundGameControl;
public static GameControl Instance { get; private set; }
[BoxGroup("Internal")] [SerializeField]
private Button startButton, stopButton, pauseButton, addTimeButton, removeTimeButton;
[BoxGroup("Internal")] [SerializeField]
@@ -41,6 +30,8 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
private void Awake()
{
Instance = this;
_targetTime = Engine.Instance.initialTargetTime;
}