private bool AoE() { if (areaEffect > 0) { List <Vector2Int> hexes; hexes = TerrainGen.GetHexInRange(TerrainGen.GetGridPosition2D(transform.position), Mathf.RoundToInt(1 + areaEffect)); List <mobBase> mobs = new List <mobBase>(); foreach (Vector2Int hex in hexes) { List <mobBase> mobHex = MobLister.GetMobList(hex); if (mobHex != null) { foreach (mobBase mob in mobHex) { float distance = MyMath.calcDistance(transform.position, mob.transform.position); if (distance < areaEffect * TerrainGen.hexSize && mob != target) { mobs.Add(mob); } } } } foreach (mobBase mob in mobs) { float distance = MyMath.calcDistance(transform.position, mob.transform.position); float dmgMult = distance / (TerrainGen.hexSize * areaEffect); mob.DamageMob(damage); } return(true); } return(false); }
public void RecalcArea(PathType type, Vector2Int position, int radius) { List <Vector2Int> hexes; hexes = TerrainGen.GetHexInRange(position, radius); indexes[type]++; foreach (Vector2Int hex in hexes) { FindGoal(type, TerrainGen.GetGridPosition2D(goal), hex); } }
public static void RemoveMob(mobBase oldMob) { Vector2Int gridPos = TerrainGen.GetGridPosition2D(oldMob.thisHex); RemoveMobFromGrid(oldMob, gridPos); mobList.Remove(oldMob); oldMob.transform.SetParent(deadMobs.transform); oldMob.gameObject.SetActive(false); deadMobList.Add(oldMob); allMobs.name = "Mobs: (" + mobList.Count + " / " + deadMobList.Count + ") = " + (deadMobList.Count + mobList.Count); //Debug.Log("Dead mobs " + deadMobList.Count); }
public void GetParticleSystems() { ParticleSystem[] spawnParticles = GetComponentsInChildren <ParticleSystem>(); foreach (ParticleSystem system in spawnParticles) { Vector2Int gridPos; gridPos = TerrainGen.GetGridPosition2D(system.transform.position); if (!hexParticles.ContainsKey(gridPos)) { hexParticles.Add(gridPos, system); } } }
/// <summary> /// Updates the highlight grid to show where a tower could hit taking its name as a string. /// </summary> /// <param name="tower"></param> void PreviewTowerRange(string tower) { float?towerVal = Towers.instance.GetTowerValue(tower, "attack_range"); int range = 0; float heightOffset = 0.05f; bool arc = false; if (towerVal.HasValue) { range = (int)towerVal.Value; } towerVal = Towers.instance.GetTowerValue(tower, "projectile_arc"); if (towerVal.HasValue) { arc = true; } towerVal = Towers.instance.GetTowerValue(tower, "projectile_yoff"); if (towerVal.HasValue) { heightOffset = towerVal.Value; } HexHighlighter.ResetGrid(); Dictionary <string, List <Vector2Int> > hexes = TowerBase.GetHexesInRange(hexHook.transform.position, range, arc, heightOffset); if (hexes.ContainsKey("good") && hexes["good"] != null) { foreach (Vector2Int newPos in hexes["good"]) { if (!MyMath.IsWithin(newPos.x, -1, TerrainGen.gridX) || !MyMath.IsWithin(newPos.y, -1, TerrainGen.gridZ)) { continue; } if (newPos != TerrainGen.GetGridPosition2D(hexHook.transform.position)) { HexHighlighter.Set(newPos, HexHighlight.positive); } } } if (hexes.ContainsKey("bad") && hexes["bad"] != null) { foreach (Vector2Int newPos in hexes["bad"]) { if (!MyMath.IsWithin(newPos.x, -1, TerrainGen.gridX) || !MyMath.IsWithin(newPos.y, -1, TerrainGen.gridZ)) { continue; } HexHighlighter.Set(newPos, HexHighlight.negative); } } }
private bool Fork() { if (forkCount > 0 && forkProjectiles > 0) { List <Vector2Int> hexes; hexes = TerrainGen.GetHexInRange(TerrainGen.GetGridPosition2D(transform.position), (int)chainDistanceMax); List <mobBase> mobs = new List <mobBase>(); foreach (Vector2Int hex in hexes) { List <mobBase> mobHex = MobLister.GetMobList(hex); if (mobHex != null) { foreach (mobBase mob in MobLister.GetMobList(hex)) { float distance = MyMath.calcDistance(transform.position, mob.transform.position); if (distance > chainDistanceMin && distance < chainDistanceMax) { mobs.Add(mob); } } } } // forkCount -= 1; forkProjectiles = Mathf.RoundToInt(forkProjectiles * 0.5f); damage *= forkDamageLoss; if (mobs.Count > 0) { for (int i = 0; i < forkProjectiles; i++) { ProjectileBase newProj = CopyProjectile(chainDamageLoss); newProj.transform.position = this.transform.position; int randomTarget = Random.Range(0, mobs.Count - 1); newProj.target = mobs[randomTarget]; mobs.RemoveAt(randomTarget); if (mobs.Count == 0) { break; } } } // return(true); } return(false); }
// Update is called once per frame void Update() { if (debug) { Debug.DrawRay(goal, Vector3.up, Color.white); } if (TerrainGen.terrainGenerated) { if (criticalUpdateNodes[PathType.normal].Count > 0) { foreach (PathNode node in criticalUpdateNodes[PathType.normal]) { UpdateNode(PathType.normal, node, true); } criticalUpdateNodes[PathType.normal].Clear(); } else { if (updateNodes[PathType.normal].Count > 0) { Vector2Int updateNode = updateNodes[PathType.normal][0]; FindGoal(PathType.normal, TerrainGen.GetGridPosition2D(goal), updateNode); //TargetNode(ref updateNode, PathType.normal); updateNodes[PathType.normal].RemoveAt(0); } else { //updateNodes[PathType.normal].Add(pathGrids[PathType.normal][UnityEngine.Random.Range(0, gridX - 1), UnityEngine.Random.Range(0, gridZ - 1)]); //updateNodes[PathType.normal].Add(pathGrids[PathType.normal][UnityEngine.Random.Range(0, gridX - 1), UnityEngine.Random.Range(0, gridZ - 1)]); //updateNodes[PathType.normal].Add(pathGrids[PathType.normal][UnityEngine.Random.Range(0, gridX - 1), UnityEngine.Random.Range(0, gridZ - 1)]); } } if (debug) { if (HexHighlighter.showingPath != displayType) { if (pathGrids.ContainsKey(displayType)) { ShowOnGrid(displayType); HexHighlighter.showingPath = displayType; gridShowing = displayType; } } } } }
public void SpawnFromOrb(SpawnOrb orb, float spawnPoints) { Vector2Int hex = TerrainGen.GetGridPosition2D(orb.transform.position); List <Vector2Int> hexes = TerrainGen.GetHexInRange(hex, 3); string mobType = Mobs.instance.getRandomMob(); mobType = "slime"; while (spawnPoints > 0) { hex = hexes[Random.Range(0, hexes.Count)]; while (TerrainGen.GetHex(hex.x, hex.y) == null) { hex = hexes[Random.Range(0, hexes.Count)]; } SpawnMob(ref spawnPoints, hex, mobType); } KillOrb(orb); }
public mobBase SpawnMob(ref float mobPoints, Vector2Int hex = new Vector2Int(), string nextMob = "") { Vector3 newPos; if (hex == new Vector2Int()) { newPos = TerrainGen.GetHexPosition(spawnHexes[Random.Range(0, spawnHexes.Count)]); } else { newPos = TerrainGen.GetHexPosition(hex); } if (nextMob == "") { nextMob = Mobs.instance.getRandomMob(); } mobBase newMob; newMob = MobLister.GetDeadMob(); newMob.goal = goal; newMob.gameObject.SetActive(true); mobPoints -= newMob.SetMob(nextMob); mobs.Add(newMob); newMob.SetSpawner(this); newMob.goal = goal; //newMob.transform.position = newPos; newMob.SetAgentPosition(newPos); //newMob.SetAgentDestination(TerrainGen.goal.transform.position); Vector2Int gridPos = TerrainGen.GetGridPosition2D(newPos); if (hexParticles.ContainsKey(gridPos)) { ParticleSystem spawnSystem; spawnSystem = hexParticles[gridPos]; ParticleSystem.Burst burst; burst = new ParticleSystem.Burst(0, (int)mobPoints); spawnSystem.emission.SetBurst(0, burst); spawnSystem.time = 0; } return(newMob); }
private bool Chain() { if (chainCount > 0) { List <Vector2Int> hexes; hexes = TerrainGen.GetHexInRange(TerrainGen.GetGridPosition2D(transform.position), (int)chainDistanceMax); List <mobBase> mobs = new List <mobBase>(); foreach (Vector2Int hex in hexes) { List <mobBase> mobHex = MobLister.GetMobList(hex); if (mobHex != null) { foreach (mobBase mob in mobHex) { float distance = MyMath.calcDistance(transform.position, mob.transform.position); if (distance > chainDistanceMin && distance < chainDistanceMax && mob != target) { mobs.Add(mob); } } } } chainCount -= 1; damage *= chainDamageLoss; if (mobs.Count > 0) { Debug.Log("Chaining"); ProjectileBase newProj = CopyProjectile(chainDamageLoss); newProj.SetParticleSystems(effect, explosion); newProj.transform.position = this.transform.position; newProj.target = mobs[Random.Range(0, mobs.Count - 1)]; Debug.DrawLine(newProj.transform.position, newProj.target.transform.position, Color.red, 1); } return(true); // } return(false); }
void GetClump() { Vector2Int gridPos = TerrainGen.GetGridPosition2D(this.transform.position); clumpMobs = new List <mobBase>(); for (int i = 0; i < 6; i++) { int ind = i; if ((gridPos.y & 1) == 1) { ind += 6; } Vector2Int offPos = gridPos; offPos.x += MyMath.hexOffSetGrid[ind].x; offPos.y += MyMath.hexOffSetGrid[ind].y; foreach (mobBase mob in MobLister.mobGrid[offPos.x, offPos.y]) { if (!clumpMobs.Contains(mob)) { clumpMobs.Add(mob); } } } }
public bool FindGoal(PathType pathType, Vector2Int goal, Vector2Int start) { if (pathGrids[pathType][start.x, start.y].index == indexes[pathType]) { return(true); } Vector2Int pos = start; List <PathNode> checkNodes = new List <PathNode>(); List <PathNode> doneNodes = new List <PathNode>(); PathNode newNode; BuildingBase building; Vector3 rayPos; RaycastHit hit; newNode = new PathNode(pos.x, pos.y) { distance = Mathf.RoundToInt(TerrainGen.GetHexDistance(pos, TerrainGen.GetGridPosition2D(PathKeeper.goal))) }; newNode.sortCost = newNode.distance; checkNodes.Add(newNode); Vector2Int checkStep = new Vector2Int(); int rounds = 0; // while (pos != goal && checkNodes.Count > 0) { checkNodes.Sort(); if (debug) { Vector3 startDraw = TerrainGen.GetHexPosition(pos); Vector3 endDraw = TerrainGen.GetHexPosition(checkNodes[0].position); startDraw.y += 0.01f; endDraw.y += 0.01f; Debug.DrawLine(startDraw, endDraw, Color.green, 3); } pos = checkNodes[0].position; int ind = 0; if (pos.y % 2 == 0) { ind += 6; } for (int i = 0; i < 6; i++) { checkStep.x = pos.x + MyMath.hexOffSetGrid[ind + i].x; checkStep.y = pos.y + MyMath.hexOffSetGrid[ind + i].z; if (pathGrids[pathType][pos.x, pos.y].index == indexes[pathType]) { continue; } newNode = new PathNode(checkStep.x, checkStep.y); if (debug) { Debug.DrawLine(TerrainGen.GetHexPosition(pos), TerrainGen.GetHexPosition(checkStep), Color.red, 2); } newNode.distance = Mathf.RoundToInt(TerrainGen.GetHexDistance(checkStep, TerrainGen.GetGridPosition2D(PathKeeper.goal))); newNode.sortCost = CalcCost(pathType, pos, checkStep) + checkNodes[0].sortCost; newNode.cost = CalcCost(pathType, pos, checkStep) + newNode.distance; newNode.index = indexes[pathType]; newNode.from = pos; rayPos = TerrainGen.GetHexPosition(checkStep); rayPos.y += 2; if (Physics.Raycast(rayPos, Vector3.down, out hit, 3)) { building = hit.collider.GetComponentInParent <BuildingBase>(); if (building != null) { if (pathType != PathType.flight && building.HasProperty(BuildingProperties.blocking)) { newNode.sortCost += 100000; } } } int exists = checkNodes.FindIndex(a => a.position == newNode.position); if (exists == -1 && doneNodes.FindIndex(node => node.position == newNode.position) == -1) { checkNodes.Add(newNode); } else if (exists != -1) { PathNode existingNode = checkNodes[exists]; if (existingNode.sortCost > newNode.sortCost) { checkNodes.Remove(existingNode); checkNodes.Add(newNode); } } } doneNodes.Add(checkNodes[0]); checkNodes.RemoveAt(0); if (rounds > 500) { Debug.Log("Ending Pathfind with " + checkNodes.Count + " / " + doneNodes.Count); break; } rounds++; } doneNodes.Sort(); PathNode thisNode; PathNode fromNode; List <PathNode> adjacentNodes; bool atStart = false; rounds = 0; thisNode = doneNodes[0]; while (!atStart && rounds < 500 && thisNode != null) { fromNode = doneNodes.Find(node => node.position == thisNode.from); if (fromNode != null) { //fromNode.target = thisNode.position; //Find all nodes that came from fromNode adjacentNodes = doneNodes.FindAll(node => node.from == fromNode.position); foreach (PathNode node in adjacentNodes) { //See if the node is adjacent to out new target if (MyMath.hexOffSetGrid2D.Contains(thisNode.position - node.position)) { if (debug) { Vector3 drawStart = TerrainGen.GetHexPosition(node.position); Vector3 drawEnd = drawStart; drawEnd.y += 0.1f; Debug.DrawLine(drawStart, drawEnd, Color.magenta, 3); } if (node.target == node.position) { Debug.DrawRay(TerrainGen.GetHexPosition(node.position), Vector3.up, Color.red, 5); } node.target = thisNode.position; pathGrids[pathType][thisNode.x, thisNode.z] = node; //doneNodes.Remove(node); } else { if (debug) { Vector3 drawStart = TerrainGen.GetHexPosition(node.position); Vector3 drawEnd = drawStart; drawEnd.y += 0.1f; Debug.DrawLine(drawStart, drawEnd, Color.yellow, 3); } node.target = fromNode.position; pathGrids[pathType][thisNode.x, thisNode.z] = node; //doneNodes.Remove(node); } } } else { Debug.Log("No node found"); //pathGrids[pathType][thisNode.x, thisNode.z] = thisNode; } if (thisNode.target == Vector2Int.zero && thisNode.position != goal) { //Find best target by cost; Debug.Log("we got a lonly one"); } pathGrids[pathType][thisNode.x, thisNode.z] = thisNode; rounds++; thisNode = fromNode; } foreach (PathNode node in checkNodes) { //updateNodes[pathType].Add(node.position); } return(false); }
// Update is called once per frame void FixedUpdate() { overButton = false; mousePos = GetMousePosition(); mousePos.z = -2; snapPos = mousePos; snapPos.z = 0; snapPos = MyMath.SnapToSub(subSnaps, snapPos); transform.position = mousePos; if (UIHits.Count > 0) { TriButton hitButton; ButtonClick clickButton; foreach (RaycastResult hit in UIHits) { if (hit.gameObject != null) { hitButton = hit.gameObject.GetComponent <TriButton>(); clickButton = hit.gameObject.GetComponent <ButtonClick>(); triMenu.ResetButtons(); if (hitButton != null) { overButton = true; hitButton.SetState(1); } if (clickButton != null) { overButton = true; } } } } UIHits = new List <RaycastResult>(); UIEvent = new PointerEventData(UIEventSystem); UIEvent.position = Input.mousePosition; UICaster.Raycast(UIEvent, UIHits); if (selectedBuilding == null && selectedSpawner == null && !keepDetails) { triMenu.DestroyDetails(); } if (UIHits.Count > 0) { //Debug.Log("UI hit"); TriButton hitButton; LinkToggle linkButton; foreach (RaycastResult hit in UIHits) { //Check For TriMenu hitButton = hit.gameObject.GetComponent <TriButton>(); if (hitButton != null) { // Load details for whichever button hit. Vector2 detailPos = GetScreenPosition(hexHook.transform.position); detailPos.x -= 120; string buttonVal = hitButton.getValue().ToLower(); switch (buttonVal) { case "build_speed_augment_button": case "build_range_augment_button": case "build_damage_augment_button": case "build_chain_augment_button": case "build_fork_augment_button": case "build_multi_augment_button": case "build_ethereal_augment_button": triMenu.DestroyDetails(); triMenu.CreateDetails(detailPos); triMenu.AddDetail(hitButton.getValue(), -1); triMenu.LoadDetails(Towers.instance.GetAugment(buttonVal.Replace("build_", "").Replace("_button", "").Replace("_augment", ""))); triMenu.RefreshDetails(); keepDetails = true; break; case "build_fire_tower_button": case "build_water_tower_button": case "build_earth_tower_button": case "build_air_tower_button": case "build_basic_tower_button": triMenu.DestroyDetails(); triMenu.CreateDetails(detailPos); triMenu.AddDetail(Translator.Get(buttonVal), -1); string tower = buttonVal.Replace("build_", "").Replace("_button", "").Replace("_tower", ""); triMenu.LoadDetails(Towers.instance.GetTower(tower)); triMenu.RefreshDetails(); keepDetails = true; break; default: break; } if (lastButtonHover != buttonVal && triMenu.CurrentMenu() == "towers_build") { PreviewTowerRange(buttonVal.Replace("build_", "").Replace("_button", "").Replace("_tower", "")); } lastButtonHover = buttonVal; } //Check For Link Toggle linkButton = hit.gameObject.GetComponent <LinkToggle>(); if (linkButton != null) { Vector2 detailPos = GetScreenPosition(hexHook.transform.position); detailPos.x -= 96; } } } if (Input.GetAxis("Jump") == 1) { if (currentCamera == CurrentCamera.main) { ChangeCamera(CurrentCamera.overhead); } } else { ChangeCamera(CurrentCamera.main); } if (mouseCheck[0] == 1) { if (UIHits.Count > 0) { MenuPositioner dragHandle; foreach (RaycastResult UIhit in UIHits) { dragHandle = UIhit.gameObject.GetComponent <MenuPositioner>(); if (dragHandle != null) { dragHandle.StartDrag(); dragging = true; } } } } //Check left mouse button up; if (mouseCheck[0] == -1) { dragging = false; Ray ray; if (currentCamera == CurrentCamera.main) { ray = gameCam.ScreenPointToRay(Input.mousePosition); } else { ray = overHeadCam.ScreenPointToRay(Input.mousePosition); } RaycastHit hit; if (UIHits.Count > 0) { TriButton hitButton; ButtonClick clickButton; foreach (RaycastResult UIhit in UIHits) { hitButton = UIhit.gameObject.GetComponent <TriButton>(); clickButton = UIhit.gameObject.GetComponent <ButtonClick>(); if (hitButton != null) { string buttonValue = hitButton.getValue().ToLower(); TowerTypes towerType = TowerTypes.none; AugmentTypes augmentType = AugmentTypes.none; BuildingType buildingType = BuildingType.none; buttonValue = buttonValue.Replace("_button", ""); if (buttonValue.Contains("build_")) { buttonValue = buttonValue.Replace("build_", ""); if (buttonValue.Contains("_tower")) { buttonValue = buttonValue.Replace("_tower", ""); towerType = TowerBase.GetTowerType(buttonValue); } else if (buttonValue.Contains("_augment")) { buttonValue = buttonValue.Replace("_augment", ""); augmentType = Towers.GetAugmentType(buttonValue); } } MobSpawner spawner; switch (buttonValue) { case "path": PathKeeper.indexes[PathType.normal]++; PathKeeper.pathKeeper.FindGoal(PathType.normal, TerrainGen.GetGridPosition2D(PathKeeper.goal), TerrainGen.GetGridPosition2D(hexHook.transform.position)); break; case "select": TerrainGen.mapGenState = MapGen.pathing; buildingType = BuildingType.Base; break; case "regen": TerrainGen.instance.KillTerrain(); TerrainGen.mapGenState = MapGen.terrain; break; case "towers": triMenu.DestroyMenu(); triMenu.CreateMenu("towers_build"); break; case "augments": triMenu.DestroyMenu(); triMenu.CreateMenu("augments"); break; case "buildings": triMenu.DestroyMenu(); triMenu.CreateMenu("buildings"); break; case "sell": if (selectedBuilding != null) { float value = selectedBuilding.Sell(); value *= 0.8f; player.GiveGold((int)value); TowerBase.UpdateTowerHexes(); triMenu.DestroyMenu(); hexHook.SetActive(false); HexHighlighter.ResetGrid(); } break; case "upgrade": if (selectedBuilding != null) { if (player.hasGold(100)) { player.TakeGold(100); selectedBuilding.AddValue(100); selectedBuilding.GetComponent <TowerBase>().LevelUp(); triMenu.CreateDetails(); triMenu.LoadDetails(selectedBuilding.GetComponent <TowerBase>().GetDetails()); triMenu.RefreshDetails(); } } break; case "points": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.wavePoints *= 1.1f; CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "more": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.spawnNumber += 1; CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "less": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.spawnNumber -= 1; if (spawner.spawnNumber < 0) { spawner.spawnNumber = 0; } CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "faster": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.coolDownTime -= 1; if (spawner.coolDownTime < 1) { spawner.coolDownTime = 1; } CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "slower": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.coolDownTime += 1; CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "wall": buildingType = BuildingType.Wall; break; default: break; } int cost = Towers.instance.GetCost(buttonValue.Replace("build_", "").Replace("_button", "")); if (towerType != TowerTypes.none) { if (player.hasGold(cost)) { TowerBase towerBase = Instantiate(towerFabBasic, hexHook.transform.position, new Quaternion(), towerParent.transform) .GetComponent <TowerBase>(); player.TakeGold(cost); towerBase.SetProjectileParent(projectileParent); string tower = buttonValue.Replace("build_", "").Replace("_button", ""); towerBase.SetTower(TowerBase.GetTowerType(tower)); towerBase.UpdateLinks(); UpdateGrid(); CloseMenu(); // // // } } if (augmentType != AugmentTypes.none) { if (player.hasGold(cost)) { AugmentBase augmentBase = Instantiate(augmentFabBasic, hexHook.transform.position, new Quaternion(), towerParent.transform) .GetComponent <AugmentBase>(); player.TakeGold(cost); augmentBase.SetAugmentType(buttonValue); augmentBase.AddValue(cost); UpdateGrid(); CloseMenu(); } } if (buildingType != BuildingType.none) { if (player.hasGold(cost)) { if (buttonValue == "select") { buttonValue = "base"; } BuildingBase buildingBase = Instantiate(buildingFabBasic, hexHook.transform.position, new Quaternion(), towerParent.transform) .GetComponent <BuildingBase>(); buildingBase.SetBuilding(buttonValue); player.TakeGold(cost); UpdateGrid(hexHook.transform.position); CloseMenu(); } } } if (clickButton != null) { switch (clickButton.buttonClick) { case "pathing": if (HexHighlighter.showingType != GridType.path) { PathKeeper.ShowOnGrid(PathType.normal); HexHighlighter.showingType = GridType.path; } else { HexHighlighter.ResetGrid(); HexHighlighter.showingType = GridType.grid; } break; case "height": if (HexHighlighter.showingType != GridType.height) { HexHighlighter.ShowHeightMap(); HexHighlighter.showingType = GridType.height; } else { HexHighlighter.ResetGrid(); HexHighlighter.showingType = GridType.grid; } break; case "towerrange": if (HexHighlighter.showingType != GridType.range) { HexHighlighter.ResetGrid(); HexHighlighter.ShowTowersRange(true); HexHighlighter.showingType = GridType.range; } else { HexHighlighter.ResetGrid(); HexHighlighter.showingType = GridType.grid; } break; case "undock_details": triMenu.DockDetails(); break; } } } } else if (Physics.Raycast(ray, out hit, 10, UIMask)) { Debug.Log("Other Ui hits>"); LinkToggle hitToggle; hitToggle = hit.transform.parent.GetComponent <LinkToggle>(); if (hitToggle != null) { hitToggle.Toggle(); UpdateLinks(); showingRange = true; } } else { triMenu.DestroyMenu(); //Ray ray = gameCam.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction, Color.blue, 1); if (Physics.Raycast(ray, out hit)) { hexHook.SetActive(true); if (hit.transform.position != Vector3.zero) { PlaceHexHook(hit.transform.position); } else { PlaceHexHook(hit.point); } } BuildingBase buildingBase = null; if (hit.collider != null) { buildingBase = hit.transform.parent.GetComponent <BuildingBase>(); if (buildingBase != null) { triMenu.DestroyMenu(); Vector2 detailPos = GetScreenPosition(hexHook.transform.position); detailPos.x -= 120; triMenu.CreateMenu("towerselect"); triMenu.CreateDetails(detailPos); triMenu.LoadDetails(buildingBase.GetDetails()); triMenu.AddDetail("Upgrade Cost:", 100); triMenu.RefreshDetails(); selectedBuilding = buildingBase; selectedBuilding.UpdateLinks(); UpdateLinks(); //triMenu.DestroyButtons(); if (!showingRange && buildingBase is TowerBase towerBase) { towerBase.ShowHexes(); } } } Vector2 menuPos = GetScreenPosition(hexHook.transform.position); menuPos.x += 60; triMenu.transform.position = menuPos; // if (buildingBase == null) { selectedBuilding = null; HexHighlighter.ResetGrid(); hexHook.GetComponentInChildren <MeshRenderer>(true).gameObject.SetActive(false); MobSpawner spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (TerrainGen.mapGenState == MapGen.terrainCon) { triMenu.CreateMenu("startmenu"); } else if (spawner == null) { triMenu.CreateMenu("base"); } else { CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } } else { hexHook.GetComponentInChildren <MeshRenderer>(true).gameObject.SetActive(true); } } mouseCheck[0] = 0; } if (mouseCheck[1] == -1) { if (!overButton) { if (rightClickTime <= 0.33f) { triMenu.DestroyMenu(); selectedBuilding = null; selectedSpawner = null; hexHook.SetActive(false); mouseCheck[1] = 0; lastButtonHover = null; HexHighlighter.ResetGrid(); showingRange = false; } } else if (overButton && !didBack) { if (triMenu.CurrentMenu() != "startmenu") { didBack = true; triMenu.DestroyMenu(); triMenu.CreateMenu("base"); } } } bool inX = !dragging && !overButton && Input.mousePosition.x > 0 - overBorder && Input.mousePosition.x < Screen.width + overBorder; bool inside = inX && Input.mousePosition.y > 0 - overBorder && Input.mousePosition.y < Screen.height + overBorder; if (inside) { MoveCamera(); } if (mouseCheck[1] == 1) { RotateCamera(); } if (triMenu.HaveLinks()) { triMenu.ReDrawLinks(); } }