private void CreateBoxes() { for (int i = 0; i < _count / _rowCount; i++) { for (int h = 0; h < _rowCount; h++) { PlantBox p = Instantiate(PlantBoxPrefab, BoxParent); p.transform.localPosition = new Vector3(_Spacing.x * h, _Spacing.y, _Spacing.z * i); _plantBoxes.Add(p); } } }
public void PlantSeed(Seed seed, PlantBox box, Action onComplete, Action onFailed) { if (box.IsFull) { onFailed?.Invoke(); } else { box.PlantSeed(seed); onComplete?.Invoke(); } }
private void PlantCallBack(PlantBox box, SeedBox seedBox) { if (box == null || seedBox == null) { return; } if (box.IsFull || !seedBox.IsFull) { return; } box.PlantSeed(seedBox._currentSeed); seedBox.RemoveSeed(); SaveSeeds(); }
private void PlantBoxSelected(PlantBox _box) { if (_box.IsFull && _box.fullyGrown && !_box._hasReturnedSeed) { // Try Harvest if (_seedBoxContainer.HasEmptySpace) { Seed _seed = _box.Harvest(); if (_seed != null) { _seedBoxContainer.AddToSlot(_seed); SaveSeeds(); } } else if (_box.IsFull) { if (PlantInteractorView.Instance != null) { PlantInteractorView.Instance.OpenPanel(_box); } } } else if (!_box.IsFull && _selectedBox != null && _selectedBox.IsFull) { _box.PlantSeed(_selectedBox._currentSeed); _selectedBox.RemoveSeed(); } else if (_box.IsFull) { if (PlantInteractorView.Instance != null) { PlantInteractorView.Instance.OpenPanel(_box); } } _selectedBox = null; SaveSeeds(); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { if (_eventSystem.IsPointerOverGameObject()) { } else { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 10000f)) { Debug.Log("Clicked on" + hit.transform.name); PlantBox box = hit.transform.GetComponent <PlantBox>(); if (box != null && box.OnBoxSelect != null) { StartCoroutine(WaitAndTrigger(() => { box.OnBoxSelect?.Invoke(box); })); } else if (hit.transform.gameObject == _chestObject) { _chestObject.SetActive(false); if (ItemParticlesAnimator.Instance != null) { ItemParticlesAnimator.Instance.NewGenericRewardAnimation(CurrencyManager.Instance.MainCurrency, ItemParticlesAnimator.Instance.DefaultAnimation, 100, Input.mousePosition, IncrementalController.Instance.CurrencyDestination.transform.position); StartCoroutine(SlowlyAddToCurrency()); } } } } } if (Input.GetMouseButton(0) && _dragSeedBox != null) { dragImage.rectTransform.position = Input.mousePosition; } if (Input.GetMouseButtonUp(0)) { if (_nextSeedBox != null && _dragSeedBox != null) { _nextSeedBox.DropCall?.Invoke(_nextSeedBox, _dragSeedBox); } else { if (_eventSystem.IsPointerOverGameObject()) { } else if (_dragSeedBox != null) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 10000f)) { PlantBox box = hit.transform.GetComponent <PlantBox>(); if (box != null) { GameObject g = Instantiate(_plantParticle, this.transform); g.transform.position = box.transform.position + new Vector3(0, 0.1f, 0); Destroy(g, 1f); box.PlantCallBack?.Invoke(box, _dragSeedBox); StartCoroutine(WaitAndTrigger(() => { if (ItemParticlesAnimator.Instance != null) { ItemParticlesAnimator.Instance.NewGenericRewardAnimation(CurrencyManager.Instance.MainCurrency, ItemParticlesAnimator.Instance.DefaultAnimation, 100, new Vector3(Screen.width / 2, Screen.height / 2, 0) /*dragImage.gameObject.transform*/, IncrementalController.Instance.CurrencyDestination.transform.position); StartCoroutine(SlowlyAddToCurrency()); } })); } } } } dragImage.gameObject.SetActive(false); _dragSeedBox = null; _nextSeedBox = null; } if (Input.GetKeyDown(KeyCode.Space)) { _chestObject.SetActive(true); } if (Input.GetKeyDown(KeyCode.LeftShift)) { if (NewAreaUnlocked.Instance != null) { NewAreaUnlocked.Instance.Show(); } } }
public void DestroySeed() { _currentBox.RemoveSeed(); _currentBox = null; Hide(); }
public void CloseClick() { _currentBox = null; Hide(); }
public void OpenPanel(PlantBox _box) { _currentBox = _box; FillOut(); Show(); }
public void ClickPlantBox(PlantBox _box) { OnBoxSelect?.Invoke(_box); }
private void PlantCallBack(PlantBox box, SeedBox seedBox) { PlantCall?.Invoke(box, seedBox); }