protected virtual void Awake() { if (_instance != null && _instance != this) { Destroy(this.gameObject); } else { _instance = (T)this; OnInitialisation?.Invoke(); } }
/// <summary> /// Populates dictionary with references to block handlers. /// Used for accessing blocks with Get() while simulating. /// If mod is loaded, it gets called automatically at the start of simulation. /// Invokes OnInitialisation event when done. /// </summary> public static void Initialize() { IDToBlockHandler = new Dictionary <string, Block>(); GUIDToBlockHandler = new Dictionary <Guid, Block>(); BbToBlockHandler = new Dictionary <BlockBehaviour, Block>(); var typeCount = new Dictionary <string, int>(); for (var i = 0; i < ReferenceMaster.BuildingBlocks.Count; i++) { var name = ReferenceMaster.BuildingBlocks[i].GetComponent <MyBlockInfo>().blockName.ToUpper(); typeCount[name] = typeCount.ContainsKey(name) ? typeCount[name] + 1 : 1; var id = name + " " + typeCount[name]; var guid = ReferenceMaster.BuildingBlocks[i].Guid; var b = Create(ReferenceMaster.SimulationBlocks[i]); IDToBlockHandler[id] = b; GUIDToBlockHandler[guid] = b; } Initialised = true; OnInitialisation?.Invoke(); }
internal void Initialise() { OnInitialisation?.Invoke(); }