private void InstantiateBuiltElementsFromPosition(List <BuiltElementDescription> dataBuiltElements) { var buildStore = FindObjectOfType <BuildStoreController>(); var builtElementStore = FindObjectOfType <BuiltElementsStoreController>(); var storeItems = buildStore.GetBuildItemsDictionary(); dataBuiltElements.ForEach(item => { if (!storeItems[item.Name]) { print($"Item \"{item.Name}\" was not found in buildStore."); return; } var newElement = Instantiate(storeItems[item.Name], item.Position, Quaternion.identity); newElement.transform.parent = builtElementStore.transform; newElement.gameObject.SetActive(GridMap.ContainsKey(item.Position.ToVector2Int())); var health = newElement.GetComponent <BuildElementLifeCycle>(); if (health) { health.Hitpoints = item.Health; } BuiltElementsStoreController.AddElement(newElement); }); }
private void InstantiateBuildElement() { var previewPosition = previewPresenter.transform.position; if (!canBuild || !inputEnabled || !Input.GetMouseButton(0) || !elementToBuild || !previewPresenter.activeSelf) { return; } var instantiatedElement = Instantiate(elementToBuild, previewPosition, Quaternion.identity); instantiatedElement.tag = elementToBuild.tag; instantiatedElement.transform.parent = builtElementParent; if (gameMode == GameMode.Replace) { replacedElement = null; BuiltElementsStoreController.RemoveAndDestroyElementWithPosition(previewPosition); } BuiltElementsStoreController.AddElement(instantiatedElement); UpdateSurroundingElementsConnections(instantiatedElement); if (instantiatedElement.BuildBaseOn != BuildPosition.AllSides) { //TODO: Here it would need to be tuned for variants of BuildPositions DetachedElementsChecker.CheckForDetachedElements(instantiatedElement); } canBuild = false; StartCoroutine(CooldownCanBuild()); }