Пример #1
0
    public void SpawnProjectile(E_ProjectileType inProjeType, Vector3 inPos, Vector3 inDir, Projectile.InitSettings inSettings)
    {
        //Debug.Log("New SpawnProjectile " + inProjeType);
        // test if we have configured cache for this type of resource...
        if (CacheOfProjectiles.ContainsKey(inProjeType) == false)
        {
            Debug.LogError("ProjectileFactory: unknown type " + inProjeType);
            return;
        }

        // if we known this type but we don't have resource cache than go out,
        // this is corect situation...
        else if (CacheOfProjectiles[inProjeType] == null)
        {
            Debug.LogError("ProjectileFactory: For this type " + inProjeType + " we don't have resource");
            return;
        }

        //check the projectile against the camera frustum - when it doesn't intersect it, do not bother spawning it on client
        if (uLink.Network.isServer == false && inSettings.Agent && inSettings.Agent.IsProxy)
        {
            Frustum.SetupCamera(GameCamera.Instance, 100);
            // variant A: faster but not accurate
            Frustum.E_Location loc = Frustum.LineInFrustumFast(inPos, inPos + inDir * GameCamera.Instance.MainCamera.farClipPlane);
            // variant B: accurate but slower
            //	Frustum.E_Location loc = Frustum.LineInFrustum(GameCamera.Instance.MainCamera,inPos, inPos + inDir * GameCamera.Instance.MainCamera.far);

            if (loc == Frustum.E_Location.Outside)             //do not spawn the projectile if it's not visible at all
            {
//				Debug.Log ("Projectile NOT SPAWNED, pos=" + inPos.ToString("F3") + ", dir=" + inDir.ToString("F3"));
                return;
            }
//			else
//			{
//				Debug.Log ("Projectile SPAWNED, pos=" + inPos.ToString("F3") + ", dir=" + inDir.ToString("F3"));
//			}
        }
        //

        Projectile proj = CacheOfProjectiles[inProjeType].Get();

        if (proj == null)
        {
            Debug.LogError("ProjectileFactory: Can't create projectile for type " + inProjeType);
            return;
        }

        proj.ProjectileInit(inPos, inDir.normalized, inSettings);
        ActiveProjectiles.Add(proj);
    }
Пример #2
0
    public void PlayHitEffect(GameObject parent, int layer, Vector3 pos, Vector3 dir, E_ProjectileType inProjectileType, bool localPlayer)
    {
        if (uLink.Network.isServer)
        {
            return;
        }

        if (localPlayer == false)
        {
            Frustum.SetupCamera(GameCamera.Instance, 30);
            Frustum.E_Location loc = Frustum.PointInFrustum(pos);

            if (loc == Frustum.E_Location.Outside)             //do not spawn the projectile if it's not visible at all
            {
                return;
            }
        }

        if (inProjectileType == E_ProjectileType.Plasma)
        {
            if (PlasmaGunHit.Prefab != null)
            {
                //shift it a little to avoid static object penetration
                PlasmaGunHit.Play(pos + dir * 0.4f, dir);
                return;
            }
        }

        if (inProjectileType == E_ProjectileType.Rail)
        {
            if (PlasmaGunHit.Prefab != null)
            {
                PlasmaGunHit.Play(pos, dir);
                return;
            }
        }

        // default, old, behavior...
        if (HitEffects.ContainsKey(layer) == true)
        {
            HitEffects[layer].Play(pos, dir);
        }
        else
        {
            HitEffects[0].Play(pos, dir);
        }
    }
Пример #3
0
    // ==================================================================================================
    // === INTERNAL =====================================================================================

    void ClientExplode()
    {
        // Check if this explosion is
        MFDebugUtils.Assert(m_Exploded == false);

        if (GetComponent <AudioSource>() != null && GetComponent <AudioSource>().clip != null)
        {
            GetComponent <AudioSource>().Play();
        }

        Frustum.SetupCamera(GameCamera.Instance);
        Frustum.E_Location loc = Frustum.PointInFrustum(Position);

        if (loc == Frustum.E_Location.Outside)         //do not spawn the projectile if it's not visible at all
        {
            return;
        }

        // Run particles only when explosion is longer as is m_ParticleCriticalDistance.
        // Reason : Particles from explosion are full scree when explosion is too near, and
        //          full-screen particles are too slow. So we don't run them.
#if !UNITY_EDITOR
        if (m_ParticleCriticalDistance < 0 || Camera.main == null || Vector3.Magnitude(Camera.main.transform.position - Position) > m_ParticleCriticalDistance)
#endif
        {
            // Run all particles...
            foreach (ParticleSystem em in m_Emitters)
            {
                if (null != em)
                {
                    em.Play();
                }
            }
        }

        //if (audio != null && audio.clip != null)
        //	audio.Play();

        // Do screen fx...
        if (m_GenerateWaveFX && CamExplosionFXMgr.Instance)
        {
            GenerateWaveFX();
        }
    }