Ejemplo n.º 1
0
        void Awake()
        {
            gameObject.GetComponent <Collider>().isTrigger = true;
            gameObject.layer = TDS.GetLayerCollectible();

            if (type == _CollectType.Self)
            {
                //initiate the weapon list to contain all weapon if the condition is checked
                if (gainWeapon && randomWeapon && enableAllWeapon)
                {
                    weaponList = new List <Weapon>(WeaponDB.Load());
                }

                //make sure none of the element in weaponList is null
                for (int i = 0; i < weaponList.Count; i++)
                {
                    if (weaponList[i] == null)
                    {
                        weaponList.RemoveAt(i); i -= 1;
                    }
                }
            }

            //effect=EffectDB.CloneItem(effectID);
            effectIdx = EffectDB.GetEffectIndex(effectID);

            if (triggerEffectObj != null)
            {
                ObjectPoolManager.New(triggerEffectObj, 1);
            }
        }
Ejemplo n.º 2
0
        void Awake()
        {
            instance = this;

            //QualitySettings.vSyncCount=1;
            //Application.targetFrameRate=60;

            //get the unit in game
            player = (UnitPlayer)FindObjectOfType(typeof(UnitPlayer));

            //setup the collision rules
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerShootObject(), !shootObject);
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerCollectible(), !collectible);

            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerTerrain(), true);
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerTrigger(), true);

            //clear all the spawner and tracker sicne it's a new game
            UnitTracker.Clear();
            UnitSpawnerTracker.Clear();

            //this is not required, each individual unit and spawner will register itself to the tracker
            //UnitTracker.ScanForUnit();
            //UnitSpawnerTracker.ScanForSpawner();
        }
Ejemplo n.º 3
0
 void UpdateSphereCastMask(bool ignoreFriendly, bool ignoreSO, bool ignoreCollectible)
 {
     mask = ~(1 << TDS.GetLayerTrigger());
     if (ignoreFriendly)
     {
         mask &= ~(1 << srcLayer);
     }
     if (ignoreSO)
     {
         mask &= ~(1 << TDS.GetLayerShootObject());
     }
     if (ignoreCollectible)
     {
         mask &= ~(1 << TDS.GetLayerCollectible());
     }
 }
Ejemplo n.º 4
0
        //called when shootobject hit something
        void OnTriggerEnter(Collider col)
        {
            if (state == _State.Hit)
            {
                return;                                 //if the shootobject has hit something before this, return
            }
            //if the shootobject hits another shootobject from friendly unit
            if (!GameControl.SOHitFriendly() && col != null)
            {
                if (srcLayer == col.gameObject.layer)
                {
                    return;
                }
            }

            //register the state of the shootobject as hit
            state = _State.Hit;

            TDS.CameraShake(impactCamShake);


            //when hit a shootObject
            if (col != null && col.gameObject.layer == TDS.GetLayerShootObject())
            {
                //if this is a beam shootobject, inform the other shootobject that it has been hit (beam doesnt use a collider)
                if (type == _SOType.Beam)
                {
                    col.gameObject.GetComponent <ShootObject>().Hit();
                }
            }


            //when hit a collectible, destroy the collectible
            if (col != null && col.gameObject.layer == TDS.GetLayerCollectible())
            {
                ObjectPoolManager.Unspawn(col.gameObject);
                return;
            }


            //if there's a attack instance (means the shootobject has a valid attacking stats and all)
            if (attInstance != null)
            {
                float aoeRadius = attInstance.aStats.aoeRadius;

                //for area of effect hit
                if (aoeRadius > 0)
                {
                    Unit unitInstance = null;

                    //get all the potental target in range
                    Collider[] cols = Physics.OverlapSphere(thisT.position, aoeRadius);
                    for (int i = 0; i < cols.Length; i++)
                    {
                        //if the collider in question is the collider the shootobject hit in the first place, apply the full attack instance
                        if (cols[i] == col)
                        {
                            unitInstance = col.gameObject.GetComponent <Unit>();
                            if (unitInstance != null)
                            {
                                unitInstance.ApplyAttack(attInstance.Clone());
                            }
                            continue;
                        }

                        //no friendly fire, then skip if the target is a friendly unit
                        if (!GameControl.SOHitFriendly())
                        {
                            if (cols[i].gameObject.layer == srcLayer)
                            {
                                continue;
                            }
                        }

                        unitInstance = cols[i].gameObject.GetComponent <Unit>();

                        //create a new attack instance and mark it as aoe attack, so diminishing aoe can be applied if enabled
                        AttackInstance aInstance = attInstance.Clone();
                        aInstance.isAOE       = true;
                        aInstance.aoeDistance = Vector3.Distance(thisT.position, cols[i].transform.position);

                        //apply the attack
                        if (unitInstance != null)
                        {
                            unitInstance.ApplyAttack(aInstance);
                        }
                    }
                }
                else
                {
                    if (col != null)
                    {
                        //get the unit and apply the attack
                        Unit unitInstance = col.gameObject.GetComponent <Unit>();
                        if (unitInstance != null)
                        {
                            unitInstance.ApplyAttack(attInstance);
                        }
                    }
                }

                if (col != null)
                {
                    //apply impact force to the hit object
                    Vector3 impactDir = Quaternion.Euler(0, thisT.eulerAngles.y, 0) * Vector3.forward;
                    TDSPhysics.ApplyAttackForce(thisT.position, impactDir, col.gameObject, attInstance.aStats);
                }
            }

            //add collider to the condition so the shootobject wont split if the shootObject didnt hit anything (it could have just reach the range limit)
            if (splitUponHit && col != null)
            {
                Split(col);
            }

            Hit();
        }