|
Post by gromiczek on Jan 31, 2022 17:24:36 GMT
Hi - I've been debugging a program and have a static manager class that I want to house the `SimpleSQLManager dbManager`, but this would require the SimpleSQLManager field to be static, and so far with all of my tests and sanity checks I've not been able to get that working. Can the SimpleSQLManager be a static field - or not? Thanks for your help - and for such a well-supported tool.
`static SimpleSQLManager dbManager;`
|
|
|
Post by echo17 on Feb 1, 2022 12:25:12 GMT
The SimpleSQLManager class is inherited from Monobehaviour. So to reference them from a script, your manager will also need to inherit Monobehaviour. The simplest way to do this is to make your manager a singleton derived from Monobehaviour. Something like: using System.Collections; using System.Collections.Generic; using UnityEngine; using SimpleSQL;
public class SingletonManager : MonoBehaviour { public SimpleSQLManager dbManager;
public static SingletonManager instance;
private void Awake() { if (instance == null) { instance = this; } } }
Then, to reference any object on the singleton manager, you can refer to its instance. Something like: using System.Collections; using System.Collections.Generic; using SimpleSQL.Demos; using UnityEngine;
public class test : MonoBehaviour { void Start() { var list = SingletonManager.instance.dbManager.Query<Weapon>("SELECT * FROM Weapon"); foreach (Weapon weapon in list) { Debug.Log(weapon.WeaponName); } } }
Google query for more information: link
|
|
|
Post by gromiczek on Feb 1, 2022 13:59:27 GMT
Great - thank you! - And thanks again for all the maintenance and support!
|
|