示例#1
0
    public void ProjectileIntercepted(Projectile pr, RaycastHit2D hit)
    {
        // Called on both client and server.
        // Disable the projectile.
        // On server, this is authorative.
        // On client, this hides it, and could lead to visual desync. Oh well.


        // Ignore if not attached.
        if (!Attachment.IsAttached)
        {
            return;
        }

        // Do not shoot down our own projectiles!
        if (Attachment.ParentUnit.Faction == pr.Faction)
        {
            return;
        }

        pr.Disable(hit.point);

        // Play the shoot down effect, and spawn a shot down particle effect.
        PlayShootdownAnim(hit.point);

        var particle = Pool.Get(TempEffect.GetPrefab(TempEffects.DESTROYED_SPARKS).PoolableObject);

        particle.transform.position    = hit.point;
        particle.transform.eulerAngles = pr.transform.eulerAngles;
    }
    public void ProcessHit(RaycastHit2D hit, int penetration, DamageModel model)
    {
        // Can run on either server or client.

        // On server, deals damage, applies forces.
        if (isServer)
        {
            ProcessServerHit(hit, penetration, model);
        }

        // On clients, spawns hit effects and audio ect.
        // TODO apply hit effect and audio.

        // Apply hit effect.
        if (model != null)
        {
            if (model.ColliderPartMap.ContainsKey(hit.collider))
            {
                var hitEffect = model.ColliderPartMap[hit.collider].HitEffect;
                if (hitEffect != TempEffects.NONE)
                {
                    // Spawn hit effect.
                    var prefab = TempEffect.GetPrefab(hitEffect).PoolableObject;
                    var effect = Pool.Get(prefab);
                    if (effect != null)
                    {
                        effect.transform.position = hit.point;
                        float angle = Mathf.Atan2(hit.normal.y, hit.normal.x) * Mathf.Rad2Deg;
                        effect.transform.eulerAngles = new Vector3(0f, 0f, angle);
                    }
                    else
                    {
                        Debug.LogWarning("Tried to spawn effect for projectile hit, but the pool returned null!");
                    }
                }
            }
        }
    }