/** * <summary> * Construct a building * </summary> * * <param name="building">Building gameobject</param> * * <returns> * IEnumerator null * </returns> */ private IEnumerator Construct(GameObject building) { Vector3 closestPoint = this.ClosestPointToBuilding(building); this.MoveTo(closestPoint); // Move to the closest spot // Once the builder has reached the destination, start the construction while (!this.IsReachedAtDestination(closestPoint)) { BuildingBehaviour buildingBehaviour = building.GetComponent <BuildingBehaviour>(); if (buildingBehaviour.IsConstructed()) { this.StopConstruction(); } yield return(null); } Debug.Log("BUILDER : CONSTRUCTION : START"); // Starting the construction this.constructing = true; while (this.constructing) { this.animation.StartWalkAnimation(); BuildingBehaviour buildingBehaviour = building.GetComponent <BuildingBehaviour>(); buildingBehaviour.SetActivate(true); this.SetConstructing(!buildingBehaviour.IsConstructed()); yield return(null); } Debug.Log("BUILDER : CONSTRUCTION : DONE"); this.SetStructure(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"); } }