private void HandleLandChunkSelected(Land_Chunk landChunk) { if (landChunk == selectedLand) return; if (selectedLand) selectedLand.SetSelectedState(false); selectedLand = landChunk; if (selectedLand) selectedLand.SetSelectedState(true); }
private void HandleLandChunkDeselected() { transform.position = selector.GetAveragePositionOfSelected(); Land_Chunk chunk = selector.GetLastSelectedLandChunk(); if (!chunk) return; UpdatePurchaseButton(chunk); UpdatePlowLandButton(chunk); selectedLandChunk = chunk; }
public bool AddChunkChecked(Land_Chunk chunk) { if (!chunk) return false; if (!selectedChunks.Contains(chunk)) { AddChunk(chunk); return true; } return false; }
private void HandleLandChunkSelected(Land_Chunk landChunk) { if (landChunk) { gameObject.SetActive(true); transform.position = selector.GetAveragePositionOfSelected(); UpdatePurchaseButton(landChunk); UpdatePlowLandButton(landChunk); selectedLandChunk = landChunk; } else { gameObject.SetActive(false); selectedLandChunk = null; } }
private GameObject FindIntersectingFencePiece(Land_Chunk a, Land_Chunk b) { GameObject result = null; Collider col = intersectionCheckVolume; //NOTE: returns after first intersection is found for (int i = 0; i < fenceCheckOffsets.Length; ++i) { col.transform.position = a.transform.position + fenceCheckOffsets[i]; result = CheckForFenceIntersection(col.bounds, b); if (result) break; } return result; }
private GameObject CheckForFenceIntersection(Bounds bounds, Land_Chunk b) { GameObject[] pieces = b.fenceMidSections; for (int i = 0; i < pieces.Length; ++i) { if (!pieces[i] || !pieces[i].activeSelf) continue; Collider pieceCol = pieces[i].GetComponentInChildren<Collider>(); if (pieceCol && pieceCol.bounds.Intersects(bounds)) return pieces[i]; } return null; }
//NOTE: Checks for sections of fence that should be unhidden due to tiles being sold by the player. private void FixGapsInFence(Land_Chunk chunk) { Collider intersectionCollider = intersectionCheckVolume; GameObject[] fencePieces = chunk.fenceMidSections; for (int i = 0; i < fencePieces.Length; ++i) { bool activated = false; if (!fencePieces[i] || fencePieces[i].activeSelf) continue; fencePieces[i].SetActive(true); //The post model and collider are children of the fence object. Collider postCollider = fencePieces[i].GetComponentInChildren<Collider>(); if (!postCollider) continue; //Check for adjacent tile using bounds intersection checks. for (int k = 0; k < landChunks.Length; ++k) { if (!landChunks[k] || landChunks[k].owned || landChunks[k].transform == postCollider.transform) continue; intersectionCollider.transform.position = postCollider.transform.position; Collider landCol = landChunks[k].GetComponent<Collider>(); if (landCol) { if (intersectionCollider.bounds.Intersects(landCol.bounds)) { fencePieces[i].SetActive(true); activated = true; break; } } else Print.NotFound<Collider>(this, "failed to find land collider"); } if (!activated) fencePieces[i].SetActive(false); } }
private void HandleNonImportantSelection() { if (selectedLand) selectedLand.SetSelectedState(false); selectedLand = null; }
private void UpdatePlowLandButton(Land_Chunk chunk) { if (!chunk) return; plowLandButton.gameObject.SetActive(showSellScreen && !chunk.plowed); if (plowLandButtonText) plowLandButtonText.text = "Plow: -$" + selector.GetTotalSelectedLandPlowCost().ToString(); }
private void SingleSelection(Land_Chunk chunk) { if (!chunk) return; ClearSelection(); AddChunk(chunk); }
private void HandleChunkSelectedCtrlMod(Land_Chunk chunk) { if (!chunk) return; if (!selectedChunks.Contains(chunk)) AddChunk(chunk); else RemoveChunk(chunk); }
public void RemoveChunk(Land_Chunk chunk) { chunk.SetSelectedState(false); selectedChunks.Remove(chunk); TriggerOnLandChunkDeselected(); }
private void HandleOnLandPlowed(Land_Chunk chunk) { if (selectedLandChunk && chunk == selectedLandChunk) UpdatePlowLandButton(chunk); }
private void UpdatePurchaseButton(Land_Chunk chunk) { if (!chunk) return; if (chunk.owned) { string priceText = selector.GetTotalSelectedLandSellValue().ToString(); purchaseButtonText.text = "Sell +$" + priceText; showSellScreen = true; } else { string priceText = selector.GetTotalSelectedLandCost().ToString(); purchaseButtonText.text = "Purchase -$" + priceText; showSellScreen = false; } }
private void AddNeighborChunk(Land_Chunk chunk) { for (int k = 0; k < neighborChunks.Length; ++k) { if (neighborChunks[k] != null) continue; neighborChunks[k] = chunk; if (k >= neighborChunks.Length) return; break; } }
public void AddChunk(Land_Chunk chunk) { chunk.SetSelectedState(true); selectedChunks.Add(chunk); }
private void TriggerOnLandChunkSelectedCtrlMod(Land_Chunk landChunk) { if (onLandChunkSelectedCtrlMod != null) onLandChunkSelectedCtrlMod(landChunk); }
private void TriggerOnLandChunkSelected(Land_Chunk chunk) { if (onLandChunkSelected != null) onLandChunkSelected(chunk); }