private void DeserializeModules(Dictionary <string, IPowerable> powerableMap) { _DestroyCurrent <ResourcelessGameplay>(); _DestroyCurrent <SingleResourceModuleGameplay>(); _DestroyCurrent <MultipleResourceModuleGameplay>(typeof(Habitat)); Habitat[] allHabs = Transform.FindObjectsOfType <Habitat>().Where(x => x.isActiveAndEnabled).ToArray(); Dictionary <string, ModuleGameplay> moduleMap = new Dictionary <string, ModuleGameplay>(); #if UNITY_EDITOR reflectionRuns = 0; reflectionCheckTime.Reset(); reflectionPropertyTime.Reset(); #endif //we have to look at each data to figure out which prefab to use foreach (ResourcelessModuleData data in ResourcelessData) { Transform t = GameObject.Instantiate(ModuleBridge.Instance.Modules[(int)data.ModuleType], data.Position, data.Rotation) as Transform; ResourcelessGameplay r = t.GetComponent <ResourcelessGameplay>(); r.Data = data; moduleMap.Add(data.ModuleInstanceID, r); if (!String.IsNullOrEmpty(data.PowerableInstanceID)) { powerableMap.Add(data.PowerableInstanceID, r); } DeserializeFlexData(data, r); } foreach (SingleResourceModuleData data in SingleResourceContainerData) { Transform t = GameObject.Instantiate(ModuleBridge.Instance.Modules[(int)data.ModuleType], data.Position, data.Rotation) as Transform; SingleResourceModuleGameplay r = t.GetComponent <SingleResourceModuleGameplay>(); r.Data = data; moduleMap.Add(data.ModuleInstanceID, r); if (!String.IsNullOrEmpty(data.PowerableInstanceID)) { powerableMap.Add(data.PowerableInstanceID, r); } DeserializeFlexData(data, r); } foreach (MultipleResourceModuleData data in MultiResourceContainerData) { if (data.ModuleType == Buildings.Module.Habitat) { SyncToHabitat(allHabs, data, moduleMap, powerableMap); } else { Transform t = GameObject.Instantiate(ModuleBridge.Instance.Modules[(int)data.ModuleType], data.Position, data.Rotation) as Transform; MultipleResourceModuleGameplay r = t.GetComponent <MultipleResourceModuleGameplay>(); r.Data = data; moduleMap.Add(data.ModuleInstanceID, r); if (!String.IsNullOrEmpty(data.PowerableInstanceID)) { powerableMap.Add(data.PowerableInstanceID, r); } DeserializeFlexData(data, r); } } foreach (PipelineData data in PipeData) { Transform t = GameObject.Instantiate(PlayerInput.Instance.gasPipePrefab, data.Position, data.Rotation) as Transform; t.localScale = data.LocalScale; Pipe r = t.GetComponent <Pipe>(); r.Data = data; r.AssignConnections(data.MatterType, moduleMap[data.FromModuleInstanceID], moduleMap[data.ToModuleInstanceID], null, null); } foreach (PowerlineData data in PowerData) { Transform prefab = null; switch (data.Type) { default: case PowerlineType.Powerline: prefab = PlayerInput.Instance.powerlinePrefab; break; case PowerlineType.Umbilical: prefab = PlayerInput.Instance.umbilicalPrefab; break; case PowerlineType.Corridor: prefab = PlayerInput.Instance.tubePrefab; break; } Transform t = GameObject.Instantiate(prefab, data.Position, data.Rotation) as Transform; t.localScale = data.LocalScale; Powerline r = t.GetComponent <Powerline>(); r.Data = data; DeserializeFlexData(data, r); r.AssignConnections(powerableMap[data.FromPowerableInstanceID], powerableMap[data.ToPowerableInstanceID], null, null); } #if UNITY_EDITOR UnityEngine.Debug.Log(String.Format("deserialize reflection: {0} run, type checks: {1}ms, property reflection: {2}ms", reflectionRuns, reflectionCheckTime.ElapsedMilliseconds, reflectionPropertyTime.ElapsedMilliseconds)); #endif }