private void Awake() { lm = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); string sceneName = Application.loadedLevelName; if (Application.isEditor && !sceneName.Equals(LevelsEnum.Menu.ToString())) { if (lm.CurrentLevel == null) { foreach (LevelsEnum pl in (LevelsEnum[])Enum.GetValues(typeof(LevelsEnum))) { if (pl.ToString() == sceneName) { lm.LoadLevel(pl); break; } } } } movement = GameObject.Find("_Scripts").GetComponent <Movement>(); highlight = GameObject.Find("_Scripts").GetComponent <Highlight>(); capBuildings = GameObject.Find("_Scripts").GetComponent <CaptureBuildings>(); productionOverlay = GameObject.Find("_Scripts").GetComponent <ProductionOverlayMain>(); dayStateController = GameObject.Find("_Scripts").GetComponent <DayStateController>(); animInfo = GameObject.Find("_Scripts").GetComponent <Assets.Scripts.UnitActions.AnimationInfo>(); }
/// <summary> /// This methods updates all of the fog of war for the given player. Loops through all of the buildings and units in order to update the fog of war. /// </summary> /// <param Name="index"></param> /// <param Name="showFog"></param> private void CheckLineForAllObjects(PlayerIndex index, bool showFog) { if (IsFowActive) { Player player = lm.CurrentLevel.Players[index]; foreach (Unit item in player.OwnedUnits) { ShowOrHideFowWithinRange(item.UnitGameObject.Tile, item.FowLineOfSightRange, showFog); } foreach (Building item in player.OwnedBuildings) { ShowOrHideFowWithinRange(item.BuildingGameObject.Tile, item.FowLineOfSightRange, showFog); } } // Update all of the health / capturepoints from all of the other players. foreach ( Player players in lm.CurrentLevel.Players.Where(x => x.Value.Index != index && x.Value.Index != PlayerIndex.Neutral) .Select(x => x.Value)) { foreach (Unit unit in players.OwnedUnits) { unit.UnitGameObject.UpdateHealthText(); } } CaptureBuildings capBuilding = GameObject.Find("_Scripts").GetComponent <CaptureBuildings>(); foreach (Building building in capBuilding.BuildingsBeingCaptured) { building.BuildingGameObject.UpdateCapturePointsText(); } }
public void Moving(UnitGameObject unitMoving) { unitMoving.transform.position = Vector2.Lerp(unitMoving.Tile.Vector2, nodeList.Last().Tile.Vector2, GetTimePassed()); if (GetTimePassed() >= 1f) { // Show fow for the unit. dayStateControl.ShowFowWithinLineOfSight(unitMoving.index); // Remove the references from the old Tile. unitMoving.Tile.unitGameObject = null; unitMoving.Tile = null; // Remove the last Tile from the list. Tile newPosition = nodeList.Last().Tile; nodeList.Remove(nodeList.Last()); // Assign the references using the new Tile. newPosition.unitGameObject = unitMoving; unitMoving.Tile = newPosition; unitMoving.Tile.Vector2 = newPosition.Vector2; // Set the parent and position of the unit to the new Tile. unitMoving.transform.parent = newPosition.transform; unitMoving.transform.position = newPosition.transform.position; // Hide the fow for the unit. It will use the new Tile location. dayStateControl.HideFowWithinLineOfSight(unitMoving.index); StartTimeMoving = Time.time; } if (nodeList.Count <= 0) { highlight.ClearHighlights(); Tile endDestinationTile = unitMoving.Tile; if (endDestinationTile.HasLoot()) { endDestinationTile.Loot.PickUpLoot(levelManager.CurrentLevel.CurrentPlayer); } if (endDestinationTile.HasBuilding()) { CaptureBuildings capBuilding = GameObject.Find("_Scripts").GetComponent <CaptureBuildings>(); capBuilding.AddBuildingToCaptureList( endDestinationTile.buildingGameObject.BuildingGame); } if (unitMoving.UnitGame.CanAttackAfterMove && attack.ShowAttackHighlights(unitMoving, unitMoving.UnitGame.AttackRange) > 0) { unitMoving.UnitGame.HasMoved = true; } else { unitMoving.UnitGame.HasMoved = true; unitMoving.UnitGame.HasAttacked = true; } NeedsMoving = false; unitMoving.UnitGame.UpdateUnitColor(); } }