public void ResetState() { description.text = ""; cost.text = ""; foreach (ResourceIcon res in resourceIconList) { res.gameObject.SetActive(false); } foreach (ConstructionIcon ico in icons) { ico.gameObject.SetActive(false); } if (layerIcon) { layerIcon.border.color = selectedLayerColorCache; } if (selectedIcon) { selectedIcon.border.color = selectedLayerColorCache; } hoveredIcon = null; selectedIcon = null; layerIcon = null; selectedLayer = null; iconsContainer.sizeDelta = new Vector2(iconsContainer.sizeDelta.x, 122); }
public void OnIconPointerEnter(ConstructionIcon icon) { if (hoveredIcon != icon && hoveredIcon && hoveredIcon != selectedIcon && hoveredIcon != layerIcon) { hoveredIcon.border.color = hoveredColorCache; } if (icon != selectedIcon && icon != layerIcon) { hoveredIcon = icon; if (hoveredIcon) { hoveredColorCache = hoveredIcon.border.color; hoveredIcon.border.color = hoveredBorderColor; } } description.text = icon.description; ConstructionLayer layer = icon.gameObject.GetComponent <ConstructionLayer>(); if (!layer) { cost.text = (icon.cost.Count == 0) ? "Free" : "Cost :"; LoadCost(icon); } }
private void ResetState() { if (grid.grid.ContainsKey(lastChunkPointing)) { grid.grid[lastChunkPointing].SetBatchVisible(true); } if (lastPointedTile != null) { if (lastPointedTile.terrain) { lastPointedTile.terrain.SetActive(true); } if (lastPointedTile.building) { lastPointedTile.building.SetActive(true); } if (lastPointedTile.decoration) { lastPointedTile.decoration.SetActive(true); } } brush = null; targetLayer = null; lastIcon = null; lastPointedTile = null; lastChunkPointing = new Vector2Int(int.MinValue, int.MinValue); preview.SetActive(false); constructionUI.ResetState(); constructionUI.rotationTip.text = "press " + rotationLeft.ToString() + " or " + rotationRight.ToString() + " to rotate"; constructionUI.rotationTip.gameObject.SetActive(false); }
private void LoadCost(ConstructionIcon icon) { if (icon.cost.Count > resourceIconList.Count) { Debug.LogWarning("Not enough prefab in ConstructionUIJuicer to assign all resources of icon " + icon.name); } int index = 0; foreach (KeyValuePair <string, int> entry in icon.cost) { if (sortedResources.ContainsKey(entry.Key)) { resourceIconList[index].gameObject.SetActive(true); resourceIconList[index].icon.sprite = sortedResources[entry.Key].icon; resourceIconList[index].text.text = entry.Value.ToString(); index++; } else { Debug.LogWarning("Construction icon " + icon.name + " refer to an unknown resource : " + entry.Key); } if (index >= resourceIconList.Count) { break; } } for (; index < resourceIconList.Count; index++) { resourceIconList[index].gameObject.SetActive(false); } }
public void UnselectBrush() { if (selectedIcon) { selectedIcon.border.color = selectedColorCache; } selectedIcon = null; }
public void OnIconPointerExit(ConstructionIcon icon) { if (icon != selectedIcon && icon != layerIcon && hoveredIcon == icon && hoveredIcon) { hoveredIcon.border.color = hoveredColorCache; } hoveredIcon = null; description.text = ""; }
void Update() { ModeUpdate(); if (!activated) { return; } // tool state update if (lastIcon != constructionUI.selectedIcon) { LoadBrush(constructionUI.selectedIcon); lastIcon = constructionUI.selectedIcon; } // pointing the world if (!eventsystem.IsPointerOverGameObject() && !constructionUI.helpVideo.activeSelf) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 200f, 1 << LayerMask.NameToLayer("Ground"))) { Vector2Int chunkPointing = MapChunk.WorldToCell(hit.point); Vector3Int tilePointing = modifier.WorldToCell(hit.point); Vector3 pointing = modifier.GetTileCenter(tilePointing); // make chunk batches disabled if (grid.grid.ContainsKey(chunkPointing) && lastChunkPointing != chunkPointing) { if (grid.grid.ContainsKey(lastChunkPointing)) { grid.grid[lastChunkPointing].SetBatchVisible(true); } grid.grid[chunkPointing].SetBatchVisible(false); lastChunkPointing = chunkPointing; } // update depending on selected tool if (brush != null) { BrushToolUpdate(tilePointing, pointing); } else if (targetLayer && targetLayer.layerType == ConstructionLayer.LayerType.Delete) { DeleteToolUpdate(tilePointing, pointing); } } } }
private void ModeUpdate() { // mode update if (activated && ((Input.GetKeyDown(KeyCode.Escape) && brush == null) || Input.GetKeyDown(keyMode))) { activated = false; } else if (!activated && Input.GetKeyDown(keyMode)) { activated = true; } if (lastActivated != activated) { if (activated) { ForgeUI.instance.gameObject.SetActive(false); } else { constructionUI.helpVideo.SetActive(false); } tpsController.activated = !activated; rtsController.activated = activated; constructionUI.ResetState(); constructionUI.gameObject.SetActive(activated); RenderSettings.fog = !activated; ResetState(); } lastActivated = activated; gridRenderer.enabled = activated; if (activated && Input.GetKeyDown(KeyCode.Escape) && brush != null) { brush = null; targetLayer = null; lastIcon = null; preview.SetActive(false); constructionUI.rotationTip.gameObject.SetActive(false); constructionUI.UnselectBrush(); } }
public void OnIconClick(ConstructionIcon icon) { if (icon != selectedIcon && icon != layerIcon) { if (hoveredIcon != icon && hoveredIcon && hoveredIcon != layerIcon) { hoveredIcon.border.color = hoveredColorCache; } if (selectedIcon && selectedIcon != layerIcon) { selectedIcon.border.color = selectedColorCache; } if (icon) { selectedColorCache = hoveredColorCache; ConstructionLayer layer = icon.gameObject.GetComponent <ConstructionLayer>(); if (layer) { if (layerIcon && layer != selectedLayer) { layerIcon.border.color = selectedLayerColorCache; } selectedLayerColorCache = selectedColorCache; layerIcon = icon; selectedLayer = layer; LoadLayerIcons(layer); } icon.border.color = selectedBorderColor; } } hoveredIcon = icon; selectedIcon = icon; }
void Start() { eventsystem = (EventSystem)FindObjectOfType(typeof(EventSystem)); tpsController.activated = !activated; rtsController.activated = activated; constructionUI.gameObject.SetActive(activated); lastActivated = activated; RenderSettings.fog = !activated; lastIcon = constructionUI.selectedIcon; previewMeshFilter = preview.AddComponent <MeshFilter>(); MeshRenderer mr = preview.AddComponent <MeshRenderer>(); mr.sharedMaterial = previewMaterial; currentPreviewMaterial = mr.material; multiPreviewPrefab.SetActive(false); multiPreviewFilters.Add(multiPreviewPrefab.GetComponent <MeshFilter>()); mr = multiPreviewPrefab.GetComponent <MeshRenderer>(); mr.sharedMaterial = previewMaterial; multiPreviewRenderers.Add(mr); for (int i = 0; i < maximumMultiplacement - 1; i++) { GameObject go = Instantiate(multiPreviewPrefab); go.name = multiPreviewPrefab.name; go.transform.parent = multiPreviewContainer; go.transform.localPosition = Vector3.zero; go.SetActive(false); multiPreviewFilters.Add(go.GetComponent <MeshFilter>()); mr = go.GetComponent <MeshRenderer>(); mr.sharedMaterial = previewMaterial; multiPreviewRenderers.Add(mr); } if (export_csv) { file_csv += "Constructions data\n" + "Name;Wood;Wheat;Stone;Iron;Gold;Crystal\n"; } foreach (ConstructionData cd in buildingList) { knownBuildings.Add(cd.name, cd); if (export_csv) { ItemCost cost = GetCost(cd); file_csv += cd.name + ";" + cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n"; } } if (export_csv) { StreamWriter writer = new StreamWriter("Assets/Resources/constructions.csv", false); writer.WriteLine(file_csv); writer.Close(); } ResetState(); }
private void LoadBrush(ConstructionIcon icon) { if (targetLayer && targetLayer != constructionUI.selectedLayer && targetLayer.layerType == ConstructionLayer.LayerType.Terrain) { if (lastPointedTile != null && lastPointedTile.terrain) { lastPointedTile.terrain.SetActive(true); } } targetLayer = constructionUI.selectedLayer; if (icon != constructionUI.layerIcon) { brush = icon; preview.SetActive(true); previewMeshFilter.sharedMesh = brush.data.preview; foreach (MeshFilter mf in multiPreviewFilters) { mf.sharedMesh = brush.data.preview; } previewArrow.transform.localEulerAngles = new Vector3(0, 0, 0); // preview preview.transform.localEulerAngles = brush.data.previewEulerOffset; if (brush.name.Contains("RegularTree")) { preview.transform.localScale = 2f * Vector3.one; } else { preview.transform.localScale = Vector3.one; } // preview arrows if (brush.name.Contains("Tower")) { previewArrow.transform.localEulerAngles = new Vector3(0, 0, -90); } else if (brush.name.Contains("Granary") || brush.name.Contains("Windmill")) { previewArrow.transform.localEulerAngles = new Vector3(0, 0, -90); } if (targetLayer.layerType != ConstructionLayer.LayerType.Building || brush.name.Contains("Fence") || brush.name.Contains("Wall")) { previewArrow.SetActive(false); } else { previewArrow.SetActive(true); } } else if (targetLayer.layerType == ConstructionLayer.LayerType.Delete) { preview.SetActive(true); previewArrow.SetActive(false); previewMeshFilter.sharedMesh = deletionMesh; preview.transform.localEulerAngles = new Vector3(0, 0, 0); preview.transform.localScale = Vector3.one; currentPreviewMaterial.color = previewInvalid; brush = null; } else { brush = null; preview.SetActive(false); previewArrow.SetActive(false); } constructionUI.rotationTip.gameObject.SetActive(previewArrow.activeSelf); }