public void GiveHarvesterJob(GameObject cat, CatBoxInfo info) { CatListData nextjob = null; if (HarvesterJobs.Count > 0 && info != null) { float width2 = Mathf.Abs((info.x2) - info.x) + 1; float height2 = Mathf.Abs((info.y2) - info.y) + 1; float middlex = (info.x + (info.x2 + 1)) / 2f; float middley = (info.y + (info.y2 + 1)) / 2f; if (HarvesterJobs.Count > 0) { foreach (CatListData job in HarvesterJobs) { if (job.x >= middlex - width2 / 2 && job.x < middlex + width2 / 2 && job.y >= middley - height2 / 2 && job.y < middley + height2 / 2) { nextjob = job; break; } } if (nextjob != null) { if (nextjob.x == -1) { return; } } cat.GetComponent <CatCon>().SetJob(nextjob); TakenJobs.Add(nextjob); HarvesterJobs.Remove(nextjob); } } }
public void SetCatBox(CatBoxInfo info, GameObject plane) { box = new CatBoxInfo(info.x, info.y, info.x2, info.y2); Debug.Log(box.x + "box x"); Debug.Log(box.y + "box y"); Debug.Log(box.x2 + "box x"); Debug.Log(box.y2 + "box y"); patch = plane; }
public void MakeSoilPlane(CatBoxInfo info) { MyBox = new CatBoxInfo(info.x, info.y, info.x2, info.y2); float width = Mathf.Abs((info.x2) - info.x) + 1; float height = Mathf.Abs((info.y2) - info.y) + 1; float middlex = (info.x + (info.x2 + 1)) / 2f; float middley = (info.y + (info.y2 + 1)) / 2f; transform.position = new Vector3(middlex, 0.001f, middley); transform.localScale = new Vector3(width / 10f, 1, height / 10f); }
private void UpdateMouse() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Vector3 mousepos = new Vector3(0, 0, 0); if (Physics.Raycast(ray, out hit, 100f)) { if (hit.transform.gameObject.tag == "Cat") { CatSelected = hit.transform.gameObject; CellHighlight.SetActive(false); hit.transform.gameObject.GetComponent <CatCon>().Highlight(); } else { if (CatSelected != null) { if (CatSelected.GetComponent <CatCon>().selected == false) { CatSelected.GetComponent <CatCon>().Highlightfalse(); CatSelected = null; } } } if (hit.transform.gameObject.tag == "Ground") { mousepos = hit.point; CellHighlight.SetActive(true); } if (hit.transform.gameObject.tag == "Patch") { if (selectingcat == true) { if (Input.GetMouseButtonDown(1) && selectingcat == true && CatSelected != null) { CatSelected.GetComponent <CatCon>().SetCatBox(hit.transform.gameObject.GetComponent <Patch>().MyBox, hit.transform.gameObject); } if (Input.GetMouseButton(1)) { hit.transform.GetComponent <Patch>().Highlight(); selectingcat = false; CatSelected.GetComponent <CatCon>().Highlightfalse(); CatSelected = null; } } if (RemoveMode == true) //destroy patch { var box = hit.transform.gameObject.GetComponent <Patch>().MyBox; float width2 = Mathf.Abs((box.x2) - box.x) + 1; float height2 = Mathf.Abs((box.y2) - box.y) + 1; float refund = width2 * height2 + (width2 * height2 * ExpandCounter); CurrencyManager.GetComponent <Money>().AddCurrency(Mathf.RoundToInt(refund)); Destroy(hit.transform.gameObject); } mousepos = hit.point; CellHighlight.SetActive(true); } if (Input.GetMouseButton(0)) { if (CatSelected != null) { CatSelected.GetComponent <CatCon>().Highlightfalse(); } if (hit.transform.gameObject.tag == "Cat") { CatSelected = hit.transform.gameObject; hit.transform.gameObject.GetComponent <CatCon>().Select(); selectingcat = true; } else { selectingcat = false; } } } else { if (CatSelected != null && selectingcat == false) { CatSelected.GetComponent <CatCon>().Highlightfalse(); CatSelected = null; } if (Input.GetMouseButtonDown(0)) { if (CatSelected != null) { CatSelected.GetComponent <CatCon>().Highlightfalse(); CatSelected = null; } } CellHighlight.SetActive(false); return; } int x1 = Mathf.FloorToInt(mousepos[0]); int y1 = Mathf.FloorToInt(mousepos[2]); int x = 0; int y = 0; float cost = 0; if (x1 >= 0 && x1 <= width && y1 >= 0 && y1 < height) { x = Mathf.FloorToInt(mousepos[0]); y = Mathf.FloorToInt(mousepos[2]); } Vector3 highlightpos = new Vector3(x + 0.5f, 0.05f, y + 0.5f); CellHighlight.transform.position = highlightpos; CellHighlight.transform.localScale = new Vector3(1, 1, 1); if (DrawMode == true) { if (Input.GetMouseButtonDown(0)) { x3 = x; y3 = y; Debug.Log(gridArray[x, y].celltype); } if (Input.GetMouseButton(0)) { float middlex = (x3 + (x + 1)) / 2f; float middley = (y3 + (y + 1)) / 2f; float width2 = Mathf.Abs((x) - x3) + 1; float height2 = Mathf.Abs((y) - y3) + 1; cost = width2 * height2 + (width2 * height2 * ExpandCounter); CostOfNewPatch.text = cost.ToString(); CellHighlight.transform.position = new Vector3(middlex, 0.05f, middley); CellHighlight.transform.localScale = new Vector3(width2, height2, 1); } CatBoxInfo box = new CatBoxInfo(x3, y3, x, y); if (Input.GetMouseButtonUp(0)) { float width2 = Mathf.Abs((x) - x3) + 1; float height2 = Mathf.Abs((y) - y3) + 1; cost = width2 * height2; if (CurrencyManager.GetComponent <Money>().currency < cost) { cost = 0; return; } else { CurrencyManager.GetComponent <Money>().RemoveCurrency(Mathf.RoundToInt(cost)); cost = 0; } for (int x4 = 0; x4 < gridArray.GetLength(0); x4++) { for (int y4 = 0; y4 < gridArray.GetLength(1); y4++) { float middlex = (box.x + (box.x2 + 1)) / 2f; float middley = (box.y + (box.y2 + 1)) / 2f; width2 = Mathf.Abs((box.x2) - box.x) + 1; height2 = Mathf.Abs((box.y2) - box.y) + 1; if (x4 >= middlex - width2 / 2 && x4 < middlex + width2 / 2 && y4 >= middley - height2 / 2 && y4 < middley + height2 / 2) { if (gridArray[x4, y4].celltype == 2) { return; } gridArray[x4, y4].celltype = 2; } } } var plane = Instantiate(SoilPlane, new Vector3(0, 0, 0), Quaternion.identity); plane.gameObject.GetComponent <Patch>().MakeSoilPlane(box); } } if (Input.GetMouseButtonDown(0) && Pause == false && DrawMode == false) { if (gridArray[x, y].celltype == 2) { if (ReturnNumberOfSeeds(SelectedSeedType) > 0) { if (CatSelected.GetComponent <CatCon>().selected == false) { CatSelected.GetComponent <CatCon>().Highlightfalse(); CatSelected = null; } } } else { HarvestCell(x, y); } UpdatePrefab(x, y); CatManager.GetComponent <CatManager>().UpdateListWithMouse(x, y, gridArray[x, y].celltype); } }