optimise instance access
This commit is contained in:
@@ -13,18 +13,7 @@ namespace EscapeRoomEngine.Engine.Runtime
|
|||||||
public class Engine : MonoBehaviour
|
public class Engine : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static EngineTheme Theme => Instance.theme;
|
public static EngineTheme Theme => Instance.theme;
|
||||||
public static Engine Instance
|
public static Engine Instance { get; private set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_foundEngine == null)
|
|
||||||
{
|
|
||||||
_foundEngine = FindObjectOfType<Engine>();
|
|
||||||
}
|
|
||||||
return _foundEngine;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static Engine _foundEngine;
|
|
||||||
|
|
||||||
public delegate void UpdateUIHandler();
|
public delegate void UpdateUIHandler();
|
||||||
public event UpdateUIHandler UpdateUIEvent;
|
public event UpdateUIHandler UpdateUIEvent;
|
||||||
@@ -45,6 +34,8 @@ namespace EscapeRoomEngine.Engine.Runtime
|
|||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
Instance = this;
|
||||||
|
|
||||||
Measure.Clear();
|
Measure.Clear();
|
||||||
|
|
||||||
_puzzles = new List<PuzzleModuleDescription>(theme.puzzleTypes);
|
_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);
|
_playSpaceOrigin.transform.localPosition = new Vector3(-theme.playSpace.x / 2f, 0, -theme.playSpace.y / 2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Generation
|
||||||
|
|
||||||
public void GenerateRoom()
|
public void GenerateRoom()
|
||||||
{
|
{
|
||||||
Logger.Log("Generating room...", LogType.RoomGeneration);
|
Logger.Log("Generating room...", LogType.RoomGeneration);
|
||||||
@@ -123,6 +116,8 @@ namespace EscapeRoomEngine.Engine.Runtime
|
|||||||
room.AddSpace(space, exit);
|
room.AddSpace(space, exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public void HidePreviousRoom(bool destroy = true)
|
public void HidePreviousRoom(bool destroy = true)
|
||||||
{
|
{
|
||||||
if (NumberOfRooms > 2)
|
if (NumberOfRooms > 2)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
using System;
|
||||||
|
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||||
using Realms;
|
using Realms;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||||
@@ -8,18 +9,7 @@ namespace EscapeRoomEngine.Engine.Runtime.Measurements
|
|||||||
{
|
{
|
||||||
public class PuzzleStorage : MonoBehaviour
|
public class PuzzleStorage : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static PuzzleStorage Instance
|
public static PuzzleStorage Instance { get; private set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_foundStorage == null)
|
|
||||||
{
|
|
||||||
_foundStorage = FindObjectOfType<PuzzleStorage>();
|
|
||||||
}
|
|
||||||
return _foundStorage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static PuzzleStorage _foundStorage;
|
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private string databasePath = "measurements.realm";
|
private string databasePath = "measurements.realm";
|
||||||
@@ -31,6 +21,11 @@ namespace EscapeRoomEngine.Engine.Runtime.Measurements
|
|||||||
_realm = Realm.GetInstance(databasePath);
|
_realm = Realm.GetInstance(databasePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
Logger.Log($"Using realm database at {_realm.Config.DatabasePath}", LogType.Measuring);
|
Logger.Log($"Using realm database at {_realm.Config.DatabasePath}", LogType.Measuring);
|
||||||
|
|||||||
@@ -14,18 +14,7 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
|
|||||||
|
|
||||||
public class GameControl : MonoBehaviour
|
public class GameControl : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static GameControl Instance
|
public static GameControl Instance { get; private set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_foundGameControl == null)
|
|
||||||
{
|
|
||||||
_foundGameControl = FindObjectOfType<GameControl>();
|
|
||||||
}
|
|
||||||
return _foundGameControl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static GameControl _foundGameControl;
|
|
||||||
|
|
||||||
[BoxGroup("Internal")] [SerializeField]
|
[BoxGroup("Internal")] [SerializeField]
|
||||||
private Button startButton, stopButton, pauseButton, addTimeButton, removeTimeButton;
|
private Button startButton, stopButton, pauseButton, addTimeButton, removeTimeButton;
|
||||||
@@ -41,6 +30,8 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
|
|||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
Instance = this;
|
||||||
|
|
||||||
_targetTime = Engine.Instance.initialTargetTime;
|
_targetTime = Engine.Instance.initialTargetTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user