/** * <summary> * Unselect the any resource * </summary> * * <returns> * void * </returns> */ public static void UnselectResource() { if (ResourcesManagerBehaviour.SelectedResource == null) { return; } ResourceBehaviour resourceBehaviour = ResourcesManagerBehaviour.SelectedResource .GetComponent <ResourceBehaviour>(); //resourceBehaviour.SetSelect(false); // Hide info component panel Self.infoComponentPanel.SetActive(false); Self.infoComponentPanel .transform .Find("Single") .gameObject .SetActive(false); InfoComponentPanelUI infoComponentPanelUI = Self.infoComponentPanel.GetComponent <InfoComponentPanelUI>(); infoComponentPanelUI.SetName(""); infoComponentPanelUI.SetHealth(0, 100); infoComponentPanelUI.SetIcon(null); ResourcesManagerBehaviour.SelectedResource = null; }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, resourceMask)) { ResourceBehaviour resource = hit.collider.gameObject.GetComponent <ResourceBehaviour>(); if (resource) { if (resource.selected) { resource.SetSelected(false); } else { DeactivateAllResources(); resource.SetSelected(true); } } } else if (!eventSystem.IsPointerOverGameObject()) { DeactivateAllResources(); } } }
/** * <summary> * Select a given resource * </summary> * * <param name="resource">resource</param> * * <returns> * void * </returns> */ public static void SelectResource(GameObject resource) { ResourcesManagerBehaviour.UnselectResource(); // Unselect units if (UnitsManagerBehaviour.SelectedUnits != null) { UnitsManagerBehaviour.UnselectGameObjects(); } ResourceBehaviour resourceBehaviour = resource.GetComponent <ResourceBehaviour>(); //resourceBehaviour.SetSelect(true); // Show info component panel Self.infoComponentPanel.SetActive(true); Self.infoComponentPanel .transform .Find("Single") .gameObject .SetActive(true); ResourceUI resourceUI = resourceBehaviour.GetUI() .GetComponent <ResourceUI>(); InfoComponentPanelUI infoComponentPanelUI = Self.infoComponentPanel.GetComponent <InfoComponentPanelUI>(); infoComponentPanelUI.SetName(resource.name); infoComponentPanelUI.SetHealth(resourceBehaviour.GetHealth(), resourceBehaviour.GetMaxHealth()); infoComponentPanelUI.SetIcon(resourceUI.GetIcon()); // Set selected resource ResourcesManagerBehaviour.SelectedResource = resource; }
/** * <summary> * Turn all visibles placement indicators to a given parameter * </summary> * * <param name="flag"></param> * * <returns> * void * </returns> */ public static void TurnPlacementIndicator(bool flag) { foreach (GameObject resource in ResourcesManagerBehaviour.Resources) { ResourceBehaviour resourceBehaviour = resource.GetComponent <ResourceBehaviour>(); resourceBehaviour.TurnPlacementIndicator(flag); } }
private void UpdateInput() { if (selected) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { if (Input.GetMouseButton(1) && hit.collider) { if (hit.collider.tag == "Cpu") { Entity entity = hit.collider.GetComponent <Entity>(); if (entity != this) { request_farming = false; request_mining = false; SetTarget(entity); SetDestination(Target.transform.position); } } else if (hit.collider.tag == "Resource") { ResourceBehaviour r = hit.collider.GetComponent <ResourceBehaviour>(); Debug.Log(r.name); if (r.name == "Ore") { request_mining = true; SetTarget(null); SetDestination(hit.point); } if (r.name == "Farm") { request_farming = true; SetTarget(null); SetDestination(hit.point); } if (r.name.Contains("Tree")) { request_cutting = true; SetTarget(null); SetDestination(hit.point); } } else { request_farming = false; request_mining = false; request_cutting = false; SetTarget(null); SetDestination(hit.point); } } } } }
public void ReleasePanel(ResourceBehaviour r, string name) { for (int i = 0; i < panels.Length; i++) { if (panels[i] && panels[i].name == name) { ReleasePanel(r, i); break; } } }
public GameObject ShowPanel(ResourceBehaviour r, string name) { for (int i = 0; i < panels.Length; i++) { if (panels[i] && panels[i].name == name) { return(ShowPanel(r, i)); } } return(ShowPanel(r, -1)); }
/** * <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); }
public void ReleasePanel(ResourceBehaviour r, int id) { if (id >= 0 && id < panels.Length) { activeControllers.Remove(r); if (activeControllers.Count == 0) { inventory.SetActive(false); panels[id].SetActive(false); activePanel = -1; } } }
public GameObject ShowPanel(ResourceBehaviour r, int id) { if (activePanel != id) { ClearActivePanel(); } if (id >= 0 && id < panels.Length) { activeControllers.Add(r); inventory.SetActive(true); activePanel = id; return(panels[id]); } return(null); }
/** * <summary> * Refresh or update the selected resource information * </summary> * * <returns> * void * </returns> */ public static void UpdateSelectedResourceInfo() { if (!ResourcesManagerBehaviour.SelectedResource) { return; } ResourceBehaviour resourceBehaviour = ResourcesManagerBehaviour.SelectedResource .GetComponent <ResourceBehaviour>(); ResourceUI resourceUI = resourceBehaviour.GetUI() .GetComponent <ResourceUI>(); InfoComponentPanelUI infoComponentPanelUI = Self.infoComponentPanel.GetComponent <InfoComponentPanelUI>(); infoComponentPanelUI.SetName(ResourcesManagerBehaviour.SelectedResource.name); infoComponentPanelUI.SetHealth(resourceBehaviour.GetHealth(), resourceBehaviour.GetMaxHealth()); infoComponentPanelUI.SetIcon(resourceUI.GetIcon()); }
/** * <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"); } }
// Unit Gathering void ModifyUR(int nl, int ol, UnitController targ) { ResourceBehaviour[] copyArr = new ResourceBehaviour[ol]; for(int x = 0; x < copyArr.Length; x++){ copyArr[x] = targ.resource.behaviour[x]; } targ.resource.behaviour = new ResourceBehaviour[nl]; if(nl > ol){ for(int x = 0; x < copyArr.Length; x++){ targ.resource.behaviour[x] = copyArr[x]; } targ.resource.behaviour[nl-1] = new ResourceBehaviour(); } else{ for(int x = 0; x < targ.resource.behaviour.Length; x++){ targ.resource.behaviour[x] = copyArr[x]; } } }