コード例 #1
0
    public void ReturnEffectToPool(GameObject effectToStore, GameConstants.EffectTypes effectType)
    {
        if (effectType == GameConstants.EffectTypes.BulletHit)
        {
            // Return to normal bullet pool
            effectToStore.transform.SetParent(bulletHitEffectsPool);
        }
        else if (effectType == GameConstants.EffectTypes.ShieldHit)
        {
            // Return to shotgun bullet pool
            effectToStore.transform.SetParent(shieldHitEffectsPool);
        }
        else if (effectType == GameConstants.EffectTypes.ShipExplosion)
        {
            // Return to laser bullet pool
            effectToStore.transform.SetParent(explodeEffectsPool);
        }
        else if (effectType == GameConstants.EffectTypes.SmokeEffect)
        {
            // Return to laser bullet pool
            effectToStore.transform.SetParent(smokeEffectsPool);
        }

        effectToStore.gameObject.SetActive(false);
        effectToStore.transform.localScale = Vector3.one;
        effectToStore.transform.position   = Vector3.zero;
    }
コード例 #2
0
    public GameObject BeginEffect(GameConstants.EffectTypes effectType, Vector3 position, Vector3 lookAt)
    {
        GameObject effectObject = null;

        switch (effectType)
        {
        // Get First Child, set parent to gunport (to remove from respective pool)
        case GameConstants.EffectTypes.BulletHit:
            effectObject = bulletHitEffectsPool.GetComponentInChildren <BulletHitEffect>(true).gameObject;
            break;

        case GameConstants.EffectTypes.ShieldHit:
            effectObject = shieldHitEffectsPool.GetComponentInChildren <ShieldHitEffect>(true).gameObject;
            break;

        case GameConstants.EffectTypes.SmokeEffect:
            effectObject = smokeEffectsPool.GetComponentInChildren <SmokeEffect>(true).gameObject;
            break;

        case GameConstants.EffectTypes.ShipExplosion:
            effectObject = explodeEffectsPool.GetComponentInChildren <ExplosionEffect>(true).gameObject;
            break;
        }

        //bulletObject.transform.SetParent(worldBullets);
        //bulletObject.transform.position = gunPort.transform.position;
        //// Return bullet and let GunPort handle how to fire and set initial velocities
        //return bulletObject;
        effectObject.transform.SetParent(worldEffects);
        effectObject.transform.position = new Vector3(position.x, position.y, position.z);
        effectObject.transform.up       = new Vector3(lookAt.x, lookAt.y, lookAt.z);

        effectObject.SetActive(true);

        switch (effectType)
        {
        // Get First Child, set parent to gunport (to remove from respective pool)
        case GameConstants.EffectTypes.BulletHit:
            effectObject.GetComponent <BulletHitEffect>().FadeIn();
            break;

        case GameConstants.EffectTypes.ShieldHit:
            effectObject.GetComponent <ShieldHitEffect>().FadeIn();
            break;

        case GameConstants.EffectTypes.SmokeEffect:
            effectObject.GetComponent <SmokeEffect>().FadeIn();
            break;

        case GameConstants.EffectTypes.ShipExplosion:
            effectObject.GetComponent <ExplosionEffect>().FadeIn();
            break;
        }

        return(effectObject);
    }