void Awake(){ instance = (SpawnManager)target; int enumLength = Enum.GetValues(typeof(SpawnManager._SpawnLimit)).Length; spawnLimitLabel=new string[enumLength]; spawnLimitTooltip=new string[enumLength]; for(int i=0; i<enumLength; i++){ spawnLimitLabel[i]=((SpawnManager._SpawnLimit)i).ToString(); if((SpawnManager._SpawnLimit)i==SpawnManager._SpawnLimit.Finite) spawnLimitTooltip[i]="Finite number of waves"; if((SpawnManager._SpawnLimit)i==SpawnManager._SpawnLimit.Infinite) spawnLimitTooltip[i]="Infinite number of waves (for survival or endless mode)"; } enumLength = Enum.GetValues(typeof(SpawnManager._SpawnMode)).Length; spawnModeLabel=new string[enumLength]; spawnModeTooltip=new string[enumLength]; for(int i=0; i<enumLength; i++){ spawnModeLabel[i]=((SpawnManager._SpawnMode)i).ToString(); if((SpawnManager._SpawnMode)i==SpawnManager._SpawnMode.Continous) spawnModeTooltip[i]="A new wave is spawn upon every wave duration countdown (with option to skip the timer)"; if((SpawnManager._SpawnMode)i==SpawnManager._SpawnMode.WaveCleared) spawnModeTooltip[i]="A new wave is spawned when the current wave is cleared (with option to spawn next wave in advance)"; if((SpawnManager._SpawnMode)i==SpawnManager._SpawnMode.Round) spawnModeTooltip[i]="Each wave is treated like a round. a new wave can only take place when the previous wave is cleared. Each round require initiation from user"; } }
private static void GetSpawnManager() { instance=(SpawnManager)FindObjectOfType(typeof(SpawnManager)); if(instance!=null){ window.waveFoldList=new List<bool>(); for(int i=0; i<instance.waveList.Count; i++) window.waveFoldList.Add(true); //if path is empty, get a path if(instance.defaultPath==null) instance.defaultPath=(PathTD)FindObjectOfType(typeof(PathTD)); //verify and setup the procedural wave generation unit list List<ProceduralUnitSetting> unitSettingList=instance.waveGenerator.unitSettingList; List<ProceduralUnitSetting> newSettingList=new List<ProceduralUnitSetting>(); for(int i=0; i<creepList.Count; i++){ bool match=false; for(int n=0; n<unitSettingList.Count; n++){ if(unitSettingList[n].unit==creepList[i].gameObject){ newSettingList.Add(unitSettingList[n]); match=true; break; } } if(!match){ ProceduralUnitSetting unitSetting=new ProceduralUnitSetting(); unitSetting.unit=creepList[i].gameObject; newSettingList.Add(unitSetting); } } instance.waveGenerator.unitSettingList=newSettingList; instance.waveGenerator.CheckPathList(); if(instance.defaultPath!=null && instance.waveGenerator.pathList.Count==0) instance.waveGenerator.pathList.Add(instance.defaultPath); List<ProceduralVariable> rscSettingList=instance.waveGenerator.rscSettingList; while(rscList.Count>rscSettingList.Count) rscSettingList.Add(new ProceduralVariable(10, 500)); while(rscList.Count<rscSettingList.Count) rscSettingList.RemoveAt(rscSettingList.Count-1); EditorUtility.SetDirty(instance); } }
void Awake() { instance=this; }
private static void GetSpawnManager() { instance = (SpawnManager)FindObjectOfType(typeof(SpawnManager)); if (instance != null) { window.waveFoldList = new List <bool>(); for (int i = 0; i < instance.waveList.Count; i++) { window.waveFoldList.Add(true); } //if path is empty, get a path if (instance.defaultPath == null) { instance.defaultPath = (PathTD)FindObjectOfType(typeof(PathTD)); } //verify and setup the procedural wave generation unit list List <ProceduralUnitSetting> unitSettingList = instance.waveGenerator.unitSettingList; List <ProceduralUnitSetting> newSettingList = new List <ProceduralUnitSetting>(); for (int i = 0; i < creepList.Count; i++) { bool match = false; for (int n = 0; n < unitSettingList.Count; n++) { if (unitSettingList[n].unit == creepList[i].gameObject) { newSettingList.Add(unitSettingList[n]); match = true; break; } } if (!match) { ProceduralUnitSetting unitSetting = new ProceduralUnitSetting(); unitSetting.unit = creepList[i].gameObject; newSettingList.Add(unitSetting); } } instance.waveGenerator.unitSettingList = newSettingList; instance.waveGenerator.CheckPathList(); if (instance.defaultPath != null && instance.waveGenerator.pathList.Count == 0) { instance.waveGenerator.pathList.Add(instance.defaultPath); } List <ProceduralVariable> rscSettingList = instance.waveGenerator.rscSettingList; while (rscList.Count > rscSettingList.Count) { rscSettingList.Add(new ProceduralVariable(10, 500)); } while (rscList.Count < rscSettingList.Count) { rscSettingList.RemoveAt(rscSettingList.Count - 1); } EditorUtility.SetDirty(instance); } }
void Awake() { instance = this; }
void OnSpawnButton(GameObject butObj, int pointerID = -1) { SpawnManager.Spawn(); buttonSpawn.SetActive(false); }
IEnumerator AbilityEffect(Vector3 pos) { if (effectDelay > 0) { yield return(new WaitForSeconds(effectDelay)); } List <Unit> tgtList = new List <Unit>(); if (targetType == _TargetType.Hostile) { if (!requireTargetSelection) { tgtList = SpawnManager.GetActiveUnitList(); } else { tgtList = SpawnManager.GetUnitsWithinRange(pos, stats.aoeRange); } } else if (targetType == _TargetType.Friendly) { if (!requireTargetSelection) { tgtList = TowerManager.GetActiveUnitList(); } else { tgtList = TowerManager.GetUnitsWithinRange(pos, stats.aoeRange); } } else { if (!requireTargetSelection) { tgtList = SpawnManager.GetActiveUnitList(); List <Unit> towerList = TowerManager.GetActiveUnitList(); for (int i = 0; i < towerList.Count; i++) { tgtList.Add(towerList[i]); } } else { tgtList = SpawnManager.GetUnitsWithinRange(pos, stats.aoeRange); List <Unit> towerList = TowerManager.GetUnitsWithinRange(pos, stats.aoeRange); for (int i = 0; i < towerList.Count; i++) { tgtList.Add(towerList[i]); } } } for (int i = 0; i < tgtList.Count; i++) { tgtList[i].ApplyAttack(new AttackInfo(this, tgtList[i], false)); effectOnTarget.Spawn(tgtList[i].GetTargetPoint(), Quaternion.identity); } yield return(null); }
void UpdateWaveDisplay(int wave) { //lbWave.text="wave-"+wave+(!SpawnManager.IsEndlessMode() ? "/"+SpawnManager.GetTotalWaveCount() : "" ); waveItem.lbMain.text = wave + (!SpawnManager.IsEndlessMode() ? "/" + SpawnManager.GetTotalWaveCount() : ""); //buttonSpawn.SetActive(false); }
public void OnSpawnButton() { SpawnManager.Spawn(); butSpawn.rectT.localPosition = new Vector3(0, 99999, 0); butSpawn.label.text = "Next Wave"; }
private bool GetSpawnManager() { instance = (SpawnManager)FindObjectOfType(typeof(SpawnManager)); return(instance == null ? false : true); }
public BuildInfo _CheckBuildPoint(Vector3 pointer, int towerID) { BuildInfo buildInfo = new BuildInfo(); if (disableBuildWhenInPlay && SpawnManager.GetActiveUnitCount() > 0) { buildInfo.status = _TileStatus.NotInBuildPhase; return(buildInfo); } Camera mainCam = Camera.main; if (mainCam != null) { Ray ray = mainCam.ScreenPointToRay(pointer); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, maskPlatform)) { for (int i = 0; i < buildPlatforms.Count; i++) { if (hit.transform == buildPlatforms[i].thisT) { PlatformTD platform = buildPlatforms[i]; //calculating the build center point base on the input position Vector3 pos = GetTilePos(platform, hit.point); buildInfo.position = pos; buildInfo.platform = platform; //checking if tower can be built on the platform, for dragNdrop mode if (towerID >= 0 && !platform.availableTowerIDList.Contains(towerID)) { buildInfo.status = _TileStatus.Unavailable; } if (buildInfo.status == _TileStatus.Available) { //check if the position is blocked, by any other obstabcle other than the baseplane itself Collider[] cols = Physics.OverlapSphere(pos, gridSize / 2 * 0.9f, ~maskAll); if (cols.Length > 0) { buildInfo.status = _TileStatus.NoPlatform; } else { buildInfo.status = _TileStatus.Available; } if (buildInfo.status == _TileStatus.Available) { //check if the platform is walkable, if so, check if building on the point wont block all possible path if (platform.IsWalkable()) { if (platform.CheckForBlock(pos)) { buildInfo.status = _TileStatus.Blocked; } } //map platform availableTowerIDList (which is the towers' prefabID) to the list elements' ID in towerList buildInfo.availableTowerIDList = new List <int>(); for (int m = 0; m < platform.availableTowerIDList.Count; m++) { for (int n = 0; n < towerList.Count; n++) { if (platform.availableTowerIDList[m] == towerList[n].prefabID) { buildInfo.availableTowerIDList.Add(n); break; } } } } } break; } } } else { buildInfo.status = _TileStatus.NoPlatform; } } else { buildInfo.status = _TileStatus.NoPlatform; } //reverse block status for mine if (buildInfo.status == _TileStatus.Blocked) { //for drag n drop mode if (towerID >= 0 && GetTowerPrefab(towerID).type == _TowerType.Mine) { buildInfo.status = _TileStatus.Available; } if (towerID < 0) { bool gotMineInList = false; for (int i = 0; i < buildInfo.availableTowerIDList.Count; i++) { if (towerList[buildInfo.availableTowerIDList[i]].type == _TowerType.Mine) { gotMineInList = true; } else { buildInfo.availableTowerIDList.RemoveAt(i); i -= 1; } } if (gotMineInList) { buildInfo.status = _TileStatus.Available; } } } if (!UseDragNDrop()) //for PointNClick { if (buildInfo.status != _TileStatus.Available) { IndicatorControl.ClearBuildTileIndicator(); } else { IndicatorControl.SetBuildTileIndicator(buildInfo); } } return(buildInfo); }
public void ApplyAttack(AttackInfo aInfo) { if (aInfo.aoeRange > 0) { if (aInfo.srcUnit.IsTower()) { List <Unit> tgtList = SpawnManager.GetUnitsWithinRange(this, aInfo.aoeRange); for (int i = 0; i < tgtList.Count; i++) { if (tgtList[i] == this) { continue; } tgtList[i].ApplyAttack(new AttackInfo(aInfo.srcUnit, tgtList[i], false)); } } } if (IsDestroyed()) { return; } if (aInfo.damage > 0) { if (aInfo.hit) { TDTK.TextOverlay(aInfo.damage.ToString(), GetTargetPoint()); AnimPlayHit(); //~ if(sh>0){ //~ if(aInfo.damage<sh){ //~ sh-=aInfo.damage; //~ aInfo.damage=0; //~ } //~ else{ //~ aInfo.damage-=sh; //~ sh=0; //~ } //~ } aInfo.damage = ApplyShieldDamage(aInfo.damage); shStagger = GetSHStagger(); hp -= aInfo.damage; } else { TDTK.TextOverlay("missed", GetTargetPoint()); } if (hp <= 0) { Destroyed(); return; } } if (aInfo.UseEffect()) { ApplyEffect(aInfo.effect); } }
public void ScanForTarget() { if (attackTarget != null) { if (attackTarget.IsDestroyed()) { attackTarget = null; } else { float dist = Vector3.Distance(GetPos(), attackTarget.GetPos()); if (dist > GetDetectionRange(attackTarget)) { attackTarget = null; } else { return; } } } if (CreepIsOnAttackCD()) { return; //for creep only } //if(cooldownAttack>0) return; List <Unit> unitList = null; if (IsTower()) { unitList = SpawnManager.GetUnitsWithinRange(this, GetAttackRange(), GetTargetGroup()); } else { unitList = TowerManager.GetUnitsWithinRange(this, GetAttackRange()); } if (targetingFov > 0 && targetingFov < 360) { Quaternion curDir = thisT.rotation * Quaternion.Euler(0, targetingDir, 0); for (int i = 0; i < unitList.Count; i++) { Quaternion dirToTarget = Quaternion.LookRotation(unitList[i].GetPos() - GetPos()); if (Quaternion.Angle(curDir, dirToTarget) > targetingFov * 0.5f) { unitList.RemoveAt(i); i -= 1; } } } if (unitList.Count <= 0) { return; } if (IsCreep() && targetMode == _TargetMode.NearestToDestination) { targetMode = _TargetMode.Random; } int newTargetIdx = -1; if (unitList.Count == 1) { newTargetIdx = 0; } else if (targetMode == _TargetMode.Random) { newTargetIdx = Random.Range(0, unitList.Count); } else if (targetMode == _TargetMode.NearestToSelf) { float nearest = Mathf.Infinity; for (int i = 0; i < unitList.Count; i++) { float dist = Vector3.Distance(GetPos(), unitList[i].GetPos()); if (dist < nearest) { newTargetIdx = i; nearest = dist; } } } else if (targetMode == _TargetMode.MostHP) { float mostHP = 0; for (int i = 0; i < unitList.Count; i++) { if (unitList[i].hp + unitList[i].sh > mostHP) { newTargetIdx = i; mostHP = unitList[i].hp + unitList[i].sh; } } } else if (targetMode == _TargetMode.LeastHP) { float leastHP = Mathf.Infinity; for (int i = 0; i < unitList.Count; i++) { if (unitList[i].hp + unitList[i].sh < leastHP) { newTargetIdx = i; leastHP = unitList[i].hp + unitList[i].sh; } } } else if (targetMode == _TargetMode.NearestToDestination) { float pathDist = Mathf.Infinity; int furthestWP = 0; int furthestSubWP = 0; float distToDest = Mathf.Infinity; for (int i = 0; i < unitList.Count; i++) { float pDist = unitList[i].GetPathDist(); int wpIdx = unitList[i].GetWPIdx(); int subWpIdx = unitList[i].GetSubWPIdx(); float tgtDistToDest = unitList[i].GetDistToTargetPos(); if (pDist < pathDist) { newTargetIdx = i; pathDist = pDist; furthestWP = wpIdx; furthestSubWP = subWpIdx; distToDest = tgtDistToDest; } else if (pDist == pathDist) { if (furthestWP < wpIdx) { newTargetIdx = i; pathDist = pDist; furthestWP = wpIdx; furthestSubWP = subWpIdx; distToDest = tgtDistToDest; } else if (furthestWP == wpIdx) { if (furthestSubWP < subWpIdx) { newTargetIdx = i; pathDist = pDist; furthestWP = wpIdx; furthestSubWP = subWpIdx; distToDest = tgtDistToDest; } else if (furthestSubWP == subWpIdx && tgtDistToDest < distToDest) { newTargetIdx = i; pathDist = pDist; furthestWP = wpIdx; furthestSubWP = subWpIdx; distToDest = tgtDistToDest; } } } } } if (newTargetIdx >= 0) { attackTarget = unitList[newTargetIdx]; if (snapAiming) { Aim(); } } }
//Check Auto Spawn public void CheckSpawn() { SpawnManager.Spawn(); }