Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using System;
- using System.Xml;
- using System.Text;
- using System.IO;
- #if UNITY_ANDROID
- using UnityEngine.Advertisements;
- #endif
- public class GameController : MonoBehaviour {
- Touch touch;
- float TouchTime;
- //Tiles
- public LayerMask TileLayer;
- public GameObject TilePrefab;
- //public TileObject[] Tiles;
- public Tile SelectedTile;
- public int TilesActive = 0;
- public UIController UIController;
- public Ressources Ressources;
- public XMLManager XMLMannager;
- public Buildings Buildings;
- public RelativeAnimator RAnimator;
- public float Malus;
- public int SaveTimer;
- public int defaultSaveTimer;
- int Timer;
- public float AwayMoney;
- public bool OnMenu = false;
- [Header("AllTiles")]
- public List<TileObject> Tiles;
- public bool EmploisAdvert;
- public bool MarchAdvert;
- public bool TerrainValAdvert;
- //Var utils
- [Header("Variable")]
- public float Money;
- public float Population;
- public float TerrainVal;
- public float PopulationMax;
- public float PopulationAuto;
- public float SurplusElectrique;
- public float SurplusHydrolique;
- public float Pollution;
- public float Emplois;
- public float RisqueFeu;
- public float RisqueCrime;
- public float Marchandise;
- //Default var utils
- [Header("Variable valeur par défaut")]
- public float TilePrice;
- public float MoneyDefault;
- public float TerrainValDefault;
- public float PopulationDefault;
- public float PopulationMaxDefault;
- public float EmploisDefault;
- public float SurplusElectricDefault;
- public float SurplusHydrolicDefault;
- public float MarchandiseDefault;
- private bool upgrade;
- public float upgradePrice;
- public bool loading;
- // Use this for initialization
- void Start () {
- loading = false;
- upgrade = false;
- Tiles = new List<TileObject>();
- Tiles.Capacity = 99999;
- Buildings = this.gameObject.GetComponent<Buildings> ();
- GameObject TilesFolder = GameObject.Find ("Tiles");
- UIController = GameObject.Find ("Hud").GetComponent<UIController> ();
- XMLMannager = this.gameObject.GetComponent<XMLManager> ();
- Ressources = this.gameObject.GetComponent<Ressources> ();
- Ressources.Start ();
- XMLMannager.Start ();
- if (PlayerPrefs.HasKey ("Money") && XMLMannager.CheckDoc() == true) {
- LoadSave ();
- } else {
- XMLMannager.CreateSave ();
- GameObject obj = Instantiate (TilePrefab, Vector3.zero, Quaternion.identity, TilesFolder.transform) as GameObject;
- Money = MoneyDefault;
- TerrainVal = TerrainValDefault;
- Population = PopulationDefault;
- PopulationMax = PopulationMaxDefault;
- SaveTimer = defaultSaveTimer;
- Emplois = EmploisDefault;
- Marchandise = MarchandiseDefault;
- }
- if (PlayerPrefs.HasKey ("oT")) {
- StartCoroutine (AwayAutoTimer ());
- }
- Timer = 0;
- SaveTimer = 10;
- StartCoroutine (refresh ());
- }
- // Update is called once per frame
- void Update () {
- RaycastHit hit;
- Ray ray;
- Physics.Raycast (new Vector3(0,0,0),new Vector3(0,0,0), out hit);
- if (Input.touchCount > 0) {
- touch = Input.GetTouch (0);
- if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended) {
- TouchTime = Time.time;
- }
- }
- if (Input.touchCount > 0) {
- if (touch.phase == TouchPhase.Stationary) {
- if (Time.time - TouchTime >= 0.3f) {
- if (Input.GetTouch (0).position.y > (0.15 * Screen.height) && Input.GetTouch (0).position.y < (0.83 * Screen.height)) {
- if (OnMenu == false) {
- ray = Camera.main.ScreenPointToRay (Input.GetTouch (0).position);
- Physics.Raycast (ray, out hit);
- }
- }
- }
- }
- }
- if (Application.isMobilePlatform == false && Input.touchCount <= 0) {
- if (Input.GetMouseButton (0) || Input.GetMouseButton (1) || Input.GetMouseButton (2)) {
- if (Input.mousePosition.y > (0.15 * Screen.height) && Input.mousePosition.y < (0.83 * Screen.height)) {
- if (OnMenu == false) {
- ray = Camera.main.ScreenPointToRay (Input.mousePosition);
- Physics.Raycast (ray, out hit);
- }
- }
- }
- }
- if (hit.transform != null && hit.transform.tag == "Tile") {
- GameObject obj = hit.transform.gameObject;
- if (obj.tag == "Tile" && OnMenu != true) {
- if (obj.transform != null)
- if (obj.GetComponent<Tile> () != null) {
- obj.GetComponent<Tile> ().Select ();
- }
- }
- }
- if (Input.GetKeyDown (KeyCode.LeftControl) && Input.GetKeyDown (KeyCode.S)) {
- Save ();
- }
- }
- public void LoadSave(){
- if (PlayerPrefs.HasKey ("Money")) {
- Money = PlayerPrefs.GetFloat ("Money");
- XMLMannager.TileLoad ();
- }
- if (PlayerPrefs.HasKey ("TerrainVal"))
- TerrainVal = PlayerPrefs.GetFloat ("TerrainVal");
- if (PlayerPrefs.HasKey ("Population"))
- Population = PlayerPrefs.GetFloat ("Population");
- if (PlayerPrefs.HasKey ("PopulationMax"))
- PopulationMax = PlayerPrefs.GetFloat ("PopulationMax");
- if (PlayerPrefs.HasKey ("TilesActive"))
- TilesActive = PlayerPrefs.GetInt ("TilesActive");
- if (PlayerPrefs.HasKey ("SaveTimer"))
- SaveTimer = PlayerPrefs.GetInt ("SaveTimer");
- }
- public IEnumerator refresh() {
- yield return new WaitForSeconds (1);
- Malus = 1;
- if (Population < PopulationMax) {
- Population = Population + PopulationAuto;
- }
- if (Emplois <= 0 && Emplois > -(0.05f * PopulationMax)) {
- if (EmploisAdvert == false) {
- UIController.KnobInfoDisplay ("Il n'y a plus d'emploi disponible, vous devez créer de nouvelles entreprise comme des commerces, ou des services publiques.");
- EmploisAdvert = true;
- }
- } else if (Emplois <= -(0.05f * PopulationMax)) {
- UIController.KnobAlertDisplay ("Il n'y a plus d'emploi disponible, vous devez créer de nouvelles entreprise comme des commerces, ou des services publiques.");
- StartCoroutine (UIController.LittleAlertDisplay ("Crise du chômage !!", Color.red));
- Malus = 0.5f;
- } else {
- EmploisAdvert = false;
- }
- if (Marchandise < 0 && Marchandise > -(0.03f * PopulationMax + MarchandiseDefault)) {
- UIController.KnobInfoDisplay ("Les commerçants n'ont plus de marchandise à vendre, vous devez créer des industries.");
- } else if (Marchandise <= -(0.03f * PopulationMax + MarchandiseDefault)) {
- UIController.KnobAlertDisplay ("Les commerçants n'ont plus de marchandise à vendre, vous devez créer des industries.");
- StartCoroutine (UIController.LittleAlertDisplay ("Crise de marchandise !!", Color.red));
- Malus = 0.5f;
- }
- if (Marchandise < (1f * PopulationMax) && Marchandise > (1.25f * PopulationMax + MarchandiseDefault)) {
- UIController.KnobInfoDisplay ("Les commerçants n'arrive pas a écoulé toute les marchandises. Construisez plus de commerces");
- } else if (Marchandise >= (1.5f * PopulationMax + MarchandiseDefault)) {
- UIController.KnobAlertDisplay ("Les commerçants n'arrive pas a écoulé toute les marchandises. Construisez plus de commerces");
- StartCoroutine (UIController.LittleAlertDisplay ("Surplus de marchandise !!", Color.red));
- Malus = 0.5f;
- }
- if (SurplusElectrique < 0 && SurplusElectrique > - 100) {
- UIController.KnobInfoDisplay ("Vos habitants subissent des coupures électrique. Vous devez améliorer votre réseau électrique");
- } else if (SurplusElectrique <= -100) {
- UIController.KnobAlertDisplay ("Vos habitants subissent des coupures électrique. Vous devez améliorer votre réseau électrique");
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'éléctricité!!", Color.red));
- Malus = 0.5f;
- }
- if (SurplusHydrolique < 0 && SurplusHydrolique > - 100) {
- UIController.KnobInfoDisplay ("Vos habitants subissent des coupures d'eau. Vous devez améliorer votre réseau hydrolique");
- } else if (SurplusHydrolique <= -100) {
- UIController.KnobAlertDisplay ("Vos habitants subissent des coupures d'eau. Vous devez améliorer votre réseau hydrolique");
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'eau!!", Color.red));
- Malus = 0.5f;
- }
- int randomEvent = UnityEngine.Random.Range (0, 75000);
- if (randomEvent <= Pollution) {
- float popLost = UnityEngine.Random.Range (0, 0.4f * (float)(Population));
- popLost = (float)Mathf.RoundToInt (popLost);
- Population = Population - popLost;
- string sMaladie = "La pollution a rendu malade et a tué " + UIController.Suffixer(popLost) + " habitants. Vous devez créer des espaces verts";
- UIController.KnobAlertDisplay (sMaladie);
- }else if (randomEvent <= RisqueCrime) {
- float moneyLost = UnityEngine.Random.Range (0, 0.5f * (float)(Money));
- moneyLost = (float)Mathf.RoundToInt (moneyLost);
- float popLost = UnityEngine.Random.Range (0, 0.2f * (float)(Population));
- popLost = (float)Mathf.RoundToInt (popLost);
- Money = Money - moneyLost;
- Population = Population - popLost;
- string sCrime = "Un crime a eu lieu dans votre ville, vous avez perdu " + UIController.Suffixer(moneyLost) + " dollars et " + UIController.Suffixer(popLost) + " habitants. Construisez des commissariat.";
- UIController.KnobAlertDisplay (sCrime);
- }else if (randomEvent <= RisqueFeu) {
- TileObject BurnTile = Tiles [UnityEngine.Random.Range (0, Tiles.Count)];
- while (BurnTile.statut != "Build") {
- BurnTile = Tiles [UnityEngine.Random.Range (0, Tiles.Count)];
- }
- SelectedTile = GameObject.Find(BurnTile.name).GetComponent<Tile>();
- Destroy (SelectedTile.transform.GetChild (0).gameObject);
- BuildInterface ("Ruines");
- string sBat = "Votre " + BurnTile.builded.Name + " a pris feu et il ne reste que des cendres, pensez à construire des casernes de pompier.";
- UIController.KnobAlertDisplay (sBat);
- }
- Money = Money + Population * (TerrainVal * Malus);;
- UIController.UpdateUi ();
- //TEMP
- if (Timer == SaveTimer) {
- Save ();
- Timer = 0;
- }
- Timer++;
- StartCoroutine (refresh ());
- }
- public void AddPeople(){
- if (Population +1 <= PopulationMax)
- Population++;
- }
- public void SelectTile(Tile tile){
- SelectedTile = tile;
- }
- public void TileAction(string action){
- if (action == "Expand") {
- if (Money >= TilePrice * ((TilesActive * 3f * TilesActive) + 1)) {
- SelectedTile.Expand ();
- Money = Money - TilePrice * ((TilesActive * 3f * TilesActive) + 1);
- UIController.CloseMenu ();
- TilesActive++;
- } else {
- StartCoroutine (UIController.LittleAlertDisplay ("Argent insuffisant", Color.red));
- }
- } else if (action == "Upgrade") {
- if (SelectedTile.Builded.nextIsEcological == true) {
- if (tryUpgrade (2) == true) {
- BuildingObject UpgradeObj = null;
- if (SelectedTile.Type == "Residentiel") {
- UpgradeObj = Buildings.Residentiels [SelectedTile.Builded.PosInList + 2];
- } else if (SelectedTile.Type == "Commercial") {
- UpgradeObj = Buildings.Commercials [SelectedTile.Builded.PosInList + 2];
- } else if (SelectedTile.Type == "Industriel") {
- UpgradeObj = Buildings.Industriels [SelectedTile.Builded.PosInList + 2];
- } else if (SelectedTile.Type == "Medical") {
- UpgradeObj = Buildings.Healths [SelectedTile.Builded.PosInList + 2];
- } else if (SelectedTile.Type == "Parcs") {
- UpgradeObj = Buildings.Parks [SelectedTile.Builded.PosInList + 2];
- } else if (SelectedTile.Type == "Education") {
- UpgradeObj = Buildings.Schools [SelectedTile.Builded.PosInList + 2];
- } else if (SelectedTile.Type == "Police") {
- UpgradeObj = Buildings.Polices [SelectedTile.Builded.PosInList + 2];
- } else if (SelectedTile.Type == "Pompier") {
- UpgradeObj = Buildings.Pompiers [SelectedTile.Builded.PosInList + 2];
- }
- upgrade = true;
- Build (UpgradeObj);
- }
- } else {
- if (tryUpgrade (1) == true) {
- BuildingObject UpgradeObj = null;
- if (SelectedTile.Type == "Residentiel") {
- UpgradeObj = Buildings.Residentiels [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Commercial") {
- UpgradeObj = Buildings.Commercials [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Industriel") {
- UpgradeObj = Buildings.Industriels [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Medical") {
- UpgradeObj = Buildings.Healths [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Parcs") {
- UpgradeObj = Buildings.Parks [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Education") {
- UpgradeObj = Buildings.Schools [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Police") {
- UpgradeObj = Buildings.Polices [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Pompier") {
- UpgradeObj = Buildings.Pompiers [SelectedTile.Builded.PosInList + 1];
- }
- upgrade = true;
- Build (UpgradeObj);
- }
- }
- } else if (action == "UpgradeEco") {
- if (tryUpgrade (1) == true) {
- BuildingObject UpgradeObj = null;
- if (SelectedTile.Type == "Residentiel") {
- UpgradeObj = Buildings.Residentiels [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Commercial") {
- UpgradeObj = Buildings.Commercials [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Industriel") {
- UpgradeObj = Buildings.Industriels [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Medical") {
- UpgradeObj = Buildings.Healths [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Parcs") {
- UpgradeObj = Buildings.Parks [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Education") {
- UpgradeObj = Buildings.Schools [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Police") {
- UpgradeObj = Buildings.Polices [SelectedTile.Builded.PosInList + 1];
- } else if (SelectedTile.Type == "Pompier") {
- UpgradeObj = Buildings.Pompiers [SelectedTile.Builded.PosInList + 1];
- }
- upgrade = true;
- Build (UpgradeObj);
- }
- }
- }
- public bool tryUpgrade(int indice){
- upgradePrice = 0;
- if (SelectedTile.Type == "Residentiel") {
- if (Buildings.Residentiels.Count - 1 >= SelectedTile.Builded.PosInList + indice) {
- BuildingObject UpgradeObj = Buildings.Residentiels [SelectedTile.Builded.PosInList + indice];
- //if (Money >= UpgradeObj.Price - SelectedTile.Builded.Price) {
- if (Money >= UpgradeObj.Price/2) {
- //upgradePrice = UpgradeObj.Price - SelectedTile.Builded.Price;
- upgradePrice = UpgradeObj.Price/2;
- return true;
- } else {
- upgradePrice = UpgradeObj.Price/2;
- return false;
- StartCoroutine (UIController.LittleAlertDisplay ("Argent insuffisant", Color.red));
- }
- } else {
- return false;
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'amélioration disponible", Color.yellow));
- }
- }else if(SelectedTile.Type == "Commercial"){
- if (Buildings.Commercials.Count - 1 >= SelectedTile.Builded.PosInList + indice) {
- BuildingObject UpgradeObj = Buildings.Commercials [SelectedTile.Builded.PosInList + indice];
- if (Money >= UpgradeObj.Price - SelectedTile.Builded.Price) {
- upgradePrice = UpgradeObj.Price - SelectedTile.Builded.Price;
- return true;
- } else {
- upgradePrice = UpgradeObj.Price/2;
- return false;
- StartCoroutine (UIController.LittleAlertDisplay ("Argent insuffisant", Color.red));
- }
- } else {
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'amélioration disponible", Color.yellow));
- return false;
- }
- }else if(SelectedTile.Type == "Industriel"){
- if (Buildings.Industriels.Count - 1 >= SelectedTile.Builded.PosInList + indice) {
- BuildingObject UpgradeObj = Buildings.Industriels [SelectedTile.Builded.PosInList + indice];
- if (Money >= UpgradeObj.Price - SelectedTile.Builded.Price) {
- upgradePrice = UpgradeObj.Price - SelectedTile.Builded.Price;
- return true;
- } else {
- upgradePrice = UpgradeObj.Price/2;
- return false;
- StartCoroutine (UIController.LittleAlertDisplay ("Argent insuffisant", Color.red));
- }
- } else {
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'amélioration disponible", Color.yellow));
- return false;
- }
- }else if(SelectedTile.Type == "Medical"){
- if (Buildings.Healths.Count - 1 >= SelectedTile.Builded.PosInList + indice) {
- BuildingObject UpgradeObj = Buildings.Healths [SelectedTile.Builded.PosInList + indice];
- if (Money >= UpgradeObj.Price - SelectedTile.Builded.Price) {
- upgradePrice = UpgradeObj.Price - SelectedTile.Builded.Price;
- return true;
- } else {
- upgradePrice = UpgradeObj.Price/2;
- StartCoroutine (UIController.LittleAlertDisplay ("Argent insuffisant", Color.red));
- return false;
- }
- } else {
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'amélioration disponible", Color.yellow));
- return false;
- }
- }else if(SelectedTile.Type == "Education"){
- if (Buildings.Schools.Count - 1 >= SelectedTile.Builded.PosInList + indice) {
- BuildingObject UpgradeObj = Buildings.Schools [SelectedTile.Builded.PosInList + indice];
- if (Money >= UpgradeObj.Price - SelectedTile.Builded.Price) {
- upgradePrice = UpgradeObj.Price - SelectedTile.Builded.Price;
- return true;
- } else {
- upgradePrice = UpgradeObj.Price/2;
- StartCoroutine (UIController.LittleAlertDisplay ("Argent insuffisant", Color.red));
- return false;
- }
- } else {
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'amélioration disponible", Color.yellow));
- return false;
- }
- }else if(SelectedTile.Type == "Police"){
- if (Buildings.Polices.Count - 1 >= SelectedTile.Builded.PosInList + indice) {
- BuildingObject UpgradeObj = Buildings.Polices [SelectedTile.Builded.PosInList + indice];
- if (Money >= UpgradeObj.Price - SelectedTile.Builded.Price) {
- upgradePrice = UpgradeObj.Price - SelectedTile.Builded.Price;
- return true;
- } else {
- upgradePrice = UpgradeObj.Price/2;
- StartCoroutine (UIController.LittleAlertDisplay ("Argent insuffisant", Color.red));
- return false;
- }
- } else {
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'amélioration disponible", Color.yellow));
- return false;
- }
- }else if(SelectedTile.Type == "Pompier"){
- if (Buildings.Pompiers.Count - 1 >= SelectedTile.Builded.PosInList + indice) {
- BuildingObject UpgradeObj = Buildings.Pompiers [SelectedTile.Builded.PosInList + indice];
- if (Money >= UpgradeObj.Price - SelectedTile.Builded.Price) {
- upgradePrice = UpgradeObj.Price - SelectedTile.Builded.Price;
- return true;
- } else {
- upgradePrice = UpgradeObj.Price/2;
- StartCoroutine (UIController.LittleAlertDisplay ("Argent insuffisant", Color.red));
- return false;
- }
- } else {
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'amélioration disponible", Color.yellow));
- return false;
- }
- }else {
- StartCoroutine (UIController.LittleAlertDisplay ("Pas d'amélioration disponible", Color.yellow));
- return false;
- }
- }
- public void Save(){
- XMLMannager.Save ();
- PlayerPrefs.SetFloat ("Money", Money);
- PlayerPrefs.SetFloat ("TerrainVal", TerrainVal);
- PlayerPrefs.SetFloat ("Population", Population);
- PlayerPrefs.SetInt ("TilesActive", TilesActive);
- PlayerPrefs.SetInt ("SaveTimer", SaveTimer);
- PlayerPrefs.SetString ("Electrique", Ressources.ElecActual.name);
- PlayerPrefs.SetString ("Hydrolique", Ressources.HydroActual.name);
- PlayerPrefs.Save ();
- UIController.LittleAlertDisplay ("Partie sauvegardé", Color.black);
- }
- public void BuildInterface(string BuildingName){
- Buildings = this.gameObject.GetComponent<Buildings> ();
- Buildings.Start ();
- if (BuildingName == "Cabane") {
- Build (Buildings.Cabane);
- } else if (BuildingName == "Maisonette") {
- Build (Buildings.Maisonette);
- } else if (BuildingName == "PetiteClinique") {
- Build (Buildings.PetiteClinique);
- } else if (BuildingName == "Ferme") {
- Build (Buildings.Ferme);
- } else if (BuildingName == "Epicerie") {
- Build (Buildings.Epicerie);
- } else if (BuildingName == "Pavillon") {
- Build (Buildings.Pavillon);
- } else if (BuildingName == "Marché") {
- Build (Buildings.Marché);
- } else if (BuildingName == "Duplex") {
- Build (Buildings.Duplex);
- } else if (BuildingName == "Mine") {
- Build (Buildings.Mine);
- } else if (BuildingName == "PetitParc") {
- Build (Buildings.PetitParc);
- } else if (BuildingName == "Clinique") {
- Build (Buildings.Clinique);
- } else if (BuildingName == "Quartier") {
- Build (Buildings.Quartier);
- } else if (BuildingName == "Supérette") {
- Build (Buildings.Supérette);
- } else if (BuildingName == "Entrepot") {
- Build (Buildings.Entrepot);
- } else if (BuildingName == "Usine") {
- Build (Buildings.Usine);
- } else if (BuildingName == "Ruines") {
- Build (Buildings.Ruines);
- } else if (BuildingName == "EcolePrimaire") {
- Build (Buildings.EcolePrimaire);
- } else if (BuildingName == "PosteDePolice") {
- Build (Buildings.PosteDePolice);
- } else if (BuildingName == "PosteDePompier") {
- Build (Buildings.PosteDePompier);
- } else if (BuildingName == "PavillonEco") {
- Build (Buildings.PavillonEco);
- } else if (BuildingName == "College") {
- Build (Buildings.College);
- }
- }
- public void Build(BuildingObject BuildingObject){
- if (Money >= BuildingObject.Price || upgrade == true) {
- if (upgrade == false) {
- Money = Money - BuildingObject.Price;
- } else {
- Money = Money - upgradePrice;
- }
- upgrade = false;
- StartCoroutine(RAnimator.BuildTile (SelectedTile.gameObject));
- SelectedTile.TileBuild (BuildingObject);
- UIController.CloseMenu ();
- RefreshBuild ();
- } else if (loading == true) {
- SelectedTile.TileBuild (BuildingObject);
- RefreshBuild ();
- }else {
- StartCoroutine(UIController.LittleAlertDisplay("Argent insuffisant", Color.red));
- }
- }
- public void RefreshBuild(){
- PopulationMax = PopulationMaxDefault;
- PopulationAuto = 0;
- Emplois = EmploisDefault;
- SurplusElectrique = Ressources.ElecActual.ressourcesPower;
- SurplusHydrolique = Ressources.HydroActual.ressourcesPower;
- TerrainVal = TerrainValDefault;
- Marchandise = MarchandiseDefault;
- int i = 0;
- while (i != Tiles.Count) {
- BuildingObject BuildingObject = Tiles [i].builded;
- if (Tiles [i].builded != null) {
- PopulationMax = PopulationMax + BuildingObject.PopMax;
- PopulationAuto = PopulationAuto + BuildingObject.PopAuto;
- TerrainVal = TerrainVal + BuildingObject.TerrainVal;
- SurplusElectrique = SurplusElectrique + BuildingObject.Electric;
- SurplusHydrolique = SurplusHydrolique + BuildingObject.Hydrolic;
- Pollution = Pollution + BuildingObject.Pollution;
- Emplois = Emplois + BuildingObject.Emplois;
- RisqueFeu = RisqueFeu + BuildingObject.RisqueFeu;
- RisqueCrime = RisqueCrime + BuildingObject.RisqueCrime;
- Marchandise = Marchandise + BuildingObject.Marchandise;
- }
- i++;
- }
- }
- public void TileRemove(){
- Destroy (SelectedTile.transform.GetChild (0).gameObject);
- GameObject obj = Instantiate(SelectedTile.ActiveTilePrefab, SelectedTile.transform.position, Quaternion.identity, SelectedTile.transform) as GameObject;
- UIController.CloseMenu ();
- Money = Money + SelectedTile.Builded.Price;
- SelectedTile.Building = "Active";
- SelectedTile.Builded = null;
- SelectedTile.Statut = "Active";
- SelectedTile.Type = "None";
- RefreshBuild ();
- }
- DateTime currentTime;
- DateTime oldTime;
- TimeSpan timeAway;
- public float SecondesAway;
- public void OnApplicationPause(bool paused)
- {
- if(paused) // When Paused
- {
- oldTime = DateTime.Now;
- PlayerPrefs.SetInt("oT", (int)oldTime.Ticks);
- }
- else // When Focused
- {
- StartCoroutine (AwayAutoTimer ());
- }
- }
- public void AwayUpdate(){
- currentTime = DateTime.Now;
- oldTime.AddTicks( PlayerPrefs.GetInt("oT"));
- PlayerPrefs.DeleteKey ("oT");
- timeAway = currentTime.Subtract(oldTime);
- SecondesAway = (float)TimeSpan.FromTicks (timeAway.Ticks).TotalSeconds;
- if (SecondesAway >= 300) {
- if (SecondesAway >= 28800)
- SecondesAway = 28800;
- AwayMoney = SecondesAway * Population * TerrainVal * 0.05f;
- UIController.AwayMenu.SetActive (true);
- GameObject.Find ("AwayMoney").GetComponent<Text> ().text = UIController.Suffixer(AwayMoney);
- }
- }
- IEnumerator AwayAutoTimer(){
- yield return new WaitForSeconds (2.5f);
- AwayUpdate ();
- }
- #if UNITY_ANDROID
- public void AwayRecolt(bool ads){
- if (ads == true) {
- ShowRewardedAdRecolt ();
- } else {
- Money = Money + AwayMoney;
- }
- UIController.CloseMenu ();
- AwayMoney = 0;
- }
- public void ShowRewardedAdRecolt()
- {
- if (Advertisement.IsReady("rewardedVideo"))
- {
- var options = new ShowOptions { resultCallback = HandleShowResultRecolt };
- Advertisement.Show("rewardedVideo", options);
- }
- }
- private void HandleShowResultRecolt(ShowResult result)
- {
- switch (result)
- {
- case ShowResult.Finished:
- //Debug.Log("The ad was successfully shown.");
- Money = Money + (AwayMoney * 2);
- break;
- case ShowResult.Skipped:
- Debug.Log ("The ad was skipped before reaching the end.");
- UIController.LittleAlertDisplay ("Pub passé, pas de bonus", Color.red);
- break;
- case ShowResult.Failed:
- Debug.LogError("The ad failed to be shown.");
- UIController.LittleAlertDisplay ("Pas de pub revenez plus tard", Color.red);
- break;
- }
- }
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment