private void WindowFunction(int id) { int row = 0; Rect viewRect = new Rect(0, 0, scrollRect.width, StructureController.GetStructureControllers().Count *rowHeight); scrollPosition = GUI.BeginScrollView(scrollRect, scrollPosition, viewRect); foreach (StructureController structureController in StructureController.GetStructureControllers()) { DrawStructureRow(structureController, row * rowHeight); row++; } GUI.EndScrollView(); GUI.DragWindow(); }
public static bool ColonyHasAtLeastThisMuch(ResourceTypes resourceType, float thisMuch) { if (thisMuch < 0) { Debug.LogError("ColonyHasAtLeastThisMuch got a negative value. " + thisMuch); } foreach (StructureController sc in StructureController.GetStructureControllers()) { thisMuch -= sc.structureInfo.reserves[resourceType]; if (thisMuch < 0) { return(true); } } return(false); }
private static void AddResources(ResourceTypes resourceType, float positiveAmount) { float amountRemaining = positiveAmount; foreach (StructureController sc in StructureController.GetStructureControllers()) { if (!sc.structureInfo.HasSpaceLeft(resourceType)) { continue; } float freeSpace = sc.structureInfo.GetSpaceLeft(resourceType); float givenAmount = amountRemaining > freeSpace ? freeSpace : amountRemaining; amountRemaining -= givenAmount; sc.structureInfo.ChangeResourceAmount(resourceType, givenAmount); } GetResources()[resourceType] += positiveAmount - amountRemaining; }
private static void TakeResources(ResourceTypes resourceType, float negativeAmount) { float debtRemaining = Mathf.Abs(negativeAmount); foreach (StructureController sc in StructureController.GetStructureControllers()) { float reserve = sc.structureInfo.reserves[resourceType]; if (reserve < 0.01) { continue; } float takenAmount = debtRemaining; if (debtRemaining > reserve) { takenAmount = reserve; } debtRemaining -= takenAmount; sc.structureInfo.ChangeResourceAmount(resourceType, -takenAmount); } GetResources()[resourceType] += negativeAmount; }