Example #1
0
        public void Explode(Vector3 additionalVelocity)
        {
            foreach (GameObject o in GameObject.FindGameObjectsWithTag("PicaVoxelVolume"))
            {
                if (ExplodeTarget == ExplodeTargets.AllButSelf && o.transform.root == transform.root)
                {
                    continue;
                }
                if (ExplodeTarget == ExplodeTargets.SelfOnly && o.transform.root != transform.root)
                {
                    continue;
                }

                Volume pvo = o.GetComponent <Volume>();
                if (pvo == null)
                {
                    continue;
                }
                Vector3 cpob = pvo.Hitbox.ClosestPointOnBounds(transform.position);

                if (Vector3.Distance(transform.position, cpob) <= ExplosionRadius ||
                    pvo.GetVoxelAtWorldPosition(transform.position) != null)
                {
                    Batch batch = pvo.Explode(transform.position, ExplosionRadius, ValueFilter, ValueFilterOperation);

                    if (batch.Voxels.Count > 0 && VoxelParticleSystem.Instance != null)
                    {
                        VoxelParticleSystem.Instance.SpawnBatch(batch,
                                                                pos =>
                                                                (((pos + Random.insideUnitSphere) - transform.position) *
                                                                 ((Random.Range(ParticleVelocity - 1f, ParticleVelocity + 1f)))) + additionalVelocity);
                    }

                    batch.Dispose();
                }
            }
        }