public void Grow(PlantInstance plantInstance, LayerData layerData, TextureData textureData) { this.plantInstance = plantInstance; this.layerData = layerData; plantData = this.plantInstance.GetPlantData(); plantLayerIndex = LayerData.MaskToIndex(layerData.plants); growDelay = Random.Range(0f, 0.5f); RaycastHit hit; if (Physics.Raycast(transform.position, Vector3.down, out hit, Mathf.Infinity, layerData.terrain.value)) { if (textureData.FoliageAllowed(hit.point)) { transform.position = hit.point; transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation; if (plantData.randomRotation) { transform.RotateAround(transform.position, transform.up, Random.Range(0f, 360f)); } gameObject.layer = plantLayerIndex; if (plantData.seedPrefab != null) { seedVisual = Instantiate(plantData.seedPrefab, transform.position, transform.rotation); seedVisual.transform.parent = transform; } float scale = plantInstance.GetScale(); transform.localScale = new Vector3(scale, scale, scale); if (!plantData.instantIgnite && !plantData.isCigarette) { SetupSaturation(); } state = State.Seed; } else { Destroy(gameObject); } } else { Destroy(gameObject); } }
private void UpdateBrush(bool hoveringUI) { if (Input.mouseScrollDelta.y > 0) { if (Input.GetKey(KeyCode.LeftShift)) { brush.DecreaseDensity(); } else { brush.DecreaseRadius(); } } else if (Input.mouseScrollDelta.y < 0) { if (Input.GetKey(KeyCode.LeftShift)) { brush.IncreaseDensity(); } else { brush.IncreaseRadius(); } } RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerData.terrain.value) && !hoveringUI) { brush.UpdatePosition(hit.point, hit.normal); bool foliageAllowed = textureData.FoliageAllowed(hit.point); brush.SetBrushEnabled(foliageAllowed); if (Input.GetMouseButton(0) && foliageAllowed) { brush.Paint(); } } }