Esempio n. 1
0
    private IEnumerator Gather(ResourceRoot source)
    {
        properties.currentResource = source.resource;
        while (!source.IsEmpty)
        {
            yield return(StartCoroutine(MoveTo(new Vector3[1] {
                source.transform.position
            })));

            while (!properties.IsFull)
            {
                int unitsThatWillBeGathered = Mathf.Min(properties.unitsGatheredPerSecond, (properties.resourceCapacity - properties.currentResourceAmount));
                print("resourceCapacity: " + properties.resourceCapacity + " - currentResourceAmount: " + properties.currentResourceAmount + " = unitsThatWillBeGathered: " + unitsThatWillBeGathered);
                properties.currentResourceAmount += source.GatherFromHere(unitsThatWillBeGathered);
                yield return(new WaitForSeconds(1));
            }
            IResouceReceiver resouceReceiver = UnitController.GetClosestResourceReceiver(source.resource, transform.position);
            yield return(StartCoroutine(MoveTo(new Vector3[1] {
                (resouceReceiver as StorageBuilding).transform.position
            })));

            properties.GiveResources(resouceReceiver);
        }
    }
Esempio n. 2
0
 public void GiveResources(IResouceReceiver receiver)
 {
     receiver.ReceiveResource(currentResourceAmount, currentResource);
     currentResourceAmount = 0;
 }