public void AddPart(int displayIndex, int anchorIndex) { if (selectedAttachPoint == null) { return; } if (page * partDisplays.Count + displayIndex > partsList.Count) { return; } GameObject obj = GameObject.Instantiate(partsList[page * partDisplays.Count + displayIndex], selectedAttachPoint.transform); DronePart part = obj.GetComponent <DronePart>(); Transform anchor = part.GetAnchorPoint(anchorIndex); obj.transform.localEulerAngles = (Vector3.up * 180) - anchor.localEulerAngles; obj.transform.localPosition = -(anchor.localRotation * anchor.localPosition); obj.transform.SetParent(selectedAttachPoint.transform.parent, true); part.AttachToAnchor(anchorIndex); part.SetParentAttachPoint(selectedAttachPoint); selectedAttachPoint.SetSelected(false); selectedAttachPoint.gameObject.SetActive(false); selectedAttachPoint = null; SerializableDictionary <RESOURCE, float> costsIncurred = part.GetResourceCost(); if (costsIncurred.ContainsKey(RESOURCE.IRON)) { currentResourceCost.Iron += costsIncurred[RESOURCE.IRON]; } if (costsIncurred.ContainsKey(RESOURCE.COPPER)) { currentResourceCost.Copper += costsIncurred[RESOURCE.COPPER]; } if (costsIncurred.ContainsKey(RESOURCE.URANIUM)) { currentResourceCost.Uranium += costsIncurred[RESOURCE.URANIUM]; } SerializableDictionary <DroneStatFields, float> statsAdded = part.GetStatFields(); if (statsAdded.ContainsKey(DroneStatFields.HEALTH)) { currentDroneStats.Health += statsAdded[DroneStatFields.HEALTH]; } if (statsAdded.ContainsKey(DroneStatFields.POWER)) { currentDroneStats.Power += statsAdded[DroneStatFields.POWER]; } if (statsAdded.ContainsKey(DroneStatFields.FUEL)) { currentDroneStats.Fuel += statsAdded[DroneStatFields.FUEL]; } if (statsAdded.ContainsKey(DroneStatFields.STORAGE)) { currentDroneStats.Storage += statsAdded[DroneStatFields.STORAGE]; } UpdateCostDisplay(); UpdateAttachDistLimit(); }
public void PartRemoved(DronePart part) { DronePart[] removedParts = part.GetComponentsInChildren <DronePart>(); foreach (DronePart removedPart in removedParts) { SerializableDictionary <RESOURCE, float> costsIncurred = part.GetResourceCost(); if (costsIncurred.ContainsKey(RESOURCE.IRON)) { currentResourceCost.Iron -= costsIncurred[RESOURCE.IRON]; } if (costsIncurred.ContainsKey(RESOURCE.COPPER)) { currentResourceCost.Copper -= costsIncurred[RESOURCE.COPPER]; } if (costsIncurred.ContainsKey(RESOURCE.URANIUM)) { currentResourceCost.Uranium -= costsIncurred[RESOURCE.URANIUM]; } SerializableDictionary <DroneStatFields, float> statsRemoved = removedPart.GetStatFields(); if (statsRemoved.ContainsKey(DroneStatFields.HEALTH)) { currentDroneStats.Health -= statsRemoved[DroneStatFields.HEALTH]; } if (statsRemoved.ContainsKey(DroneStatFields.POWER)) { currentDroneStats.Power -= statsRemoved[DroneStatFields.POWER]; } if (statsRemoved.ContainsKey(DroneStatFields.FUEL)) { currentDroneStats.Fuel -= statsRemoved[DroneStatFields.FUEL]; } if (statsRemoved.ContainsKey(DroneStatFields.STORAGE)) { currentDroneStats.Storage -= statsRemoved[DroneStatFields.STORAGE]; } } /*SerializableDictionary<RESOURCE, float> costIncurred = part.GetResourceCost(); * if (costIncurred.ContainsKey(RESOURCE.IRON)) * currentResourceCost.Iron -= costIncurred[RESOURCE.IRON]; * if (costIncurred.ContainsKey(RESOURCE.COPPER)) * currentResourceCost.Copper -= costIncurred[RESOURCE.COPPER]; * if (costIncurred.ContainsKey(RESOURCE.URANIUM)) * currentResourceCost.Uranium -= costIncurred[RESOURCE.URANIUM]; * * SerializableDictionary<DroneStatFields, float> statRemoved = part.GetStatFields(); * if (statRemoved.ContainsKey(DroneStatFields.HEALTH)) * currentDroneStats.Health -= statRemoved[DroneStatFields.HEALTH]; * if (statRemoved.ContainsKey(DroneStatFields.POWER)) * currentDroneStats.Power -= statRemoved[DroneStatFields.POWER]; * if (statRemoved.ContainsKey(DroneStatFields.FUEL)) * currentDroneStats.Fuel -= statRemoved[DroneStatFields.FUEL]; * if (statRemoved.ContainsKey(DroneStatFields.STORAGE)) * currentDroneStats.Storage -= statRemoved[DroneStatFields.STORAGE];*/ UpdateCostDisplay(); }