/* //place unit at a tile public static void PlaceUnitAt(Tile tile){ if(instance.startingUnit.Count==0) return; if(instance.startingUnit[instance.unitPlacementID]==null){ instance.startingUnit.RemoveAt(instance.unitPlacementID); if(instance.unitPlacementID>=instance.startingUnit.Count){ instance.unitPlacementID-=1; } return; } UnitTB unit=instance.startingUnit[instance.unitPlacementID]; unit.transform.position=tile.thisT.position; unit.occupiedTile=tile; tile.unit=unit; instance.startingUnit.RemoveAt(instance.unitPlacementID); instance.allUnits.Add(unit); GridManager.PlaceUnitAt(tile); if(instance.unitPlacementID>=instance.startingUnit.Count){ instance.unitPlacementID-=1; } //Debug.Log(instance.unitPlacementID); if(onPlacementUpdateE!=null) onPlacementUpdateE(); } //remove a unit from the grid public static void RemoveUnit(UnitTB unit){ GridManager.RemoveUnitAt(unit.occupiedTile); instance.startingUnit.Insert(0, unit); unit.occupiedTile.unit=null; unit.occupiedTile=null; unit.transform.position=new Vector3(0, 9999, 0); instance.allUnits.Remove(unit); if(instance.unitPlacementID<0) instance.unitPlacementID=0; if(onPlacementUpdateE!=null) onPlacementUpdateE(); } public static void AutoPlaceUnit(){ instance._AutoPlaceUnit(); } public void _AutoPlaceUnit(){ List<Tile> tileList=GridManager.GetAllPlaceableTiles(); //to make sure there's sufficient tile //if(tileList.Count<startingUnit.Count){ // Debug.Log("not enough space"); // return; //} while(startingUnit.Count>0){ int ID=Random.Range(0, tileList.Count); PlaceUnitAt(tileList[ID]); //tileList will be remove at GridManager when unit is placed if(tileList.Count<=0) break; } } private int unitPlacementID=0; public static int GetUnitPlacementID(){ return instance.unitPlacementID; } public static void NextUnitPlacementID(){ instance.unitPlacementID+=1; if(instance.unitPlacementID>=instance.startingUnit.Count) instance.unitPlacementID=0; } //~ public static void ResetUnitPlacementID(){ //~ instance.unitPlacementID=0; //~ } public static bool IsAllUnitPlaced(){ if(instance.startingUnit.Count==0) return true; return false; } */ //to place a unit in runtime, untested, will probably cause issue with certain turnMode public static void InsertUnit(UnitTB unit, Tile tile, int factionID, int duration){ if(unit==null){ Debug.Log("no unit is specified"); return; } if(tile.unit!=null){ Debug.Log("tile is occupied"); return; } GameObject unitObj=(GameObject)Instantiate(unit.gameObject); unit=unitObj.GetComponent<UnitTB>(); unit.SetSpawnInGameFlag(true); if(duration>0) unit.SetSpawnDuration(duration); //if(unit.occupiedTile!=null){ // unit.occupiedTile.unit=null; //} unit.factionID=factionID; unit.transform.position=tile.thisT.position; unit.occupiedTile=tile; tile.unit=unit; for(int i=0; i<instance.allFactionList.Count; i++){ Faction faction=instance.allFactionList[i]; if(faction.factionID==factionID){ faction.allUnitList.Add(unit); break; } } instance.allUnits.Add(unit); if(onNewUnitInRuntimeE!=null) onNewUnitInRuntimeE(unit); selectedUnit.occupiedTile.Select(); }