Ejemplo n.º 1
0
        private void OnEnable()
        {
            voxelExploder = (Exploder) target;

            explosionRadius = voxelExploder.ExplosionRadius;
            particleVelocity = voxelExploder.ParticleVelocity;
            explodeTarget = voxelExploder.ExplodeTarget;
            valueFilterOperation = voxelExploder.ValueFilterOperation;
            valueFilter = voxelExploder.ValueFilter;
        }
Ejemplo n.º 2
0
        private bool FilterExplosion(byte value, int valueFilter, Exploder.ExplodeValueFilterOperation valueFilterOperation)
        {
            switch (valueFilterOperation)
            {
                case Exploder.ExplodeValueFilterOperation.LessThan:
                    return value < valueFilter;
                case Exploder.ExplodeValueFilterOperation.LessThanOrEqualTo:
                    return value <= valueFilter;
                case Exploder.ExplodeValueFilterOperation.EqualTo:
                    return value == valueFilter;
                case Exploder.ExplodeValueFilterOperation.GreaterThanOrEqualTo:
                    return value >= valueFilter;
                case Exploder.ExplodeValueFilterOperation.GreaterThan:
                    return value > valueFilter;
            }

            return false;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deactivates all particles in the current frame, within a supplied radius of a world position
        /// </summary>
        /// <param name="position">The world position of the centre of the explosion</param>
        /// <param name="explosionRadius">The radius of the explosion</param>
        /// <returns>A Batch of voxels that were destroyed by the explosion</returns>
        public Batch Explode(Vector3 position, float explosionRadius, int valueFilter, Exploder.ExplodeValueFilterOperation valueFilterOperation)
        {
            Batch batch = new Batch(this);

            Color tint = Material.GetColor("_Tint");

            Matrix4x4 transformMatrix = transform.worldToLocalMatrix;

            position += (transform.rotation * (Pivot));

            for (float x = position.x - explosionRadius; x <= position.x + explosionRadius; x += VoxelSize * 0.5f)
                for (float y = position.y - explosionRadius; y <= position.y + explosionRadius; y += VoxelSize * 0.5f)
                    for (float z = position.z - explosionRadius; z <= position.z + explosionRadius; z += VoxelSize * 0.5f)
                    {
                        Vector3 checkPos = new Vector3(x, y, z);
                        if (Vector3.Distance(checkPos, position) <= explosionRadius)
                        {
                            Vector3 localPos = transformMatrix.MultiplyPoint3x4(checkPos); //transform.InverseTransformPoint(pos);

                            //if (!Frames[CurrentFrame].IsLocalPositionInBounds(localPos)) continue;

                            int testX = (int)(localPos.x / VoxelSize);
                            int testY = (int)(localPos.y / VoxelSize);
                            int testZ = (int)(localPos.z / VoxelSize);
                            if (testX < 0 || testY < 0 || testZ < 0 || testX >= XSize || testY >= YSize || testZ >= ZSize) continue;

                            if (Frames[CurrentFrame].Voxels[testX + XSize * (testY + YSize * testZ)].Active &&
                            FilterExplosion(Frames[CurrentFrame].Voxels[testX + XSize * (testY + YSize * testZ)].Value, valueFilter, valueFilterOperation) &&
                            Vector3.Distance(position, checkPos) <= explosionRadius)
                            {
                                Voxel v = Frames[CurrentFrame].Voxels[testX + XSize * (testY + YSize * testZ)];
                                v.Color *= tint;
                                batch.Add(v, testX, testY, testZ, checkPos - (transform.rotation * (Pivot)));
                                SetVoxelStateAtArrayPosition(testX, testY, testZ, VoxelState.Hidden);
                            }
                        }
                    }

           

            return batch;
        }