void SpawnSubCreep(UnitCreep prefab, float orHP = -1, float orSH = -1, float orSpd = -1, int orRscExp = -1, List <int> orRsc = null) { Vector3 dir = (subPath[subWpIdx] - GetPos()).normalized; Vector3 spawnPos = GetPos() + dir * Random.Range(-.5f, .5f); //~ GameObject unitObj=(GameObject)Instantiate(prefab.gameObject, spawnPos, thisT.rotation); GameObject unitObj = ObjectPoolManager.Spawn(prefab.gameObject, spawnPos, thisT.rotation); UnitCreep unitInstance = unitObj.GetComponent <UnitCreep>(); unitInstance.SetHP(orHP); unitInstance.SetSH(orSH); unitInstance.SetSpeed(orSpd); if (orRsc != null) { unitInstance.rscGainOnDestroyed = orRsc; } //~ if(orHP>0) unitInstance.SetHP(orHP); //~ if(orSH>0) unitInstance.SetSH(orSH); //~ if(orSpd>0) unitInstance.SetSpeed(orSpd); //~ if(orRsc!=null) unitInstance.rscGainOnDestroyed=orRsc; unitInstance.Init(waveIdx, path, wpIdx, subWpIdx, false, reverse, new List <Path>(prevPathList), subPath); SpawnManager.SubUnitSpawned(unitInstance); //SpawnManager.SubUnitSpawned(unitInstance, waveIdx); }
public float CreepDestroyed() { List <int> rscGain = new List <int>(); for (int i = 0; i < valueRscMin.Count; i++) { rscGain.Add(Random.Range(valueRscMin[i], valueRscMax[i])); } ResourceManager.GainResource(rscGain, PerkManager.GetRscCreepKilled()); AbilityManager.GainEnergy(valueEnergyGain + (int)PerkManager.GetEnergyWaveClearedModifier()); if (spawnUponDestroyed != null && spawnUponDestroyedCount > 0) { for (int i = 0; i < spawnUponDestroyedCount; i++) { Vector3 posOffset = new Vector3(Random.Range(-0.5f, 0.5f), 0, Random.Range(-0.5f, 0.5f)); GameObject obj = ObjectPoolManager.Spawn(spawnUponDestroyed, thisT.position + posOffset, thisT.rotation); UnitCreep unit = obj.GetComponent <UnitCreep>(); unit.waveID = waveID; int ID = SpawnManager.AddDestroyedSpawn(unit); unit.Init(path, ID, waveID, this); } } if (aniInstance != null) { return(aniInstance.PlayDead()); } return(0); }
public override void Destroyed(float delay = 0) { if (destroyed) { return; } destroyed = true; List <int> rscGain = new List <int>(); for (int i = 0; i < valueRscMin.Count; i++) { rscGain.Add(Random.Range(valueRscMin[i], valueRscMax[i])); } ResourceManager.GainResource(rscGain, PerkManager.GetRscCreepKilled()); AbilityManager.GainEnergy(valueEnergyGain + (int)PerkManager.GetEnergyWaveClearedModifier()); if (lifeValue > 0) { GameControl.GainLife(lifeValue); } if (spawnUponDestroyed != null && spawnUponDestroyedCount > 0) { for (int i = 0; i < spawnUponDestroyedCount; i++) { Vector3 posOffset = new Vector3(Random.Range(-0.5f, 0.5f), 0, Random.Range(-0.5f, 0.5f)); GameObject obj = ObjectPoolManager.Spawn(spawnUponDestroyed.gameObject, thisT.position + posOffset, thisT.rotation); UnitCreep unit = obj.GetComponent <UnitCreep>(); unit.waveID = waveID; int ID = SpawnManager.AddDestroyedSpawn(unit); unit.Init(path, ID, waveID, this); } } SpawnManager.OnUnitDestroyed(this); TDTK.OnUnitCreepDestroyed(this); base.Destroyed(PlayAnimDestroyed()); }
public UnitCreep SpawnUnit(UnitCreep creep, int waveIdx, Path path, SubWave subWave = null) { //~ GameObject unitObj=(GameObject)Instantiate(creep.gameObject, path.GetSpawnPoint(), Quaternion.identity); GameObject unitObj = ObjectPoolManager.Spawn(creep.gameObject, path.GetSpawnPoint(), Quaternion.identity); UnitCreep unitInstance = unitObj.GetComponent <UnitCreep>(); unitInstance.ResetHP(); unitInstance.ResetSH(); unitInstance.ResetSpeed(); unitInstance.ResetRscGainOnDestroy(); if (subWave != null) { //if(subWave.HP>0) unitInstance.SetHP(subWave.HP); //if(subWave.SH>0) unitInstance.SetSH(subWave.SH); //if(subWave.speed>0) unitInstance.SetSpeed(subWave.speed); //if(subWave.overrideRscGain) unitInstance.rscGainOnDestroyed=subWave.rscGain; unitInstance.SetHP(subWave.HP > 0 ? subWave.HP : -1); unitInstance.SetSH(subWave.SH > 0 ? subWave.SH : -1); unitInstance.SetSpeed(subWave.speed > 0 ? subWave.speed : -1); unitInstance.SetRscGainOnDestroy(subWave.overrideRscGain ? subWave.rscGain : null); } else //reset the unit value to default value { unitInstance.SetHP(); unitInstance.SetSH(); unitInstance.SetSpeed(); unitInstance.SetRscGainOnDestroy(null); } unitInstance.Init(waveIdx, path); totalCreepCount += 1; unitInstance.instanceID = totalCreepCount; return(unitInstance); }
IEnumerator SpawnSubWave(SubWave subWave, Wave parentWave) { yield return(new WaitForSeconds(subWave.delay)); PathTD path = defaultPath; if (subWave.path != null) { path = subWave.path; } Vector3 pos = path.GetSpawnPoint().position; Quaternion rot = path.GetSpawnPoint().rotation; int spawnCount = 0; while (spawnCount < subWave.count) { GameObject obj = ObjectPoolManager.Spawn(subWave.unit, pos, rot); UnitCreep unit = obj.GetComponent <UnitCreep>(); if (subWave.overrideHP > 0) { unit.OverrideByHP(subWave.overrideHP); } else { unit.OverrideByWave(parentWave.waveID, developPerWave); } unit.Init(path, totalSpawnCount, parentWave.waveID); totalSpawnCount += 1; activeUnitCount += 1; parentWave.activeUnitCount += 1; spawnCount += 1; if (spawnCount == subWave.count) { break; } yield return(new WaitForSeconds(subWave.interval)); } parentWave.subWaveSpawnedCount += 1; if (parentWave.subWaveSpawnedCount == parentWave.subWaveList.Count) { parentWave.spawned = true; spawning = false; Debug.Log("wave " + (parentWave.waveID + 1) + " has done spawning"); yield return(new WaitForSeconds(0.5f)); if (currentWaveID <= waveList.Count - 2) { //for UI to show spawn button again if (spawnMode == _SpawnMode.Continous && allowSkip && onEnableSpawnE != null) { onEnableSpawnE(); } if (spawnMode == _SpawnMode.WaveCleared && allowSkip && onEnableSpawnE != null) { onEnableSpawnE(); } } } }
IEnumerator SpawnSubWave(SubWave subWave, Wave parentWave) { if (subWave.unit == null) { Debug.LogWarning("No creep prefab has been assigned to sub-wave", this); yield break; } yield return(new WaitForSeconds(subWave.delay)); PathTD path = defaultPath; if (subWave.path != null) { path = subWave.path; } Vector3 pos = path.GetSpawnPoint().position; Quaternion rot = path.GetSpawnPoint().rotation; int spawnCount = 0; if (subWave.unitC == null) { subWave.unitC = subWave.unit.GetComponent <UnitCreep>(); } while (spawnCount < subWave.count) { if (subWave.unit == null) { Debug.LogWarning("no creep has been assigned to subwave", this); break; } GameObject obj = ObjectPoolManager.Spawn(subWave.unit, pos, rot); UnitCreep unit = obj.GetComponent <UnitCreep>(); if (subWave.overrideHP > 0) { unit.defaultHP = subWave.overrideHP; } else { unit.defaultHP = subWave.unitC.defaultHP; } if (subWave.overrideShield > 0) { unit.defaultShield = subWave.overrideShield; } else { unit.defaultShield = subWave.unitC.defaultShield; } if (subWave.overrideMoveSpd > 0) { unit.moveSpeed = subWave.overrideMoveSpd; } else { unit.moveSpeed = subWave.unitC.moveSpeed; } unit.Init(path, totalSpawnCount, parentWave.waveID); totalSpawnCount += 1; activeUnitCount += 1; parentWave.activeUnitCount += 1; spawnCount += 1; if (spawnCount == subWave.count) { break; } yield return(new WaitForSeconds(subWave.interval)); } parentWave.subWaveSpawnedCount += 1; if (parentWave.subWaveSpawnedCount == parentWave.subWaveList.Count) { parentWave.spawned = true; spawning = false; Debug.Log("wave " + (parentWave.waveID + 1) + " has done spawning"); yield return(new WaitForSeconds(0.5f)); if (currentWaveID <= waveList.Count - 2) { if ((spawnMode == _SpawnMode.WaveCleared || spawnMode == _SpawnMode.Continous) && allowSkip) { TDTK.OnEnableSpawn(); } } } }