public void addEquipedDevice(Device device) { Logger.Log("addEquipedDevice(" + device.ToString() + ")", Logger.Level.TRACE); if (device == null) { Logger.Log("DevicesDisplayer::addEquipedDevice device == null", Logger.Level.WARN); } bool newEquiped = (!_equipedDevices.Exists(equiped => equiped._device == device)); if (newEquiped) { Vector3 localPosition = getNewPosition(DeviceType.Equiped); UnityEngine.Transform parent = equipPanel.transform; DisplayedDevice newDevice = EquipedDisplayedDevice.Create( parent, localPosition, null, device, this, DevicesDisplayer.DeviceType.Equiped ); _equipedDevices.Add(newDevice); graphMoleculeList.addDeviceAndMoleculesComponent(newDevice); } else { Logger.Log("addDevice failed: alreadyEquiped=" + newEquiped, Logger.Level.TRACE); } }
public void addDeviceAndMoleculesComponent(DisplayedDevice equipedDeviceScript) { if (equipedDeviceScript == null) { Logger.Log("GraphMoleculeList::addDeviceAndMoleculesComponent device == null", Logger.Level.WARN); } else { //equipedDevice is "EquipedDevicePrefabPos" object GameObject equipedDevice = equipedDeviceScript.gameObject; bool newEquiped = (!_equipedDevices.Exists(equiped => equiped.device == equipedDeviceScript._device)); if (newEquiped) { //EquipedDisplayedDeviceWithMolecules GameObject prefab = Resources.Load(DisplayedDevice.equipedWithMoleculesPrefabURI) as GameObject; //deviceWithMoleculesComponent is "EquipedDisplayedDeviceWithMoleculesButtonPrefab" object //it needs an EquipmentDevice instance - it has only an EquipmentDeviceDummy object GameObject deviceWithMoleculesComponent = Instantiate(prefab, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.identity) as GameObject; deviceWithMoleculesComponent.transform.parent = transform; deviceWithMoleculesComponent.transform.localScale = new Vector3(1f, 1f, 0); EquipedDisplayedDeviceWithMolecules eddwm = deviceWithMoleculesComponent.GetComponent <EquipedDisplayedDeviceWithMolecules>(); //equipmentDevice GameObject equipmentDevicePrefab = Resources.Load(DisplayedDevice.equipmentPrefabURI) as GameObject; GameObject equipmentDeviceComponent = Instantiate(equipmentDevicePrefab, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.identity) as GameObject; eddwm.equipmentDevice = equipmentDeviceComponent; EquipmentDevice equipmentD = equipmentDeviceComponent.GetComponent <EquipmentDevice>() as EquipmentDevice; eddwm.equipmentDeviceScript = equipmentD; //equipedDevice GameObject equipedDeviceComponent = Instantiate(equipedDevice) as GameObject; eddwm.equipedDevice = equipedDeviceComponent; EquipedDisplayedDevice edd = equipedDeviceComponent.GetComponent <EquipedDisplayedDevice>() as EquipedDisplayedDevice; eddwm.equipedDeviceScript = edd; eddwm.device = equipedDeviceScript._device; edd._device = equipedDeviceScript._device; eddwm.initialize(equipmentDeviceDummy, equipedDeviceDummy); _equipedDevices.Add(eddwm); //search if there's already in the cell a molecule that this device produces foreach (DisplayedMolecule molecule in _displayedMolecules) { if (molecule.getCodeName() == eddwm.device.getFirstGeneProteinName()) { displayMoleculeInDevice(molecule, eddwm); } } //depends on displayed list of molecules //Vector3 localPosition = getNewPosition(previousEquipedDevicesCount); //deviceWithMoleculesComponent.transform.localPosition = localPosition; positionDeviceAndMoleculeComponents(); } else { Logger.Log("addDevice failed: newEquiped=" + newEquiped, Logger.Level.TRACE); } } }