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); }); }
/// <summary> /// Run from BuildPositionProvider OnReplacePreviewPositionChanged /// </summary> /// <param name="previewPosition"></param> public void ShowPreviewElement(Vector3Int previewPosition) { if (replacedElement != null) { replacedElement.gameObject.SetActive(true); } replacedElement = BuiltElementsStoreController.GetElementAtPosition(previewPosition); if (previewItem.CanBeBuilt == BuildPosition.Top && !SurroundingElementInfo.IsGroundOrBuiltElementBellow(previewPosition)) { return; } replacedElement.gameObject.SetActive(false); DisplayPreviewElement(previewPosition); }
private void CreateSaveFile(SavedPositionType positionType, string screenshotFile, string newSaveFilePath) { var newSave = new SavedPosition() { GridSize = environment.GridSize, WorldTileSide = environment.WorldTileSideSize, positionType = positionType, OriginalOffset = terrain.InitialWorldOffset, TraversedOffset = terrain.TraversedOffset, CharacterPosition = characterTransform.position, CharacterRotation = characterTransform.rotation, ScreenShotFileName = screenshotFile, DateTimeTicks = DateTime.Now.Ticks, BuiltElements = GetBuildDescriptions(BuiltElementsStoreController.GetBuiltElements()) }; var saveResult = FileServices.SavePosition(newSave, newSaveFilePath); ReportMessage(saveResult ? Strings.SaveSuccessful : Strings.SaveFailed, saveResult); OnFileSave?.Invoke(saveResult); }
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()); }
private void ClearElementStores() { ClearAndDestroyGameObjects(GridMap); ClearAndDestroyGameObjects(BuiltElementsStoreController.GetStoreDictionary()); }