/** * <summary> * Gather resource * </summary> * * <param name="resource">Resource</param> * * <returns> * IEnumerator null * </returns> */ public IEnumerator GatherResource(GameObject resource) { // TODO: in the future, we may need to closestToBuilding() to closestToResource // for custom location position Vector3 closestPoint = this.ClosestPointToBuilding(resource); this.MoveTo(closestPoint); // Move to the closest spot // Once the builder has reached the destination, start the construction while (!this.IsReachedAtDestination(closestPoint)) { if (this.resource == null) { this.StopGatherResource(); } yield return(null); } Debug.Log("BUILDER : RESOURCE GATHERING : START"); // Starting the construction this.resourceGathering = true; while (this.resourceGathering) { if (!resource) { yield break; } this.animation.StartWalkAnimation(); // Look toward the resource //yield return StartCoroutine(this.RotateTo(resource)); ResourceBehaviour resourceBehaviour = resource.GetComponent <ResourceBehaviour>(); resourceBehaviour.SetGathering(true); // Is the resource drained. this.SetResourceGathering(!resourceBehaviour.IsDrained()); yield return(null); } Debug.Log("BUILDER : RESOURCE GATHERING : DONE"); this.SetResource(null); yield return(null); }
/** * <summary> * Cancel the construction, this will pause * the construction * </summary> * * <returns> * void * </returns> */ public void Cancel() { if (!this.structure && !this.resource) { return; } // Cancel building if (this.IsConstructing()) { // Stop the coroutine immediately. this.StopConstruction(); BuildingBehaviour buildingBehaviour = this.structure.GetComponent <BuildingBehaviour>(); buildingBehaviour.SetActivate(false); this.SetConstructing(false); this.SetStructure(null); Debug.Log("BUILDER : BUILDING : CANCEL"); } // Cancel resource gathering else if (this.IsGatheringResource()) { // Stop the coroutine immediately. this.StopGatherResource(); ResourceBehaviour resourceBehaviour = this.resource.GetComponent <ResourceBehaviour>(); resourceBehaviour.SetGathering(false); this.SetResourceGathering(false); this.SetResource(null); Debug.Log("BUILDER : RESOURCE GATHERING : CANCEL"); } }