public void _GameOver(){ TBData.ClearEndData(); //save the faction back to data if it's loaded from data for(int i=0; i<factionList.Count; i++){ Faction fac=factionList[i]; if(!fac.loadFromData) continue; List<TBDataUnit> startDataList=TBData.GetStartData(fac.dataID); List<TBDataUnit> list=new List<TBDataUnit>(); for(int m=0; m<startDataList.Count; m++){ for(int n=0; n<fac.allUnitList.Count; n++){ if(fac.allUnitList[n].GetDataID()==m){ list.Add(startDataList[m].Clone(fac.allUnitList[n])); fac.allUnitList.RemoveAt(n); break; } } } TBData.SetEndData(fac.dataID, list); } TBData.ClearStartData(); }
//called by GameControl to initiate the factions, //load from data when needed, spawn the startingUnit, initiate the unit (abillities), check if unit deployment is required.... public void Init(){ if(instance==null) instance=this; if(generateUnitOnStart) GenerateUnit(); //setup all the unit in the game for(int i=0; i<factionList.Count; i++){ for(int n=0; n<factionList[i].allUnitList.Count; n++){ if(factionList[i].allUnitList[n]==null){ factionList[i].allUnitList.RemoveAt(n); n--; continue; } factionList[i].allUnitList[n].InitUnitAbility(); factionList[i].allUnitList[n].isAIUnit=!factionList[i].isPlayerFaction; } } Vector3 pos=new Vector3(0, 99999, 0); Quaternion rot=Quaternion.identity; for(int i=0; i<factionList.Count; i++){ Faction fac=factionList[i]; //if load from data, then load the list from data and then put it to startingUnitList /* if(fac.loadFromData){ fac.dataList=TBData.GetStartData(fac.dataID); if(fac.dataList!=null && fac.dataList.Count>0){ fac.startingUnitList=new List<Unit>(); for(int n=0; n<fac.dataList.Count; n++) fac.startingUnitList.Add(fac.dataList[n].unit); //put the data list back into the end data first, to save the current starting lineup for next menu loading //in case the player didnt finish the level and GameOver is not called TBData.SetEndData(fac.dataID, fac.dataList); } else fac.loadFromData=false; } if(!fac.loadFromData){ //if using default startingUnitList, make sure none of the element in startingUnitList is empty for(int n=0; n<fac.startingUnitList.Count; n++){ if(fac.startingUnitList[n]==null){ fac.startingUnitList.RemoveAt(n); n-=1; } } } */ if(fac.loadFromData){ fac.startingUnitList=new List<Unit>(); fac.dataList=TBData.GetStartData(fac.dataID); if(fac.dataList==null){ Debug.LogWarning("TBTK faction's data not setup properly", this); continue; } Debug.Log("unit from data: "+fac.dataList.Count); for(int n=0; n<fac.dataList.Count; n++) fac.startingUnitList.Add(fac.dataList[n].unit); //put the data list back into the end data first, to save the current starting lineup for next menu loading //in case the player didnt finish the level and GameOver is not called TBData.SetEndData(fac.dataID, fac.dataList); } else{ //if using default startingUnitList, make sure none of the element in startingUnitList is empty for(int n=0; n<fac.startingUnitList.Count; n++){ if(fac.startingUnitList[n]==null){ fac.startingUnitList.RemoveAt(n); n-=1; } } } for(int n=0; n<fac.startingUnitList.Count; n++){ GameObject unitObj=(GameObject)Instantiate(fac.startingUnitList[n].gameObject, pos, rot); fac.startingUnitList[n]=unitObj.GetComponent<Unit>(); fac.startingUnitList[n].InitUnitAbility(); fac.startingUnitList[n].isAIUnit=!fac.isPlayerFaction; unitObj.transform.parent=transform; unitObj.SetActive(false); if(fac.loadFromData) //fac.startingUnitList[n].ModifyStatsToData(fac.dataList[n], n); fac.dataList[n].CopyStatsToUnit(fac.startingUnitList[n], n); } if(fac.isPlayerFaction && fac.startingUnitList.Count>0 && !requireDeployment){ if(deployingFactionID==-1) deployingFactionID=i; requireDeployment=true; } } if(!GameControl.EnableManualUnitDeployment()){ for(int i=0; i<factionList.Count; i++){ if(factionList[i].startingUnitList.Count<=0) continue; AutoDeployFaction(i); for(int n=0; n<deployedUnitList.Count; n++){ deployedUnitList[n].factionID=factionList[i].ID; factionList[i].allUnitList.Add(deployedUnitList[n]); } deployedUnitList=new List<Unit>(); } } }
void Awake() { instance = this; TBData.ClearEndData(); SettingDB settingDB = InitSetting(); if (enableCover) { CoverSystem.SetFullCoverDodgeBonus(fullCoverBonus); CoverSystem.SetHalfCoverDodgeBonus(halfCoverBonus); CoverSystem.SetExposedCritChanceBonus(exposedCritBonus); } //get the instance of each component and initiate them, the order in which these component matters PerkManager perkManager = (PerkManager)FindObjectOfType(typeof(PerkManager)); if (perkManager != null) { perkManager.Init(); } AbilityManagerUnit abManagerUnit = (AbilityManagerUnit)FindObjectOfType(typeof(AbilityManagerUnit)); if (abManagerUnit != null) { abManagerUnit.Init(); } AbilityManagerFaction abManagerFac = (AbilityManagerFaction)FindObjectOfType(typeof(AbilityManagerFaction)); if (abManagerFac != null) { abManagerFac.Init(); } TurnControl turnControl = (TurnControl)FindObjectOfType(typeof(TurnControl)); turnControl.Init(); if (settingDB != null) { turnControl.turnMode = settingDB.turnMode; turnControl.moveOrder = settingDB.moveOrder; } GridManager gridManager = (GridManager)FindObjectOfType(typeof(GridManager)); if (settingDB != null) { gridManager.generateGridOnStart = settingDB.generateGridOnStart; } gridManager.Init(); FactionManager factionManager = (FactionManager)FindObjectOfType(typeof(FactionManager)); if (settingDB != null) { factionManager.generateUnitOnStart = settingDB.generateUnitOnStart; } factionManager.Init(); CollectibleManager collectibleManager = (CollectibleManager)FindObjectOfType(typeof(CollectibleManager)); if (settingDB != null) { collectibleManager.generateCollectibleOnStart = settingDB.generateCollectibleOnStart; } collectibleManager.Init(); GridManager.SetupGridForFogOfWar(); OverlayManager overlayManager = (OverlayManager)FindObjectOfType(typeof(OverlayManager)); overlayManager.Init(); defaultShootObject = Resources.Load("ScenePrefab/DefaultShootObject", typeof(GameObject)) as GameObject; gamePhase = _GamePhase.Initialization; }