Example #1
0
 public bool Unspawn(GameObject obj)
 {
     if (activeList.Contains(obj))
     {
         obj.transform.parent = ObjectPoolManager.GetOPMTransform();
         activeList.Remove(obj);
         inactiveList.Add(obj);
         obj.SetActive(false);
         return(true);
     }
     return(false);
 }
Example #2
0
        public void MatchObjectCount(int count)
        {
            if (count > cap)
            {
                return;
            }
            int currentCount = GetTotalObjectCount();

            for (int i = currentCount; i < count; i++)
            {
                GameObject obj = (GameObject)MonoBehaviour.Instantiate(prefab);
                obj.SetActive(false);
                obj.transform.parent = ObjectPoolManager.GetOPMTransform();
                inactiveList.Add(obj);
            }
        }
Example #3
0
        private void Hit()
        {
            hit = true;

            if (hitEffect != null)
            {
                print("show hit effect  "); ObjectPoolManager.Spawn(hitEffect, targetPos, Quaternion.identity);
            }

            if (spell.effects.Count > 0)
            {
                Debug.Log("Cast spell effects");
                CastSpell(spell, targetPos, target);
            }
            ObjectPoolManager.Unspawn(gameObject);
        }
Example #4
0
        private IEnumerator FireCoroutine()
        {
            //yield return new WaitForSeconds(.1f);
            ShootObject2D arrow = ObjectPoolManager.Spawn(shootObject).GetComponent <ShootObject2D>();

            arrow.transform.position = shootPosition.position;
            print("arrow.Shoot");
            AttackInstance2D attInstance = new AttackInstance2D();

            attInstance.srcUnit = this;
            attInstance.tgtUnit = target;
            attInstance.Process();
            arrow.Shoot(attInstance, shootPosition);
            yield return(null);
            //arrow.transform.DOLocalMove(target.targetPosition.position, .5f).OnComplete(() => { base.Fire(); Destroy(arrow.gameObject); });
        }
Example #5
0
        void Awake()
        {
            speed_cached            = speed;
            bouncing_max_targets_bk = bouncing_max_targets;
            thisObj = gameObject;
            thisT   = transform;

            thisObj.layer = LayerManager.LayerShootObject();

            if (autoSearchLineRenderer)
            {
                LineRenderer[] lines = thisObj.GetComponentsInChildren <LineRenderer>(true);
                for (int i = 0; i < lines.Length; i++)
                {
                    lineList.Add(lines[i]);
                }
            }


            TrailRenderer[] trails = thisObj.GetComponentsInChildren <TrailRenderer>(true);
            for (int i = 0; i < trails.Length; i++)
            {
                trailList.Add(trails[i]);
            }

            if (type == _ShootObjectType.FPSProjectile)
            {
                SphereCollider sphereCol = GetComponent <SphereCollider>();
                if (sphereCol == null)
                {
                    sphereCol        = thisObj.AddComponent <SphereCollider>();
                    sphereCol.radius = 0.15f;
                }
                hitRadius = sphereCol.radius;
            }

            if (shootEffect != null)
            {
                ObjectPoolManager.New(shootEffect);
            }
            if (hitEffect != null)
            {
                ObjectPoolManager.New(hitEffect);
            }
        }
Example #6
0
        // Use this for initialization
        void Start()
        {
            foreach (Spawner spawner in prefabs)
            {
                ObjectPoolManager.New(spawner.prefab);
            }

            DOVirtual.DelayedCall(delay, () =>
            {
                foreach (Spawner spawner in prefabs)
                {
                    for (int i = 0; i < spawner.quatity; i++)
                    {
                        ObjectPoolManager.Spawn(spawner.prefab, spawner.StartingPosition);
                    }
                }
            });
        }
        void EffectSettings_CollisionEnter(object sender, CollisionInfo e)
        {
            if (Effect == null)
            {
                return;
            }
            var colliders = Physics.OverlapSphere(transform.position, EffectSettings.EffectRadius, EffectSettings.LayerMask);

            foreach (var coll in colliders)
            {
                var hitGO          = coll.transform;
                var renderer       = hitGO.GetComponentInChildren <Renderer>();
                var effectInstance = ObjectPoolManager.Spawn(Effect) as GameObject;
                effectInstance.transform.parent        = renderer.transform;
                effectInstance.transform.localPosition = Vector3.zero;
                effectInstance.GetComponent <AddMaterialOnHit>().UpdateMaterial(coll.transform);
            }
        }
Example #8
0
        //called by any external component to build tower, uses buildInfo
        public static string BuildTower(UnitTower tower)
        {
            if (buildInfo == null)
            {
                return("Select a Build Point First");
            }

            //dont allow building of resource tower before game started
            if (tower.type == _TowerType.Resource && !GameControl.IsGameStarted())
            {
                return("Cant Build Tower before spawn start");
            }

            UnitTower sampleTower = GetSampleTower(tower);

            //check if there are sufficient resource
            List <int> cost     = sampleTower.GetCost();
            int        suffCost = ResourceManager.HasSufficientResource(cost);

            if (suffCost == -1)
            {
                ResourceManager.SpendResource(cost);

                GameObject towerObj      = (GameObject)ObjectPoolManager.Spawn(tower.gameObject, buildInfo.position, buildInfo.platform.thisT.rotation);
                UnitTower  towerInstance = towerObj.GetComponent <UnitTower>();
                towerInstance.InitTower(instance.towerCount += 1);
                towerInstance.Build();

                //register the tower to the platform
                if (buildInfo.platform != null)
                {
                    buildInfo.platform.BuildTower(buildInfo.position, towerInstance);
                }

                //clear the build info and indicator for build manager
                ClearBuildPoint();

                return("");
            }

            return("Insufficient Resource");
        }
Example #9
0
        IEnumerator ResourceTowerRoutine()
        {
            while (true)
            {
                yield return(new WaitForSeconds(GetCooldown()));

                while (stunned || IsInConstruction())
                {
                    yield return(null);
                }

                Transform soPrefab = GetShootObjectT();
                if (soPrefab != null)
                {
                    ObjectPoolManager.Spawn(soPrefab, thisT.position, thisT.rotation);
                }

                ResourceManager.GainResource(GetResourceGain(), PerkManager.GetRscTowerGain());
            }
        }
Example #10
0
        //called from ActivateAbility, cast the ability, visual effect and actual effect goes here
        public void CastAbility(Ability ab, Vector3 pos = default(Vector3), Unit target = null)
        {
            GameObject effect = null;

            //print((ab.Caster ? "Unknown" : ab.Caster.unitName) + " casted " + ab.name + " on " + target);

            if (ab.prefab != null)
            {
                if (ab.abilityType == Ability.AbilityType.Summoning)
                {
                    effect = ObjectPoolManager.Spawn(ab.prefab, ab.caster.GetTargetT().position + Vector3.right * -2f, Quaternion.identity);
                    BuildManager.PreBuildTower(effect.GetComponent <UnitDefender>());
                }
                else if (ab.selfCast || ab.castAtCaster)
                {
                    effect = ObjectPoolManager.Spawn(ab.prefab, ab.caster.thisT.position, Quaternion.identity);
                    if (ab.caster)
                    {
                        print("Set parent");
                        effect.transform.parent = ab.caster.transform;
                    }
                }
                else
                {
                    effect = ObjectPoolManager.Spawn(ab.prefab, target ? target.GetTargetT().position : pos, Quaternion.identity);
                }
            }

            if (ab.useDefaultEffect)
            {
                StartCoroutine(ApplyAbilityEffect(ab, pos, target));
            }
            //else if (effect)
            //{
            //    AbilityBehavior abilityBehavior = effect.GetComponent<AbilityBehavior>();
            //    if (abilityBehavior)
            //    {
            //        StartCoroutine(ApplyAbilityEffect(abilityBehavior.ability, pos, target));
            //    }
            //}
        }
Example #11
0
        IEnumerator MineRoutine()
        {
            LayerMask maskTarget = 1 << LayerManager.LayerCreep();

            while (true)
            {
                if (!dead && !IsInConstruction())
                {
                    Collider[] cols = Physics.OverlapSphere(thisT.position, GetAttackRange(), maskTarget);
                    if (cols.Length > 0)
                    {
                        Collider[] colls = Physics.OverlapSphere(thisT.position, GetAOERadius(), maskTarget);
                        for (int i = 0; i < colls.Length; i++)
                        {
                            Unit unit = colls[i].transform.GetComponent <Unit>();
                            if (unit == null && !unit.dead)
                            {
                                continue;
                            }

                            AttackInstance attInstance = new AttackInstance();
                            attInstance.srcUnit = this;
                            attInstance.tgtUnit = unit;
                            attInstance.Process();

                            unit.ApplyEffect(attInstance);
                        }

                        Transform soPrefab = GetShootObjectT();
                        if (soPrefab != null)
                        {
                            ObjectPoolManager.Spawn(soPrefab, thisT.position, thisT.rotation);
                        }

                        Dead();
                    }
                }
                yield return(new WaitForSeconds(0.1f));
            }
        }
Example #12
0
        IEnumerator FPSEffectRoutine()
        {
            yield return(new WaitForSeconds(0.05f));

            RaycastHit raycastHit;
            Vector3    dir = thisT.TransformDirection(new Vector3(0, 0, 1));

            if (Physics.SphereCast(thisT.position, hitRadius / 2, dir, out raycastHit))
            {
                Unit unit = raycastHit.transform.GetComponent <Unit>();
                FPSHit(unit, raycastHit.point);

                if (hitEffect != null)
                {
                    ObjectPoolManager.Spawn(hitEffect, raycastHit.point, Quaternion.identity);
                }
            }

            yield return(new WaitForSeconds(0.1f));

            ObjectPoolManager.Unspawn(thisObj);
        }
Example #13
0
        IEnumerator FPSBeamRoutine(Transform sp)
        {
            thisT.parent = sp;
            float duration = 0;

            while (duration < beamDuration)
            {
                RaycastHit raycastHit;
                Vector3    dir         = thisT.TransformDirection(new Vector3(0, 0, 1));
                bool       hitCollider = Physics.SphereCast(thisT.position, hitRadius, dir, out raycastHit);
                if (hitCollider)
                {
                    if (!hit)
                    {
                        hit = true;
                        Unit unit = raycastHit.transform.GetComponent <Unit>();
                        FPSHit(unit, raycastHit.point);

                        if (hitEffect != null)
                        {
                            ObjectPoolManager.Spawn(hitEffect, raycastHit.point, Quaternion.identity);
                        }
                    }
                }

                float lineDist = raycastHit.distance == 0 ? 9999 : raycastHit.distance;
                for (int i = 0; i < lineList.Count; i++)
                {
                    lineList[i].SetPosition(1, new Vector3(0, 0, lineDist));
                }

                duration += Time.fixedDeltaTime;
                yield return(new WaitForSeconds(Time.fixedDeltaTime));
            }

            thisT.parent = null;
            ObjectPoolManager.Unspawn(thisObj);
        }
Example #14
0
        private IEnumerator BulletRoutine()
        {
            print("BulletRoutine");

            if (shootEffect != null)
            {
                ObjectPoolManager.Spawn(shootEffect, transform.position, transform.rotation);
            }
            yield return(new WaitForSeconds(shootDelay));

            //while the shootObject havent hit the target
            while (!hit)
            {
                if (target != null)
                {
                    targetPos = target.GetTargetTransform().position;
                }
                //calculating distance to targetPos
                Vector3 curPos = transform.position;
                //curPos.y = y;
                float currentDist = Vector2.Distance(curPos, targetPos);
                //if the target is close enough, trigger a hit
                if (currentDist < hitThreshold && !hit)
                {
                    Hit();
                    break;
                }

                transform.LookAt(targetPos);
                //move forward
                transform.Translate(Vector3.forward * Mathf.Min(speed * Time.deltaTime, currentDist));
                //transform.rotation = Quaternion.Euler(0, 0, 0);
                transform.rotation = Quaternion.Euler(0, 0, -transform.rotation.eulerAngles.x);
                speed += accel * Time.deltaTime;
                yield return(null);
            }
        }
Example #15
0
        public UnitTower CreateSampleTower(UnitTower towerPrefab)
        {
            GameObject towerObj = (GameObject)ObjectPoolManager.Spawn(towerPrefab.gameObject);

            towerObj.transform.parent = transform;
            if (towerObj.GetComponent <Collider>() != null)
            {
                Destroy(towerObj.GetComponent <Collider>());
            }
            Utility.DestroyColliderRecursively(towerObj.transform);

            //foreach(Transform child in towerObj.transform){
            //	Animator animator=child.gameObject.GetComponent<Animator>();
            //	if(animator!=null) animator.enabled=false;
            //}

            towerObj.SetActive(false);

            UnitTower towerInstance = towerObj.GetComponent <UnitTower>();

            towerInstance.SetAsSampleTower(towerPrefab);

            return(towerInstance);
        }
Example #16
0
        void Fire()
        {
            //if(!weapon.ReadyToFire()) return;

            if (currentWeapon.Shoot())
            {
                AttackInstance attInstance = new AttackInstance();
                attInstance.srcWeapon = currentWeapon;

                for (int i = 0; i < currentWeapon.shootPoints.Count; i++)
                {
                    Transform shootP    = currentWeapon.shootPoints[i];
                    Transform shootObjT = (Transform)ObjectPoolManager.Spawn(currentWeapon.GetShootObject(), shootP.position, shootP.rotation);
                    shootObjT.GetComponent <ShootObject>().ShootFPS(attInstance, shootP);
                }

                Recoil(currentWeapon.recoil);

                if (onFPSShootE != null)
                {
                    onFPSShootE();
                }
            }
        }
Example #17
0
        private IEnumerator ProjectileRoutine()
        {
            if (shootEffect != null)
            {
                ObjectPoolManager.Spawn(shootEffect, transform.position, transform.rotation);
            }
            yield return(new WaitForSeconds(shootDelay));

            //make sure the shootObject is facing the target and adjust the projectile angle
            transform.LookAt(targetPos);
            float angle = Mathf.Min(1, Vector3.Distance(transform.position, targetPos) / maxShootRange) * maxShootAngle;

            //clamp the angle magnitude to be less than 45 or less the dist ratio will be off
            transform.rotation = transform.rotation * Quaternion.Euler(-angle, 0, 0);

            Vector3 startPos  = transform.position;
            float   iniRotX   = transform.rotation.eulerAngles.x;
            float   y         = Mathf.Min(targetPos.y, startPos.y);
            float   totalDist = Vector3.Distance(startPos, targetPos);
            float   timeShot  = Time.time;

            //while the shootObject havent been hitting the target
            while (!hit)
            {
                if (target != null && updateTargetPosition)
                {
                    targetPos = target.GetTargetTransform().position;
                }
                //calculating distance to targetPos
                Vector3 curPos = transform.position;
                //curPos.y = y;
                float currentDist = Vector2.Distance(curPos, targetPos);
                //if the target is close enough, trigger a hit
                if (currentDist < hitThreshold && !hit)
                {
                    Hit();
                    break;
                }

                if (Time.time - timeShot < 3f)
                {
                    //calculate ratio of distance covered to total distance
                    float invR = 1 - Mathf.Min(.5f, currentDist * smoothly / totalDist);

                    //use the distance information to set the rotation,
                    //as the projectile approach target, it will aim straight at the target
                    Vector3 wantedDir = targetPos - transform.position;
                    if (wantedDir != Vector3.zero)
                    {
                        Quaternion wantedRotation = Quaternion.LookRotation(wantedDir);
                        float      rotX           = Mathf.LerpAngle(iniRotX, wantedRotation.eulerAngles.x, invR);

                        //make y-rotation always face target
                        transform.rotation = Quaternion.Euler(rotX, wantedRotation.eulerAngles.y, wantedRotation.eulerAngles.z);
                    }
                }
                else
                {
                    //this shoot time exceed 3 sec, abort the trajectory and just head to the target
                    transform.LookAt(targetPos);
                }
                //move forward
                //transform.LookAt(targetPos);
                transform.Translate(Vector3.forward * Mathf.Min(speed * Time.deltaTime, currentDist));
                transform.rotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.x);
                yield return(null);
            }
        }
Example #18
0
        IEnumerator Building(float duration, bool reverse = false)
        {       //reverse flag is set to true when selling (thus unbuilding) the tower
            construction = !reverse ? _Construction.Constructing : _Construction.Deconstructing;

            builtDuration = 0;
            buildDuration = duration;

            if (onConstructionStartE != null)
            {
                onConstructionStartE(this);
            }

            yield return(null);

            if (!reverse && playConstructAnimation != null)
            {
                playConstructAnimation();
            }
            else if (reverse && playDeconstructAnimation != null)
            {
                playDeconstructAnimation();
            }

            if (SpawnEffect)
            {
                SpawnEffect = ObjectPoolManager.Spawn(SpawnEffect, thisT.position, thisT.rotation);
                foreach (Renderer render in renderParent)
                {
                    render.enabled = false;
                }
            }
            while (true)
            {
                yield return(null);

                builtDuration += Time.deltaTime;
                if (builtDuration > buildDuration)
                {
                    break;
                }
            }
            if (SpawnEffect)
            {
                ObjectPoolManager.Unspawn(SpawnEffect);
                foreach (Renderer render in renderParent)
                {
                    render.enabled = true;
                }
            }
            construction = _Construction.None;

            if (!reverse && onConstructionCompleteE != null)
            {
                onConstructionCompleteE(this);
            }

            if (reverse)
            {
                if (onSoldE != null)
                {
                    onSoldE(this);
                }

                if (occupiedPlatform != null)
                {
                    occupiedPlatform.UnbuildTower(occupiedNode);
                }
                ResourceManager.GainResource(GetValue());
                Dead();
            }
        }
Example #19
0
        void Awake()
        {
            Time.fixedDeltaTime = timeStep;

            instance = this;
            thisT    = transform;

            //ObjectPoolManager.Init();

            BuildManager buildManager = (BuildManager)FindObjectOfType(typeof(BuildManager));

            buildManager.Init();

            NodeGenerator nodeGenerator = (NodeGenerator)FindObjectOfType(typeof(NodeGenerator));

            if (nodeGenerator != null)
            {
                nodeGenerator.Awake();
            }
            PathFinder pathFinder = (PathFinder)FindObjectOfType(typeof(PathFinder));

            if (pathFinder != null)
            {
                pathFinder.Awake();
            }

            PathTD[] paths = FindObjectsOfType(typeof(PathTD)) as PathTD[];
            for (int i = 0; i < paths.Length; i++)
            {
                paths[i].Init();
            }

            for (int i = 0; i < buildManager.buildPlatforms.Count; i++)
            {
                buildManager.buildPlatforms[i].Init();
            }

            gameObject.GetComponent <ResourceManager>().Init();

            PerkManager perkManager = (PerkManager)FindObjectOfType(typeof(PerkManager));

            if (perkManager != null)
            {
                perkManager.Init();
            }

            if (loadAudioManager)
            {
                Instantiate(Resources.Load("AudioManager", typeof(GameObject)));
            }

            if (rangeIndicator)
            {
                rangeIndicator        = (Transform)ObjectPoolManager.Spawn(rangeIndicator);
                rangeIndicator.parent = thisT;
                rangeIndicatorObj     = rangeIndicator.gameObject;
            }
            if (rangeIndicatorCone)
            {
                rangeIndicatorCone        = (Transform)ObjectPoolManager.Spawn(rangeIndicatorCone);
                rangeIndicatorCone.parent = thisT;
                rangeIndicatorConeObj     = rangeIndicatorCone.gameObject;
            }
            ClearSelectedTower();

            Time.timeScale = 1;
        }
Example #20
0
        IEnumerator AOETowerRoutine()
        {
            if (CurrentStat.customMask > -1)
            {
                TargetMask = CurrentStat.customMask;
            }
            else if (targetMode == _TargetMode.Hybrid)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                TargetMask = mask1 | mask2;
            }
            else if (targetMode == _TargetMode.Air)
            {
                TargetMask = 1 << LayerManager.LayerCreepF();
            }
            else if (targetMode == _TargetMode.Ground)
            {
                TargetMask = 1 << LayerManager.LayerCreep();
            }

            while (true)
            {
                yield return(new WaitForSeconds(GetCooldown()));

                while (stunned || IsInConstruction())
                {
                    yield return(null);
                }



                Collider[] cols = Physics.OverlapSphere(thisT.position, GetAttackRange(), TargetMask);
                if (cols.Length > 0)
                {
                    Transform soPrefab = GetShootObjectT();
                    if (soPrefab != null)
                    {
                        ObjectPoolManager.Spawn(soPrefab, thisT.position, thisT.rotation);
                    }

                    //SendMessage("OnAttackTargetStarted", SendMessageOptions.DontRequireReceiver);
                    //print("AOE attack");

                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].transform.GetComponent <Unit>(); //damage all units in its range
                        if (unit == null && !unit.dead)
                        {
                            continue;
                        }

                        AttackInstance attInstance = new AttackInstance();
                        attInstance.srcUnit = this;
                        attInstance.tgtUnit = unit;
                        attInstance.Process();

                        unit.ApplyEffect(attInstance);
                    }
                }
                else
                {
                    //SendMessage("OnAttackTargetStopped", SendMessageOptions.DontRequireReceiver);
                    //print("AOE stopped");
                }
            }
        }
Example #21
0
        void Hit()
        {
            hit = true;

            if (isArrow) //leave an arrow in the ground effect
            {
                targetPos = new Vector3(targetPos.x + Random.value - .5f, 0.05f, targetPos.z + Random.value - .5f);
            }
            if (hitEffect != null)
            {
                ObjectPoolManager.Spawn(hitEffect, targetPos, isArrow ? Quaternion.Euler(-180, Random.Range(0, 30), Random.Range(0, 30)) : Quaternion.identity);
            }

            //apply ability
            if (Ab_End_Holder)
            {
                AbilityManager.instance.ActivateAbility(Ab_End_Holder.ability, attInstance.srcUnit, targetPos, target);
            }
            thisT.position          = targetPos;
            attInstance.impactPoint = thisT.position;
            LayerMask mask = attInstance.srcUnit.TargetMask;

            if (attInstance.srcUnit.GetAOERadius() > 0)
            {
                Collider[] cols = Physics.OverlapSphere(thisT.position, attInstance.srcUnit.GetAOERadius(), mask);
                AttackTargets(cols);
                print("Splash attack kill more " + cols.Length);
            }
            else
            {
                if (target != null)
                {
                    target.ApplyEffect(attInstance);
                    if (target.alarmWhenGotAttacked && !target.isAlarming && target.GetAttackRange() < 2 && attInstance.damage > 0)
                    {
                        target.isAlarming = true;
                        target.attacker   = attInstance.srcUnit;
                        target.StartCoroutine(SetAlarmOff(target, 10));
                    }

                    if (penetratable && penetration_distance > 0) //penetratable attack
                    {
                        Vector3      position  = shootPoint.position;
                        Vector3      direction = target.GetTargetT().position - position;
                        RaycastHit[] hits      = Physics.RaycastAll(position, direction.normalized, penetration_distance);
                        AttackTargets(hits.GetColliders());
                        print("Penetrate attack kill more " + hits.Length);
                    }
                }
            }
            //DestroyImmediate(thisObj);
            if (!bouncing)
            {
                ObjectPoolManager.Unspawn(thisObj);
            }
            else
            {
                Collider[] cols = Physics.OverlapSphere(thisT.position, bouncing_radius, mask);
                if (cols.Length > 0)
                {
                    print("Bonce");
                    List <Unit> tgtList = new List <Unit>();
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].gameObject.GetComponent <Unit>();
                        if (unit && !unit.dead && unit != attInstance.tgtUnit)
                        {
                            tgtList.Add(unit);
                        }
                    }
                    if (tgtList.Count > 0 && bouncing_max_targets >= 0)
                    {
                        bouncing_max_targets--;
                        attInstance.tgtUnit = tgtList[0];
                        Shoot(attInstance, thisT);
                    }
                }
                else
                {
                    ObjectPoolManager.Unspawn(thisObj);
                }
            }
        }
Example #22
0
        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.overrideShield > 0)
                {
                    unit.defaultShield = subWave.overrideShield;
                }
                if (subWave.overrideMoveSpd > 0)
                {
                    unit.moveSpeed = subWave.overrideMoveSpd;
                }

                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();
                    }
                }
            }
        }
Example #23
0
        public void Shoot(AttackInstance attInst = null, Transform sp = null)
        {
            if (attInst.tgtUnit == null || attInst.tgtUnit.GetTargetT() == null)
            {
                ObjectPoolManager.Unspawn(thisObj);
                return;
            }

            attInstance = attInst;
            target      = attInstance.tgtUnit;
            //print(attInstance.srcUnit.unitName + " attacks " + attInstance.tgtUnit.unitName + " with " + attInstance.damage + " damage");

            targetPos = target.GetTargetT().position;
#if Game_2D
            hitThreshold = Mathf.Max(.01f, target.hitThreshold);
#else
            hitThreshold = Mathf.Max(.1f, target.hitThreshold);
#endif
            shootPoint = sp;

            if (shootPoint != null)
            {
                thisT.rotation = shootPoint.rotation;
            }
            if (shootEffect != null && !target.dead)
            {
                GameObject shootEffectInstance = ObjectPoolManager.Spawn(shootEffect, thisT.position, thisT.rotation);
                if (shootEffectInstance)
                {
                    effectSetting = shootEffectInstance.GetComponent <EffectSettings>();
                    if (effectSetting == null)
                    {
                        effectSetting = shootEffectInstance.GetComponentInChildren <EffectSettings>();
                    }
                    if (effectSetting)
                    {
                        if (effectSetting.EffectType == EffectSettings.EffectTypeEnum.Other)
                        {
                            Vector3 direction = (targetPos - thisT.position).normalized;
                            shootEffectInstance.transform.rotation = Quaternion.LookRotation(direction);
                        }

                        effectSetting.Target = target.GetTargetT().gameObject;
                        SelfDeactivator selfDeactivator = shootEffectInstance.GetComponent <SelfDeactivator>();
                        if (selfDeactivator == null)
                        {
                            selfDeactivator = shootEffectInstance.AddComponent <SelfDeactivator>();
                        }
                        selfDeactivator.duration = attInstance.srcUnit.CurrentStat.cooldown;
                    }
                }
                Unit.onDestroyedE += OnTargetDestroy;
            }
            hit = false;


            if (Ab_Start_Holder)
            {
                AbilityManager.instance.ActivateAbility(Ab_Start_Holder.ability, attInstance.srcUnit, targetPos, target);
            }

            if (type == _ShootObjectType.Projectile)
            {
                StartCoroutine(ProjectileRoutine());
            }
            else if (type == _ShootObjectType.Beam)
            {
                StartCoroutine(BeamRoutine());
            }
            else if (type == _ShootObjectType.Missile)
            {
                StartCoroutine(MissileRoutine());
            }
            else if (type == _ShootObjectType.Effect && EffectDelay > 0)
            {
                StartCoroutine(EffectRoutine());
            }
            else
            {
                Hit();
            }
        }
Example #24
0
        IEnumerator _ReachDestination(float duration)
        {
            yield return(new WaitForSeconds(duration));

            ObjectPoolManager.Unspawn(thisObj);
        }