public void LoadDeviceCollection() { RegisteredDevices.Clear(); // just for safety but it's not even neccesary, because LoadDeviceCollection() gets only called when the app starts or when the registeredDevice array is already empty DeviceCollectionData deviceCollectionData = SaveAndLoadSystem.LoadDeviceCollection(); if (deviceCollectionData != null) { if (deviceCollectionData.DeviceDataList != null) { for (int i = 0; i < deviceCollectionData.DeviceDataList.Length; i++) { DeviceData deviceData = (DeviceData)deviceCollectionData.DeviceDataList[i]; IDevice device = null; Debug.Log("device type name: " + deviceData.GetType().Name); switch (deviceData.GetType().Name) { case "LampData": device = new Lamp(deviceData.DeviceName, deviceData.Id, deviceData.Name); break; default: Debug.LogError("Unknown Device Data Type"); break; } if (device != null) { device.LoadDevice(deviceData); RegisteredDevices.Add(device); } } } AllDevicesOff = deviceCollectionData.AllDevicesOff; } }