public static void EnsureExistsInScene() { if (!TickEngineSettings.Single.enableTickEngine) { return; } /// Some basic singleton enforcement GameObject go = null; if (single) { go = single.gameObject; } else { /// Use NetMasterLate go if that singleton exists (this will be rare or never, but just here to cover all cases) if (NetMasterLate.single) { go = NetMasterLate.single.gameObject; } single = FindObjectOfType <NetMaster>(); if (single) { go = single.gameObject; } else { // No singletons exist... make a new GO if (!go) { go = new GameObject("Net Master"); } single = go.AddComponent <NetMaster>(); } } // Enforce singleton for NetMasterLate if (!NetMasterLate.single) { NetMasterLate.single = FindObjectOfType <NetMasterLate>(); if (!NetMasterLate.single) { NetMasterLate.single = go.AddComponent <NetMasterLate>(); } } NetMsgCallbacks.RegisterCallback(ReceiveMessage); }
private void Awake() { if (single && single != this) { /// If a singleton already exists, destroy the old one - TODO: Not sure about this behaviour yet. Allows for settings changes with scene changes. Destroy(single); } single = this; DontDestroyOnLoad(this); _prevFrameId = TickEngineSettings.frameCount - 1; _prevSubFrameId = TickEngineSettings.sendEveryXTick - 1; }