Exemplo n.º 1
0
		public void AutoDeployFaction(int factionID=-1){
			if(factionID==-1) factionID=deployingFactionID;
			
			bool setToInvisible=GameControl.EnableFogOfWar() & !factionList[factionID].isPlayerFaction;
			
			List<Unit> unitList=factionList[factionID].startingUnitList;
			List<Tile> tileList=GridManager.GetDeployableTileList(factionList[factionID].ID);
			
			for(int i=0; i<tileList.Count; i++){
				if(!tileList[i].walkable || tileList[i].unit!=null || tileList[i].obstacleT!=null){ 
					tileList.RemoveAt(i);		i-=1;
				}
			}
			
			int count=0;
			for(int i=0; i<unitList.Count; i++){
				if(tileList.Count==0) break;
				Unit unit=unitList[i];
				
				int rand=Random.Range(0, tileList.Count);
				Tile tile=tileList[rand];
				tileList.RemoveAt(rand);
				tile.unit=unit;
				unit.tile=tile;
				unit.transform.position=tile.GetPos();
				unit.transform.rotation = Quaternion.Euler(0, factionList[factionID].spawnDirection, 0);
				unit.gameObject.SetActive(true);
				
				deployedUnitList.Add(unit);
				
				if(setToInvisible && !tile.IsVisible()){
					unit.gameObject.layer=TBTK.GetLayerUnitInvisible();
					Utilities.SetLayerRecursively(unit.transform, TBTK.GetLayerUnitInvisible());
				}
				
				count+=1;
				
				unit.factionID=factionList[factionID].ID;
			}
			
			for(int i=0; i<count; i++) unitList.RemoveAt(0);
			
			TBTK.OnUnitDeployed(null);
		}