void Update() { //Checks if has been picked up and equipped //Sends out raycast Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //Checks if raycast hits if (Physics.Raycast(ray, out hit)) { //Checks if the hit is a ground tile and within Distance for hoeing if (hit.transform.gameObject.tag == "Ground" && Vector3.Distance(_player.transform.position, hit.point) <= shovelDistance && !textureShowing) { //grabs Cell tile and index Cell fertile = tgs.CellGetAtPosition(hit.point, true); int cellIndex = tgs.CellGetIndex(fertile); currentCellIndex = cellIndex; if (currentCellIndex != previousCellIndex) { previousCellIndex = currentCellIndex; } //checks if cell is normal Ground if (tgs.CellGetTag(cellIndex) == 0) { //Sets texture to clickable tgs.CellToggleRegionSurface(cellIndex, true, canClickTexture); //Takes click, sets tile to Fertile if (Input.GetMouseButtonDown(0)) { { tgs.CellSetTag(fertile, 1); StartCoroutine(ChangeTexture(cellIndex, fertileTexture)); } //soundBoard.PlayOneShot(InteractSound); } } //Switches tile back to normal Ground if (tgs.CellGetTag(previousCellIndex) == 0) { StartCoroutine(ChangeTexture(currentCellIndex, groundTexture)); } } } }
void Start() { // playAud = GetComponent<playSequence>(); //grabs Audio treeSounds = gameObject.AddComponent <AudioSource>(); //TerrainGridSystem ref tgs = TerrainGridSystem.instance; randomRotation = 60 * Random.Range(0, 6); // Clone Sapling prefabs and Instantiate groundTile = tgs.CellGetAtPosition(transform.position, true); //transform.SetParent (); cellIndex = tgs.CellGetIndex(groundTile); neighbors = tgs.CellGetNeighbours(groundTile); tgs.CellSetCanCross(cellIndex, false); //fills up neighborIndexes with the proper cell indexes for (int i = 0; i < neighbors.Count; i++) { int index = tgs.CellGetIndex(neighbors[i]); neighborIndexes.Add(index); neighbourPos[i] = tgs.CellGetPosition(index); //this gives you neighbor cell position //can be used to see which cell you’re being given //raycast to this position to get the plant collider and get the sequencer if (tgs.CellGetTag(index) == 1) { //this cell has a tree planted, but don’t run this in start //send to an array of “plants nearby” //for any rule make a bool in plantlife for “isFollowingRule” to see if neighbours are occupied or following a rule already //are two adjacent cells in the index occupied that’s a triad //if all cells are occupied that’s an arp, arp beats triad } } if (plantedInEditor) { ageCounter -= 1; transform.position = tgs.CellGetPosition(cellIndex); tgs.CellSetTag(cellIndex, 1); tgs.CellToggleRegionSurface(cellIndex, true, growingTexture); } else { //Set age and fruit ageCounter = 0; //fruitAmount = 0; growthPeriod = 1; } StartCoroutine(Growth()); }
//Checks if fruit has collided with ground void OnCollisionEnter(Collision collision) { rb.isKinematic = true; if (collision.gameObject.tag == "Ground") { onGround = true; //Checks what ground tile this is using collision point Vector3 collisionPoint = collision.contacts[0].point; Cell groundTile = tgs.CellGetAtPosition(collisionPoint, true); int cellIndex = tgs.CellGetIndex(groundTile); //Starts Decompose using ground tile StartCoroutine(Decompose(groundTile, cellIndex, tgs.CellGetTag(cellIndex))); } }
void Start() { tgs = TerrainGridSystem.instance; for (int i = 0; i < tgs.cells.Count; i++) { if (tgs.CellGetTag(i) == 0) { tgs.CellToggleRegionSurface(i, true, groundTexture); } //if (tgs.CellGetTag(i) == 1) // tgs.CellToggleRegionSurface(i, true, fertileTexture); //if (tgs.CellGetTag(i) == 2) //tgs.CellToggleRegionSurface(i, true, plantedTexture); //if (tgs.CellGetTag(i) == 5) //tgs.CellSetCanCross(i, false); } }
void Update() { //Checks if has been picked up and equipped if (inventMan.underPlayerControl) { //Sends out raycast Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //Checks if raycast hits if (Physics.Raycast(ray, out hit)) { //Checks if the hit is a ground tile and within Distance for planting if (hit.transform.gameObject.tag == "Ground" && Vector3.Distance(_player.transform.position, hit.point) <= withinPlantingRange && !textureShowing) { //grabs Cell tile and index Cell fertile = tgs.CellGetAtPosition(hit.point, true); int cellIndex = tgs.CellGetIndex(fertile); currentCellIndex = cellIndex; if (currentCellIndex != previousCellIndex) { previousCellIndex = currentCellIndex; } //checks if cell is fertile if (tgs.CellGetTag(cellIndex) == 1) { //Sets texture to clickable tgs.CellToggleRegionSurface(cellIndex, true, canClickTexture); //If player clicks, we plant seed and clear up Equip slot if (Input.GetMouseButtonDown(0)) { plantSeed = true; targetPos = hit.point; playerControl.isHoldingSeed = false; inventMan.underPlayerControl = false; invent.usedNowTakeAgain(inventMan.slotNumRetake); } } //If it's a new cell, set last cell back to fertileTexture if (tgs.CellGetTag(previousCellIndex) == 1) { StartCoroutine(ChangeTexture(currentCellIndex, fertileTexture)); } } } //This will be true either after a fruit decomposes, or after player plants seed } if (plantSeed) { //grabs Cell tile and index Cell plantTile = tgs.CellGetAtPosition(targetPos, true); int cellIndex = tgs.CellGetIndex(plantTile); //checks if cell is Fertile if (tgs.CellGetTag(cellIndex) == 1 || planting) { // Debug.Log("planter"); //Centers seed on tile transform.position = new Vector3(tgs.CellGetPosition(cellIndex).x, transform.position.y, tgs.CellGetPosition(cellIndex).z); //Calls PlantSeed function on selected tile PlantSeed(plantTile, cellIndex); } } //always rotate seed in world space transform.Rotate(0, 1, 0 * Time.deltaTime); }
void OnSceneGUI() { if (tgs == null || Application.isPlaying || !tgs.enableGridEditor) { return; } if (tgs.terrain != null) { // prevents terrain from being selected HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); } Event e = Event.current; bool gridHit = tgs.CheckRay(HandleUtility.GUIPointToWorldRay(e.mousePosition)); if (cellHighlightedIndex != tgs.cellHighlightedIndex) { cellHighlightedIndex = tgs.cellHighlightedIndex; SceneView.RepaintAll(); } int controlID = GUIUtility.GetControlID(FocusType.Passive); EventType eventType = e.GetTypeForControl(controlID); if ((eventType == EventType.MouseDown && e.button == 0) || (eventType == EventType.MouseMove && e.shift)) { if (gridHit) { e.Use(); } if (cellHighlightedIndex < 0) { return; } if (!e.shift && cellSelectedIndices.Contains(cellHighlightedIndex)) { cellSelectedIndices.Remove(cellHighlightedIndex); } else { if (!e.shift || (e.shift && !cellSelectedIndices.Contains(cellHighlightedIndex))) { if (!e.shift && !e.control) { cellSelectedIndices.Clear(); } cellSelectedIndices.Add(cellHighlightedIndex); if (textureMode > 0) { tgs.CellToggleRegionSurface(cellHighlightedIndex, true, Color.white, false, textureMode); SceneView.RepaintAll(); } if (cellHighlightedIndex >= 0) { cellTerritoryIndex = tgs.CellGetTerritoryIndex(cellHighlightedIndex); cellColor = tgs.CellGetColor(cellHighlightedIndex); if (cellColor.a == 0) { cellColor = Color.white; } cellTextureIndex = tgs.CellGetTextureIndex(cellHighlightedIndex); cellTag = tgs.CellGetTag(cellHighlightedIndex); } } } EditorUtility.SetDirty(target); } int count = cellSelectedIndices.Count; for (int k = 0; k < count; k++) { int index = cellSelectedIndices [k]; Vector3 pos = tgs.CellGetPosition(index); Handles.color = colorSelection; // Handle size Rect rect = tgs.CellGetRect(index); Vector3 min = tgs.transform.TransformPoint(rect.min); Vector3 max = tgs.transform.TransformPoint(rect.max); float dia = Vector3.Distance(min, max); float handleSize = dia * 0.05f; Handles.DrawSolidDisc(pos, tgs.transform.forward, handleSize); } }