public void DestroyUnit() { Tile.unitGameObject = null; Tile = null; GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>().CurrentLevel.Players[(index)].RemoveUnit(UnitGame); Destroy(gameObject); }
private void Awake() { UnitGame = GameJsonCreator.CreateUnit(this, isHero, type); GameObject selectionBox = null; if (index == PlayerIndex.Red) { selectionBox = (GameObject)Instantiate(Resources.Load <GameObject>("Prefabs/Misc/SelectionRed")); } else if (index == PlayerIndex.Blue) { selectionBox = (GameObject)Instantiate(Resources.Load <GameObject>("Prefabs/Misc/SelectionBlue")); } selectionBox.transform.position = transform.position; selectionBox.transform.parent = transform; SelectionBox = selectionBox.GetComponent <SpriteRenderer>(); if (transform.parent != null) { Tile = transform.parent.GetComponent <Tile>(); Tile.unitGameObject = this; } UnitHealthText = transform.FindChild("UnitHealth").gameObject; // Set the sorting layer to GUI. The same used for the hightlights. Eventhough you cannot set it via unity inspector you can still set it via code. :D UnitHealthText.renderer.sortingLayerName = "GUI"; var levelManager = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); if (levelManager.IsCurrentLevelLoaded()) { levelManager.CurrentLevel.Players[index].AddUnit(UnitGame); } }
private void Start() { levelManager = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); highlight = GameObjectReferences.GetScriptsGameObject().GetComponent <Highlight>(); attack = GameObjectReferences.GetScriptsGameObject().GetComponent <Attack>(); dayStateControl = GameObjectReferences.GetScriptsGameObject().GetComponent <DayStateController>(); }
/// <summary> /// Calculate the min and max x en y values of the game. These values are used to determine the values the camera position on the x and y position can go to. /// It takes into account the camera size and the maximum boundaries of the tiles in the level. /// </summary> private void CalculateLevelArea() { lastScreenWidth = Screen.width; lastScreenHeight = Screen.height; LevelManager lm = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); Dictionary <int, Tile> qq = lm.CurrentLevel.Tiles[lm.CurrentLevel.Tiles.Count]; Tile first = lm.CurrentLevel.Tiles[1][1]; Tile last = qq[qq.Count]; Vector3 firstTilePosition = first.transform.position; Vector3 lastTilePosition = last.transform.position; Camera c = Camera.main; Vector3 UpperLeft = c.ViewportToWorldPoint(new Vector3(0.0f, 1.0f, 0.0f)); Vector3 LowerRight = c.ViewportToWorldPoint(new Vector3(1.0f, 0.0f, 0.0f)); float viewportWidth = LowerRight.x - UpperLeft.x; float viewportHeight = LowerRight.y - UpperLeft.y; minX = (firstTilePosition.x + viewportWidth / 2.0f) - 1; maxX = (lastTilePosition.x - viewportWidth / 2.0f) + 1; minY = (first.transform.parent.transform.position.y + viewportHeight / 2.0f) + 1; maxY = (last.transform.parent.transform.position.y - viewportHeight / 2.0f) - 1; }
private void Start() { lm = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); lightFront = GameObject.Find("LightFront").GetComponent <Light>(); lightBack = GameObject.Find("LightBack").GetComponent <Light>(); IsFowActive = lastIsFowActive = false; CurrentDayState = DayStates.Morning; // Start a fade into the CurrentDayState. This is done because the intensity of the light prefab may differ from the values set below. StartTime = Time.time; tiles = new List <Fading>(); }
private void LoadLevel(string name) { GameObject.Find("Level").GetComponents <AudioSource>()[0].Play(); foreach (LevelsEnum level in (LevelsEnum[])Enum.GetValues(typeof(LevelsEnum))) { if (level.ToString() == name) { GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>().LoadLevel(level); break; } } }
private void Awake() { levelManager = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); movement = GameObjectReferences.GetScriptsGameObject().GetComponent <Movement>(); movement = GameObjectReferences.GetScriptsGameObject().GetComponent <Movement>(); attack = GameObjectReferences.GetScriptsGameObject().GetComponent <Attack>(); animInfo = GameObjectReferences.GetScriptsGameObject().GetComponent <AnimationInfo>(); IsHighlightOn = false; HighlightObjects = new List <HighlightObject>(); EventHandler.register <OnUnitClick>(ShowHighlight); EventHandler.register <OnHighlightClick>(ClickedOnHightLight); }
public void DestroyBuilding() { Tile.buildingGameObject = null; Tile = null; var levelmanager = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); levelmanager.CurrentLevel.Players[index].RemoveBuilding(BuildingGame); var capBuilding = GameObjectReferences.GetScriptsGameObject().GetComponent <CaptureBuildings>(); if (capBuilding.BuildingsBeingCaptured.Contains(BuildingGame)) { capBuilding.BuildingsBeingCaptured.Remove(BuildingGame); } Destroy(gameObject); }
public void TurnIncrease() { dayTurnCounter++; LevelManager lm = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); int turnsNeeded = lm.CurrentLevel.dayNightTurns[CurrentDayState]; bool ended = dayTurnCounter > turnsNeeded; if (ended) { int newNumber = (int)CurrentDayState + 1; int highest = 0; foreach (DayStates day in (DayStates[])Enum.GetValues(typeof(DayStates))) { int n = (int)day; if (n > highest) { highest = n; } if (newNumber > highest) { CurrentDayState = DayStates.Morning; dayTurnCounter = 1; } else if (n == newNumber) { CurrentDayState = day; dayTurnCounter = 1; } } StartTime = Time.time; Notificator.Notify(CurrentDayState.ToString() + " has arrived", 1.5f); } else { int turnsRemaining = (turnsNeeded - dayTurnCounter) + 1; Notificator.Notify(turnsRemaining + " turns remaining before new daystate!", 1.1f); } SetFowOfWar(); }
private void Awake() { BuildingGame = GameJsonCreator.CreateBuilding(this, type); if (transform.parent != null) { Tile = transform.parent.GetComponent <Tile>(); Tile.buildingGameObject = this; } CapturePointsText = transform.FindChild("CapturePoints").gameObject; CapturePointsText.renderer.enabled = false; // Set the sorting layer to GUI. The same used for the hightlights. Eventough you cannot set it via unity inspector you can still set it via code. :D CapturePointsText.renderer.sortingLayerName = "GUI"; var levelManager = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); if (levelManager.IsCurrentLevelLoaded()) { levelManager.CurrentLevel.Players[index].AddBuilding(BuildingGame); } }
/// <summary> /// Load the level that is set in the LevelManager script. /// </summary> private void LoadLevel() { var lm = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); LevelsEnum level = lm.levelToLoad; if (level == LevelsEnum.Menu) { lm.CurrentLevel = new Level(level); Application.LoadLevel(level.ToString()); } else { string jsonString = ResourceCache.GetResource <TextAsset>(level.ToString()).text; JSONNode jsonLevel = JSON.Parse(jsonString); int morning = Mathf.Clamp(jsonLevel["turn-morning"].AsInt, 1, int.MaxValue); int midday = Mathf.Clamp(jsonLevel["turn-midday"].AsInt, 1, int.MaxValue); int evening = Mathf.Clamp(jsonLevel["turn-evening"].AsInt, 1, int.MaxValue); int night = Mathf.Clamp(jsonLevel["turn-night"].AsInt, 1, int.MaxValue); string name = jsonLevel["level-name"]; string description = jsonLevel["level-description"]; JSONArray gold = jsonLevel["starting-gold"].AsArray; var startGold = new Dictionary <PlayerIndex, int>(); foreach (PlayerIndex pl in (PlayerIndex[])Enum.GetValues(typeof(PlayerIndex))) { foreach (JSONNode item in gold) { if (!String.IsNullOrEmpty(item[pl.ToString()]) && item[pl.ToString()] != pl.ToString()) { startGold.Add(pl, item[pl.ToString()].AsInt); } } } lm.CurrentLevel = new Level(true, morning, midday, evening, night, name, description, startGold, level); Application.LoadLevel(level.ToString()); } }
private void Start() { levelManager = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); }
/// <summary> /// This method is called by the GameManager within the NextPlayer method. It will calculate all of the capturing stuff. /// </summary> public void CalculateCapturing() { int count = BuildingsBeingCaptured.Count; for (int i = 0; i < count; i++) { Building building = BuildingsBeingCaptured[i]; if (building.BuildingGameObject.Tile.HasUnit()) { UnitGameObject unitOnBuilding = building.BuildingGameObject.Tile.unitGameObject; float health = unitOnBuilding.UnitGame.CurrentHealth; building.IncreaseCapturePointsBy(health); unitOnBuilding.UnitGame.DecreaseHealth(building.DamageToCapturingUnit); if (!unitOnBuilding.UnitGame.IsAlive()) { unitOnBuilding.UnitGame.OnDeath(); } if (building.HasCaptured()) { if (building.BuildingGameObject.type != BuildingTypes.Headquarters) { BuildingTypes type = building.BuildingGameObject.type; BuildingsBeingCaptured.Remove(building); count--; i--; building.BuildingGameObject.DestroyBuilding(); CreatorFactoryBuilding.CreateBuilding(unitOnBuilding.Tile, unitOnBuilding.index, type); if (type == BuildingTypes.TrainingZone) { OnTrainingzoneCapturedHero(unitOnBuilding); } } else { LevelManager lm = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>(); Camera.main.backgroundColor = lm.CurrentLevel.Players[unitOnBuilding.index].PlayerColor; GameObject.FindGameObjectWithTag("Level").SetActive(false); GameObject.Find("_Scripts").GetComponent <GameBar>().enabled = false; GameObject.Find("_Scripts").GetComponent <Notificator>().enabled = false; GameObject.Find("NotificationText").GetComponent <TextMesh>().text = unitOnBuilding.index + " has won the game! \n\nPress anywhere to return to the menu."; lm.CurrentLevel.IsEnded = true; } } } else { building.DecreaseCapturePointsBy(building.CapturePointsDecreasedBy); if (building.CurrentCapturePoints <= 0f) { BuildingsBeingCaptured.Remove(building); count--; i--; } } } }